Skip to content

Commit 5825878

Browse files
authored
Merge pull request #54 from DeepCodeAI/mini-dashboard-actions
Mini dashboard actions
2 parents ec67e36 + eaae9ab commit 5825878

File tree

7 files changed

+105
-9
lines changed

7 files changed

+105
-9
lines changed

package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@
117117
"name": "DeepCode Analysis",
118118
"when": "!deepcode:error && deepcode:loggedIn && deepcode:uploadApproved && deepcode:workspaceFound"
119119
},
120+
{
121+
"id": "deepcode.views.actions",
122+
"name": "Actions",
123+
"when": "!deepcode:error && deepcode:loggedIn && deepcode:uploadApproved && deepcode:workspaceFound"
124+
},
120125
{
121126
"id": "deepcode.views.support",
122127
"name": "Help & feedback"
@@ -149,6 +154,26 @@
149154
{
150155
"view": "deepcode.views.analysis",
151156
"contents": "DeepCode analyzed your code and found no issue! 🎉"
157+
},
158+
{
159+
"view": "deepcode.views.actions",
160+
"contents": "You are currently running DeepCode in manual mode. You are in control, no automated actions from our side.\n[Analyze now](command:deepcode.start)\n[Switch to auto-scan mode](command:deepcode.setmode?%5B%22auto%22%5D)",
161+
"when": "deepcode:mode == 'manual'"
162+
},
163+
{
164+
"view": "deepcode.views.actions",
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 a throttled mode - it scans your code every 30 minutes if it detects changes in your files.\n[Analyze now](command:deepcode.start)\n[Switch to auto-scan mode](command:deepcode.setmode?%5B%22auto%22%5D)",
171+
"when": "deepcode:mode == 'throttled'"
172+
},
173+
{
174+
"view": "deepcode.views.actions",
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'"
152177
}
153178
],
154179
"menus": {

src/deepcode/DeepCodeExtension.ts

Lines changed: 10 additions & 2 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_DCIGNORE_COMMAND,
1112
DEEPCODE_LOGIN,
@@ -97,7 +98,14 @@ class DeepCodeExtension extends DeepCodeLib implements DeepCode.ExtensionInterfa
9798
)
9899
)
99100
);
100-
101+
102+
context.subscriptions.push(
103+
vscode.commands.registerCommand(
104+
DEEPCODE_SETMODE_COMMAND,
105+
this.setMode.bind(this)
106+
)
107+
);
108+
101109
context.subscriptions.push(
102110
vscode.commands.registerCommand(
103111
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_DCIGNORE_COMMAND = "deepcode.dcignore";

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_THROTTLING_INTERVAL = 1000 * 10;// * 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: 56 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,37 @@ 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";
76
import { errorsLogs } from "../../messages/errorsServerLogMessages";
7+
import {
8+
EXECUTION_DEBOUNCE_INTERVAL,
9+
EXECUTION_THROTTLING_INTERVAL,
10+
EXECUTION_PAUSE_INTERVAL,
11+
} from "../../constants/general";
812

913
export default class DeepCodeLib extends BundlesModule implements DeepCode.DeepCodeLibInterface {
14+
private _mode = DEEPCODE_MODE_CODES.AUTO;
15+
// Platform-independant type definition.
16+
private _unpauseTimeout: ReturnType<typeof setTimeout> | undefined;
17+
private _lastThrottledExecution: number | undefined;
18+
19+
private shouldBeThrottled(): boolean {
20+
if (this._mode !== DEEPCODE_MODE_CODES.THROTTLED) return false;
21+
const now = Date.now();
22+
if (
23+
this._lastThrottledExecution === undefined ||
24+
(now - this._lastThrottledExecution) >= EXECUTION_THROTTLING_INTERVAL
25+
) {
26+
this._lastThrottledExecution = now;
27+
return false;
28+
}
29+
return true;
30+
}
31+
32+
private unpause(): void {
33+
if (this._mode === DEEPCODE_MODE_CODES.PAUSED) this.setMode(DEEPCODE_MODE_CODES.AUTO);
34+
}
35+
1036
activateAll(): void {
1137
// this.filesWatcher.activate(this);
1238
this.workspacesWatcher.activate(this);
@@ -28,10 +54,19 @@ export default class DeepCodeLib extends BundlesModule implements DeepCode.DeepC
2854
this.resetTransientErrors();
2955
}
3056

57+
// This function is called by commands, error handlers, etc.
58+
// We should avoid having duplicate parallel executions.
3159
startExtension = _.debounce(
32-
async (): Promise<void> => {
33-
// This function is called by commands, error handlers, etc.
34-
// We should avoid having duplicate parallel executions.
60+
async (manual = false): Promise<void> => {
61+
// If the execution is suspended, we only allow user-triggered analyses.
62+
if (!manual) {
63+
if ([
64+
DEEPCODE_MODE_CODES.MANUAL,
65+
DEEPCODE_MODE_CODES.PAUSED
66+
].includes(this._mode) ||
67+
this.shouldBeThrottled()
68+
) return;
69+
}
3570
try {
3671
await this.executeExtensionPipeline();
3772
} catch (err) {
@@ -43,4 +78,20 @@ export default class DeepCodeLib extends BundlesModule implements DeepCode.DeepC
4378
EXECUTION_DEBOUNCE_INTERVAL,
4479
{ 'leading': true }
4580
);
81+
82+
setMode(mode: string): void {
83+
if (!Object.values(DEEPCODE_MODE_CODES).includes(mode)) return;
84+
this._mode = mode;
85+
setContext(DEEPCODE_CONTEXT.MODE, mode);
86+
switch(mode) {
87+
case DEEPCODE_MODE_CODES.PAUSED:
88+
this._unpauseTimeout = setTimeout(this.unpause.bind(this), EXECUTION_PAUSE_INTERVAL);
89+
break;
90+
case DEEPCODE_MODE_CODES.AUTO:
91+
case DEEPCODE_MODE_CODES.MANUAL:
92+
case DEEPCODE_MODE_CODES.THROTTLED:
93+
if (this._unpauseTimeout) clearTimeout(this._unpauseTimeout);
94+
break;
95+
}
96+
}
4697
}

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)