Skip to content

Commit d43662c

Browse files
author
WebFreak001
committed
Added kill, restart DCD server commands & fixed potential dispose bug on slow machines
1 parent 54e1887 commit d43662c

3 files changed

Lines changed: 50 additions & 4 deletions

File tree

package.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,14 @@
9191
{
9292
"command": "code-d.switchConfiguration",
9393
"title": "code-d: Switch Configuration"
94+
},
95+
{
96+
"command": "code-d.killServer",
97+
"title": "code-d: Kill DCD Server"
98+
},
99+
{
100+
"command": "code-d.restartServer",
101+
"title": "code-d: Restart DCD Server"
94102
}
95103
],
96104
"jsonValidation": [

src/extension.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,33 @@ export function activate(context: vscode.ExtensionContext) {
6060
}));
6161

6262
vscode.commands.registerCommand("code-d.switchConfiguration", () => {
63-
let self = <WorkspaceD>workspaced;
64-
vscode.window.showQuickPick(self.listConfigurations()).then((config) => {
63+
vscode.window.showQuickPick(workspaced.listConfigurations()).then((config) => {
6564
if (config)
66-
self.setConfiguration(config);
65+
workspaced.setConfiguration(config);
66+
});
67+
}, (err) => {
68+
console.error(err);
69+
vscode.window.showErrorMessage("Failed to switch configuration. See console for details.");
70+
});
71+
72+
vscode.commands.registerCommand("code-d.killServer", () => {
73+
workspaced.killServer().then((res) => {
74+
vscode.window.showInformationMessage("Killed DCD-Server", "Restart").then((pick) => {
75+
if (pick == "Restart")
76+
vscode.commands.executeCommand("code-d.restartServer");
77+
});
78+
}, (err) => {
79+
console.error(err);
80+
vscode.window.showErrorMessage("Failed to kill DCD-Server. See console for details.");
81+
});
82+
});
83+
84+
vscode.commands.registerCommand("code-d.restartServer", () => {
85+
workspaced.restartServer().then((res) => {
86+
vscode.window.showInformationMessage("Restarted DCD-Server");
87+
}, (err) => {
88+
console.error(err);
89+
vscode.window.showErrorMessage("Failed to kill DCD-Server. See console for details.");
6790
});
6891
});
6992

src/workspace-d.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@ export class WorkspaceD extends EventEmitter implements
1919
let self = this;
2020
this.on("error", function(err) {
2121
console.error(err);
22-
self.ensureDCDRunning();
22+
if (this.shouldRestart)
23+
self.ensureDCDRunning();
2324
});
2425
this.startWorkspaceD();
2526
}
2627

2728
startWorkspaceD() {
29+
if (!this.shouldRestart)
30+
return;
2831
let self = this;
2932
this.workspaced = true;
3033
let path = config().get("workspacedPath", "workspace-d");
@@ -267,6 +270,7 @@ export class WorkspaceD extends EventEmitter implements
267270
}
268271

269272
dispose() {
273+
this.shouldRestart = false;
270274
console.log("Disposing");
271275
this.request({ cmd: "unload", components: "*" }).then((data) => {
272276
console.log("Unloaded " + data.join(", "));
@@ -291,6 +295,14 @@ export class WorkspaceD extends EventEmitter implements
291295
});
292296
}
293297

298+
killServer(): Thenable<any> {
299+
return this.request({ cmd: "dcd", subcmd: "kill-server" });
300+
}
301+
302+
restartServer(): Thenable<any> {
303+
return this.request({ cmd: "dcd", subcmd: "restart-server" });
304+
}
305+
294306
private mapLintType(type: string): vscode.DiagnosticSeverity {
295307
switch (type) {
296308
case "warn":
@@ -356,6 +368,8 @@ export class WorkspaceD extends EventEmitter implements
356368
private ensureDCDRunning() {
357369
if (!this.dcdReady)
358370
return;
371+
if (!this.shouldRestart)
372+
return;
359373
clearTimeout(this.runCheckTimeout);
360374
this.runCheckTimeout = setTimeout((() => {
361375
console.log("Checking status...");
@@ -445,6 +459,7 @@ export class WorkspaceD extends EventEmitter implements
445459
private dcdReady: boolean = false;
446460
private dfmtReady: boolean = false;
447461
private dscannerReady: boolean = false;
462+
private shouldRestart: boolean = true;
448463
private totalData: Buffer;
449464
private requestNum = 0;
450465
private instance: ChildProcess.ChildProcess;

0 commit comments

Comments
 (0)