Skip to content

Commit 07ffc6b

Browse files
authored
Merge pull request #53 from DeepCodeAI/dashboard_dc_ignore
Added dcignore node to HELP section and command palette.
2 parents 0ae8a88 + ca586d3 commit 07ffc6b

7 files changed

Lines changed: 79 additions & 11 deletions

File tree

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@
168168
{
169169
"command": "deepcode.login",
170170
"when": "!deepcode:loggedIn"
171+
},
172+
{
173+
"command": "deepcode.dcignore",
174+
"when": "!deepcode:error && deepcode:loggedIn && deepcode:uploadApproved && deepcode:workspaceFound"
171175
}
172176
]
173177
},
@@ -184,7 +188,13 @@
184188
},
185189
{
186190
"command": "deepcode.login",
187-
"title": "DeepCode login"
191+
"title": "DeepCode login",
192+
"icon": "$(log-in)"
193+
},
194+
{
195+
"command": "deepcode.dcignore",
196+
"title": "DeepCode create dcignore file",
197+
"icon": "$(new-file)"
188198
}
189199
]
190200
},
@@ -215,6 +225,7 @@
215225
},
216226
"dependencies": {
217227
"@deepcode/tsc": "^1.3.0",
228+
"@deepcode/dcignore": "^1.0.2",
218229
"@types/lodash": "^4.14.159",
219230
"@types/mz": "^2.7.1",
220231
"ignore": "^5.1.8",

src/deepcode/DeepCodeExtension.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ import DeepCodeLib from "./lib/modules/DeepCodeLib";
77
import {
88
DEEPCODE_START_COMMAND,
99
DEEPCODE_SETTINGS_COMMAND,
10+
DEEPCODE_DCIGNORE_COMMAND,
1011
DEEPCODE_LOGIN,
1112
DEEPCODE_APPROVE,
1213
DEEPCODE_OPEN_BROWSER,
1314
DEEPCODE_OPEN_LOCAL,
1415
} from "./constants/commands";
15-
import { openDeepcodeSettingsCommand } from "./utils/vscodeCommandsUtils";
16+
import { openDeepcodeSettingsCommand, createDCIgnoreCommand } from "./utils/vscodeCommandsUtils";
1617
import { errorsLogs } from "./messages/errorsServerLogMessages";
1718

1819
import {
@@ -108,6 +109,13 @@ class DeepCodeExtension extends DeepCodeLib implements DeepCode.ExtensionInterfa
108109
)
109110
);
110111

