Skip to content

Commit

Permalink
Merge pull request #54 from DeepCodeAI/mini-dashboard-actions
Browse files Browse the repository at this point in the history
Mini dashboard actions
  • Loading branch information
Arvi3d authored Aug 24, 2020
2 parents ec67e36 + eaae9ab commit 5825878
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 9 deletions.
25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@
"name": "DeepCode Analysis",
"when": "!deepcode:error && deepcode:loggedIn && deepcode:uploadApproved && deepcode:workspaceFound"
},
{
"id": "deepcode.views.actions",
"name": "Actions",
"when": "!deepcode:error && deepcode:loggedIn && deepcode:uploadApproved && deepcode:workspaceFound"
},
{
"id": "deepcode.views.support",
"name": "Help & feedback"
Expand Down Expand Up @@ -149,6 +154,26 @@
{
"view": "deepcode.views.analysis",
"contents": "DeepCode analyzed your code and found no issue! 🎉"
},
{
"view": "deepcode.views.actions",
"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)",
"when": "deepcode:mode == 'manual'"
},
{
"view": "deepcode.views.actions",
"contents": "DeepCode analysis is currently paused.\n[Unpause](command:deepcode.setmode?%5B%22auto%22%5D)",
"when": "deepcode:mode == 'paused'"
},
{
"view": "deepcode.views.actions",
"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)",
"when": "deepcode:mode == 'throttled'"
},
{
"view": "deepcode.views.actions",
"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)",
"when": "deepcode:mode != 'manual' && deepcode:mode != 'paused' && deepcode:mode != 'throttled'"
}
],
"menus": {
Expand Down
12 changes: 10 additions & 2 deletions src/deepcode/DeepCodeExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import DeepCode from "../interfaces/DeepCodeInterfaces";
import DeepCodeLib from "./lib/modules/DeepCodeLib";

import {
DEEPCODE_START_COMMAND,
DEEPCODE_START_COMMAND,
DEEPCODE_SETMODE_COMMAND,
DEEPCODE_SETTINGS_COMMAND,
DEEPCODE_DCIGNORE_COMMAND,
DEEPCODE_LOGIN,
Expand Down Expand Up @@ -97,7 +98,14 @@ class DeepCodeExtension extends DeepCodeLib implements DeepCode.ExtensionInterfa
)
)
);


context.subscriptions.push(
vscode.commands.registerCommand(
DEEPCODE_SETMODE_COMMAND,
this.setMode.bind(this)
)
);

