Skip to content

Commit 34a75f1

Browse files
committed
Added actions view.
1 parent c950188 commit 34a75f1

7 files changed

Lines changed: 93 additions & 27 deletions

File tree

package.json

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
{
121121
"id": "deepcode.views.actions",
122122
"name": "Actions",
123-
"when": "!deepcode:error && deepcode:loggedIn && deepcode:uploadApproved"
123+
"when": "!deepcode:error && deepcode:loggedIn && deepcode:uploadApproved && deepcode:workspaceFound"
124124
},
125125
{
126126
"id": "deepcode.views.support",
@@ -157,18 +157,23 @@
157157
},
158158
{
159159
"view": "deepcode.views.actions",
160-
"contents": "You are currently running DeepCode in manual mode.\n[Re-scan](command:deepcode.login)\nWants to r?\n[Switch to manual re-scan mode](command:deepcode.login)\nOnce manual re-scan mode is activated, results will not be updated unless you manully trigger the analysis.",
160+
"contents": "You are currently running DeepCode in manual mode.\n[Analyze now](command:deepcode.start)\n[Switch to auto-scan mode](command:deepcode.setmode?%5B%22auto%22%5D)",
161161
"when": "deepcode:mode == 'manual'"
162162
},
163163
{
164164
"view": "deepcode.views.actions",
165-
"contents": "DeepCode analysis is currently paused.\n[Unpause](command:deepcode.mode?%5B%auto%22%5D)",
166-
"when": "deepcode:mode == 'pause'"
165+
"contents": "DeepCode analysis is currently paused.\n[Unpause](command:deepcode.setmode?%5B%22auto%22%5D)",
166+
"when": "deepcode:mode == 'paused'"
167+
},
168+
{
169+
"view": "deepcode.views.actions",
170+
"contents": "You are currently running DeepCode in throttled mode. It scans your code every 30 minutes if it detects changes in your files.\n[Auto](command:deepcode.setmode?%5B%22auto%22%5D)",
171+
"when": "deepcode:mode == 'throttled'"
167172
},
168173
{
169174
"view": "deepcode.views.actions",
170-
"contents": "You are currently running DeepCode in a fully automated mode. Need to take control?\n[Switch to manual re-scan mode](command:deepcode.mode?%5B%manual%22%5D)\n[Pause DeepCode for 30 minutes](command:deepcode.mode?%5B%22pause%22%5D)",
171-
"when": "deepcode:mode != 'manual' && deepcode:mode != 'pause'"
175+
"contents": "You are currently running DeepCode in a fully automated mode. It scans your code for issues when you save a file.\nNeed to take control?\n[Pause DeepCode for 30 minutes](command:deepcode.setmode?%5B%22paused%22%5D)\n[Switch to manual scan mode](command:deepcode.setmode?%5B%22manual%22%5D)\n[Switch to throttled scan mode](command:deepcode.setmode?%5B%22throttled%22%5D)",
176+
"when": "deepcode:mode != 'manual' && deepcode:mode != 'paused' && deepcode:mode != 'throttled'"
172177
}
173178
],
174179
"menus": {

src/deepcode/DeepCodeExtension.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import DeepCode from "../interfaces/DeepCodeInterfaces";
55
import DeepCodeLib from "./lib/modules/DeepCodeLib";
66

77
import {
8-
DEEPCODE_START_COMMAND,
8+
DEEPCODE_START_COMMAND,
9+
DEEPCODE_SETMODE_COMMAND,
910
DEEPCODE_SETTINGS_COMMAND,
1011
DEEPCODE_LOGIN,
1112
DEEPCODE_APPROVE,
@@ -62,10 +63,17 @@ class DeepCodeExtension extends DeepCodeLib implements DeepCode.ExtensionInterfa
6263
context.subscriptions.push(
6364
vscode.commands.registerCommand(
6465
DEEPCODE_START_COMMAND,
65-
this.startExtension.bind(this)
66+
this.startExtension.bind(this, true)
6667
)
6768
);
68-
69+
70+
context.subscriptions.push(
71+
vscode.commands.registerCommand(
72+
DEEPCODE_SETMODE_COMMAND,
73+
this.setMode.bind(this)
74+
)
75+
);
76+
6977
context.subscriptions.push(
7078
vscode.commands.registerCommand(
7179
DEEPCODE_SETTINGS_COMMAND,

src/deepcode/constants/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const VSCODE_ADD_COMMENT_COMMAND = "editor.action.addCommentLine";
66
export const DEEPCODE_START_COMMAND = "deepcode.start";
77
export const DEEPCODE_LOGIN = "deepcode.login";
88
export const DEEPCODE_APPROVE = "deepcode.approve";
9+
export const DEEPCODE_SETMODE_COMMAND = "deepcode.setmode";
910
export const DEEPCODE_SETTINGS_COMMAND = "deepcode.settings";
1011
export const DEEPCODE_IGNORE_ISSUES_COMMAND = "deepcode.ignoreissues";
1112
export const DEEPCODE_OPEN_BROWSER = "deepcode.open";

src/deepcode/constants/general.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ export const DEEPCODE_EXTENSION_NAME = "deepcode";
44
export const ALLOWED_PAYLOAD_SIZE = 1024 * 1024 * 4; // max payload size of 4MB in bytes
55
export const MAX_CONNECTION_RETRIES = 5; // max number of automatic retries before showing an error
66
export const IDE_NAME = "vscode";
7-
export const EXECUTION_DEBOUNCE_INTERVAL = 1000;
8-
export const REFRESH_VIEW_DEBOUNCE_INTERVAL = 200;
7+
export const EXECUTION_DEBOUNCE_INTERVAL = 1000; // 1 second
8+
export const EXECUTION_DEBOUNCE_EXTENDED_INTERVAL = 1000 * 60 * 30; // 30 minutes
9+
export const EXECUTION_PAUSE_INTERVAL = 1000 * 60 * 30; // 30 minutes
10+
export const REFRESH_VIEW_DEBOUNCE_INTERVAL = 200; // 200 milliseconds

src/deepcode/constants/views.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,21 @@ export const DEEPCODE_CONTEXT = {
88
APPROVED: "uploadApproved",
99
ANALYZING: "workspaceFound",
1010
ERROR: "error",
11+
MODE: "mode",
1112
};
1213

1314
export const DEEPCODE_ERROR_CODES = {
1415
TRANSIENT: "transient",
1516
BLOCKING: "blocking",
1617
};
1718

19+
export const DEEPCODE_MODE_CODES = {
20+
AUTO: 'auto',
21+
MANUAL: 'manual',
22+
PAUSED: 'paused',
23+
THROTTLED: 'throttled',
24+
};
25+
1826
export const DEEPCODE_ANALYSIS_STATUS = {
1927
COLLECTING: "Collecting files",
2028
HASHING: "Hashing files",

src/deepcode/lib/modules/DeepCodeLib.ts

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,21 @@ import * as _ from "lodash";
22
import DeepCode from "../../../interfaces/DeepCodeInterfaces";
33
import BundlesModule from "./BundlesModule";
44
import { setContext } from "../../utils/vscodeCommandsUtils";
5-
import { DEEPCODE_CONTEXT } from "../../constants/views";
6-
import { EXECUTION_DEBOUNCE_INTERVAL } from "../../constants/general";
5+
import { DEEPCODE_CONTEXT, DEEPCODE_MODE_CODES } from "../../constants/views";
6+
import {
7+
EXECUTION_DEBOUNCE_INTERVAL,
8+
EXECUTION_DEBOUNCE_EXTENDED_INTERVAL,
9+
EXECUTION_PAUSE_INTERVAL,
10+
} from "../../constants/general";
711

812
export default class DeepCodeLib extends BundlesModule implements DeepCode.DeepCodeLibInterface {
9-
private executing = false;
13+
private _mode = DEEPCODE_MODE_CODES.AUTO;
14+
// Platform-independant type definition.
15+
private _unpauseTimeout: ReturnType<typeof setTimeout> | undefined;
16+
17+
private unpause() {
18+
if (this._mode === DEEPCODE_MODE_CODES.PAUSED) this.setMode(DEEPCODE_MODE_CODES.AUTO);
19+
}
1020

1121
activateAll(): void {
1222
// this.filesWatcher.activate(this);
@@ -29,17 +39,48 @@ export default class DeepCodeLib extends BundlesModule implements DeepCode.DeepC
2939
this.resetTransientErrors();
3040
}
3141

32-
startExtension = _.debounce(
33-
async (): Promise<void> => {
34-
// This function is called by commands, error handlers, etc.
35-
// We should avoid having duplicate parallel executions.
36-
try {
37-
await this.executeExtensionPipeline();
38-
} catch (err) {
39-
this.processError(err);
40-
}
41-
},
42-
EXECUTION_DEBOUNCE_INTERVAL,
43-
{ 'leading': true }
44-
);
42+
private getDebouncedExecution(wait: number) {
43+
return _.debounce(
44+
async (manual = false): Promise<void> => {
45+
// If the execution is suspended, we only allow user-triggered analyses.
46+
if (!manual && [
47+
DEEPCODE_MODE_CODES.MANUAL,
48+
DEEPCODE_MODE_CODES.PAUSED
49+
].includes(this._mode)) return;
50+
// This function is called by commands, error handlers, etc.
51+
// We should avoid having duplicate parallel executions.
52+
try {
53+
await this.executeExtensionPipeline();
54+
} catch (err) {
55+
this.processError(err);
56+
}
57+
},
58+
wait,
59+
{ 'leading': true }
60+
);
61+
}
62+
63+
startExtension = this.getDebouncedExecution(EXECUTION_DEBOUNCE_INTERVAL);
64+
65+
setMode(mode: string): void {
66+
if (!Object.values(DEEPCODE_MODE_CODES).includes(mode)) return;
67+
this._mode = mode;
68+
setContext(DEEPCODE_CONTEXT.MODE, mode);
69+
switch(mode) {
70+
case DEEPCODE_MODE_CODES.PAUSED:
71+
this._unpauseTimeout = setTimeout(this.unpause.bind(this), EXECUTION_PAUSE_INTERVAL);
72+
this.startExtension = this.getDebouncedExecution(EXECUTION_DEBOUNCE_INTERVAL);
73+
break;
74+
case DEEPCODE_MODE_CODES.AUTO:
75+
case DEEPCODE_MODE_CODES.MANUAL:
76+
case DEEPCODE_MODE_CODES.PAUSED:
77+
if (this._unpauseTimeout) clearTimeout(this._unpauseTimeout);
78+
this.startExtension = this.getDebouncedExecution(EXECUTION_DEBOUNCE_INTERVAL);
79+
break;
80+
case DEEPCODE_MODE_CODES.THROTTLED:
81+
if (this._unpauseTimeout) clearTimeout(this._unpauseTimeout);
82+
this.startExtension = this.getDebouncedExecution(EXECUTION_DEBOUNCE_EXTENDED_INTERVAL);
83+
break;
84+
}
85+
}
4586
}

src/interfaces/DeepCodeInterfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ namespace DeepCode {
234234

235235
export interface DeepCodeLibInterface {
236236
activateAll(): void;
237+
setMode(mode:string): void;
237238
}
238239

239240
export interface ExtensionInterface

0 commit comments

Comments
 (0)