112+
context.subscriptions.push(
113+
vscode.commands.registerCommand(
114+
DEEPCODE_DCIGNORE_COMMAND,
115+
createDCIgnoreCommand
116+
)
117+
);
118+
111119
vscode.window.registerTreeDataProvider(
112120
DEEPCODE_VIEW_SUPPORT,
113121
new SupportProvider(this)

src/deepcode/constants/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const DEEPCODE_LOGIN = "deepcode.login";
88
export const DEEPCODE_APPROVE = "deepcode.approve";
99
export const DEEPCODE_SETTINGS_COMMAND = "deepcode.settings";
1010
export const DEEPCODE_IGNORE_ISSUES_COMMAND = "deepcode.ignoreissues";
11+
export const DEEPCODE_DCIGNORE_COMMAND = "deepcode.dcignore";
1112
export const DEEPCODE_OPEN_BROWSER = "deepcode.open";
1213
export const DEEPCODE_OPEN_LOCAL = "deepcode.show";
1314

src/deepcode/utils/filesUtils.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import * as vscode from "vscode";
12
import * as crypto from "crypto";
23
import * as nodePath from "path";
34
import { Buffer } from "buffer";
45
import { fs } from "mz";
6+
import { CustomDCIgnore, DefaultDCIgnore } from "@deepcode/dcignore";
57
import {
68
HASH_ALGORITHM,
79
ENCODE_TYPE,
@@ -12,7 +14,6 @@ import {
1214
} from "../constants/filesConstants";
1315
import { ALLOWED_PAYLOAD_SIZE } from "../constants/general";
1416
import DeepCode from "../../interfaces/DeepCodeInterfaces";
15-
import { ExclusionFilter } from "../utils/ignoreUtils";
1617

1718
// The file limit was hardcoded to 2mb but seems to be a function of ALLOWED_PAYLOAD_SIZE
1819
// TODO what exactly is transmitted eventually and what is a good exact limit?
@@ -181,3 +182,16 @@ export const splitPayloadIntoChunks = (
181182

182183
return { chunks: true, payload: chunkedPayload };
183184
};
185+
186+
export const createDCIgnore = async (
187+
path: string,
188+
custom: boolean,
189+
) => {
190+
const content: Buffer = Buffer.from(custom ? CustomDCIgnore : DefaultDCIgnore);
191+
const filePath = `${path}/.dcignore`;
192+
const openPath = vscode.Uri.file(filePath);
193+
// We don't want to override the dcignore file with an empty one.
194+
if (!custom || !fs.existsSync(filePath)) await vscode.workspace.fs.writeFile(openPath, content);
195+
const doc = await vscode.workspace.openTextDocument(openPath);
196+
vscode.window.showTextDocument(doc);
197+
};

src/deepcode/utils/vscodeCommandsUtils.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,23 @@ import {
55
DEEPCODE_CONTEXT_PREFIX,
66
DEEPCODE_OPEN_BROWSER,
77
} from "../constants/commands";
8+
import { createDCIgnore } from "./filesUtils"
89

910
export const openDeepcodeSettingsCommand = async (): Promise<void> => {
1011
await vscode.commands.executeCommand(VSCODE_GO_TO_SETTINGS_COMMAND, DEEPCODE_EXTENSION_NAME);
1112
};
1213

1314
export const setContext = async (key: string, value: unknown): Promise<void> => {
14-
console.log("DeepCode context",key, value);
15+
console.log("DeepCode context", key, value);
1516
await vscode.commands.executeCommand('setContext', `${DEEPCODE_CONTEXT_PREFIX}${key}`, value);
1617
};
1718

1819
export const viewInBrowser = async (url: string): Promise<void> => {
1920
await vscode.commands.executeCommand(DEEPCODE_OPEN_BROWSER, url);
20-
};
21+
};
22+
23+
export const createDCIgnoreCommand = (custom = false, path?: string): void => {
24+
path = path || vscode.workspace.rootPath;
25+
if (!path) return;
26+
createDCIgnore(path, custom).catch(console.error);
27+
};

src/deepcode/view/SupportProvider.ts

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { TreeItemCollapsibleState, ThemeIcon } from 'vscode';
22
import { NodeProvider } from './NodeProvider';
33
import { Node } from './Node';
4+
import { DEEPCODE_DCIGNORE_COMMAND } from "../constants/commands";
45

56
export class SupportProvider extends NodeProvider {
67
getRootChildren(): Node[] {
@@ -21,15 +22,36 @@ export class SupportProvider extends NodeProvider {
2122
link: "https://www.youtube.com/watch?v=NIDeVYLWkMI"
2223
}),
2324
new Node({
24-
text: "2. How to ignore files and directories?",
25-
icon: new ThemeIcon('file-text'),
26-
link: "https://deepcode.freshdesk.com/support/solutions/articles/60000531055-how-can-i-ignore-files-or-directories-"
27-
}),
28-
new Node({
29-
text: "3. How to ignore issues within the code?",
25+
text: "2. How to ignore issues within the code?",
3026
icon: new ThemeIcon('play'),
3127
link: "https://www.youtube.com/watch?v=sjDuDqUy7pw"
3228
}),
29+
new Node({
30+
text: "3. How to ignore files and directories?",
31+
icon: new ThemeIcon('file-text'),
32+
link: "https://deepcode.freshdesk.com/support/solutions/articles/60000531055-how-can-i-ignore-files-or-directories-",
33+
collapsed: TreeItemCollapsibleState.Expanded,
34+
children: [
35+
new Node({
36+
text: "Add default .dcignore file to your workspace",
37+
icon: new ThemeIcon('new-file'),
38+
command: {
39+
command: DEEPCODE_DCIGNORE_COMMAND,
40+
title: '',
41+
arguments: [],
42+
}
43+
}),
44+
new Node({
45+
text: "Add a custom .dcignore file to your workspace",
46+
icon: new ThemeIcon('new-file'),
47+
command: {
48+
command: DEEPCODE_DCIGNORE_COMMAND,
49+
title: '',
50+
arguments: [true],
51+
}
52+
}),
53+
]
54+
}),
3355
]
3456
}),
3557
new Node({

0 commit comments

Comments
 (0)