context.subscriptions.push(
vscode.commands.registerCommand(
DEEPCODE_SETTINGS_COMMAND,
Expand Down
1 change: 1 addition & 0 deletions src/deepcode/constants/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const VSCODE_ADD_COMMENT_COMMAND = "editor.action.addCommentLine";
export const DEEPCODE_START_COMMAND = "deepcode.start";
export const DEEPCODE_LOGIN = "deepcode.login";
export const DEEPCODE_APPROVE = "deepcode.approve";
export const DEEPCODE_SETMODE_COMMAND = "deepcode.setmode";
export const DEEPCODE_SETTINGS_COMMAND = "deepcode.settings";
export const DEEPCODE_IGNORE_ISSUES_COMMAND = "deepcode.ignoreissues";
export const DEEPCODE_DCIGNORE_COMMAND = "deepcode.dcignore";
Expand Down
6 changes: 4 additions & 2 deletions src/deepcode/constants/general.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ export const DEEPCODE_EXTENSION_NAME = "deepcode";
export const ALLOWED_PAYLOAD_SIZE = 1024 * 1024 * 4; // max payload size of 4MB in bytes
export const MAX_CONNECTION_RETRIES = 5; // max number of automatic retries before showing an error
export const IDE_NAME = "vscode";
export const EXECUTION_DEBOUNCE_INTERVAL = 1000;
export const REFRESH_VIEW_DEBOUNCE_INTERVAL = 200;
export const EXECUTION_DEBOUNCE_INTERVAL = 1000; // 1 second
export const EXECUTION_THROTTLING_INTERVAL = 1000 * 10;// * 60 * 30; // 30 minutes
export const EXECUTION_PAUSE_INTERVAL = 1000 * 60 * 30; // 30 minutes
export const REFRESH_VIEW_DEBOUNCE_INTERVAL = 200; // 200 milliseconds
8 changes: 8 additions & 0 deletions src/deepcode/constants/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@ export const DEEPCODE_CONTEXT = {
APPROVED: "uploadApproved",
ANALYZING: "workspaceFound",
ERROR: "error",
MODE: "mode",
};

export const DEEPCODE_ERROR_CODES = {
TRANSIENT: "transient",
BLOCKING: "blocking",
};

export const DEEPCODE_MODE_CODES = {
AUTO: 'auto',
MANUAL: 'manual',
PAUSED: 'paused',
THROTTLED: 'throttled',
};

export const DEEPCODE_ANALYSIS_STATUS = {
COLLECTING: "Collecting files",
HASHING: "Hashing files",
Expand Down
61 changes: 56 additions & 5 deletions src/deepcode/lib/modules/DeepCodeLib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,37 @@ import * as _ from "lodash";
import DeepCode from "../../../interfaces/DeepCodeInterfaces";
import BundlesModule from "./BundlesModule";
import { setContext } from "../../utils/vscodeCommandsUtils";
import { DEEPCODE_CONTEXT } from "../../constants/views";
import { EXECUTION_DEBOUNCE_INTERVAL } from "../../constants/general";
import { DEEPCODE_CONTEXT, DEEPCODE_MODE_CODES } from "../../constants/views";
import { errorsLogs } from "../../messages/errorsServerLogMessages";
import {
EXECUTION_DEBOUNCE_INTERVAL,
EXECUTION_THROTTLING_INTERVAL,
EXECUTION_PAUSE_INTERVAL,
} from "../../constants/general";

export default class DeepCodeLib extends BundlesModule implements DeepCode.DeepCodeLibInterface {
private _mode = DEEPCODE_MODE_CODES.AUTO;
// Platform-independant type definition.
private _unpauseTimeout: ReturnType<typeof setTimeout> | undefined;
private _lastThrottledExecution: number | undefined;

private shouldBeThrottled(): boolean {
if (this._mode !== DEEPCODE_MODE_CODES.THROTTLED) return false;
const now = Date.now();
if (
this._lastThrottledExecution === undefined ||
(now - this._lastThrottledExecution) >= EXECUTION_THROTTLING_INTERVAL
) {
this._lastThrottledExecution = now;
return false;
}
return true;
}

private unpause(): void {
if (this._mode === DEEPCODE_MODE_CODES.PAUSED) this.setMode(DEEPCODE_MODE_CODES.AUTO);
}

activateAll(): void {
// this.filesWatcher.activate(this);
this.workspacesWatcher.activate(this);
Expand All @@ -28,10 +54,19 @@ export default class DeepCodeLib extends BundlesModule implements DeepCode.DeepC
this.resetTransientErrors();
}

// This function is called by commands, error handlers, etc.
// We should avoid having duplicate parallel executions.
startExtension = _.debounce(
async (): Promise<void> => {
// This function is called by commands, error handlers, etc.
// We should avoid having duplicate parallel executions.
async (manual = false): Promise<void> => {
// If the execution is suspended, we only allow user-triggered analyses.
if (!manual) {
if ([
DEEPCODE_MODE_CODES.MANUAL,
DEEPCODE_MODE_CODES.PAUSED
].includes(this._mode) ||
this.shouldBeThrottled()
) return;
}
try {
await this.executeExtensionPipeline();
} catch (err) {
Expand All @@ -43,4 +78,20 @@ export default class DeepCodeLib extends BundlesModule implements DeepCode.DeepC
EXECUTION_DEBOUNCE_INTERVAL,
{ 'leading': true }
);

setMode(mode: string): void {
if (!Object.values(DEEPCODE_MODE_CODES).includes(mode)) return;
this._mode = mode;
setContext(DEEPCODE_CONTEXT.MODE, mode);
switch(mode) {
case DEEPCODE_MODE_CODES.PAUSED:
this._unpauseTimeout = setTimeout(this.unpause.bind(this), EXECUTION_PAUSE_INTERVAL);
break;
case DEEPCODE_MODE_CODES.AUTO:
case DEEPCODE_MODE_CODES.MANUAL:
case DEEPCODE_MODE_CODES.THROTTLED:
if (this._unpauseTimeout) clearTimeout(this._unpauseTimeout);
break;
}
}
}
1 change: 1 addition & 0 deletions src/interfaces/DeepCodeInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ namespace DeepCode {

export interface DeepCodeLibInterface {
activateAll(): void;
setMode(mode:string): void;
}

export interface ExtensionInterface
Expand Down

0 comments on commit 5825878

Please sign in to comment.