Skip to content

Commit 8569aef

Browse files
author
WebFreak001
committed
Added reload imports (fix #11)
1 parent d43662c commit 8569aef

3 files changed

Lines changed: 41 additions & 6 deletions

File tree

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@
9999
{
100100
"command": "code-d.restartServer",
101101
"title": "code-d: Restart DCD Server"
102+
},
103+
{
104+
"command": "code-d.reloadImports",
105+
"title": "code-d: Reload import paths"
102106
}
103107
],
104108
"jsonValidation": [

src/extension.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,16 @@ export function activate(context: vscode.ExtensionContext) {
9090
});
9191
});
9292

93+
vscode.commands.registerCommand("code-d.reloadImports", () => {
94+
workspaced.updateImports().then((success) => {
95+
if (success)
96+
vscode.window.showInformationMessage("Successfully reloaded import paths");
97+
else
98+
vscode.window.showWarningMessage("Import paths are empty!");
99+
}, (err) => {
100+
vscode.window.showErrorMessage("Could not update imports. dub might not be initialized yet!");
101+
});
102+
});
103+
93104
console.log("Initialized code-d");
94105
}

src/workspace-d.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,10 +228,8 @@ export class WorkspaceD extends EventEmitter implements
228228
let self = this;
229229
console.log("provideDocumentFormattingEdits");
230230
return new Promise((resolve, reject) => {
231-
if (!self.dfmtReady) {
232-
console.log("Resolve null");
231+
if (!self.dfmtReady)
233232
return resolve(null);
234-
}
235233
self.request({ cmd: "dfmt", code: document.getText() }).then((formatted) => {
236234
let lastLine = document.lineCount;
237235
let lastLineLastCol = document.lineAt(lastLine - 1).range.end.character;
@@ -247,10 +245,8 @@ export class WorkspaceD extends EventEmitter implements
247245
let self = this;
248246
console.log("lint");
249247
return new Promise((resolve, reject) => {
250-
if (!self.dscannerReady) {
251-
console.log("Resolve null");
248+
if (!self.dscannerReady)
252249
return resolve(null);
253-
}
254250
self.request({ cmd: "dscanner", subcmd: "lint", file: document.uri.fsPath }).then(issues => {
255251
let diagnostics: vscode.Diagnostic[] = [];
256252
if (issues && issues.length)
@@ -296,13 +292,37 @@ export class WorkspaceD extends EventEmitter implements
296292
}
297293

298294
killServer(): Thenable<any> {
295+
if (!this.dcdReady)
296+
return new Promise((resolve, reject) => { reject(); });
299297
return this.request({ cmd: "dcd", subcmd: "kill-server" });
300298
}
301299

302300
restartServer(): Thenable<any> {
301+
if (!this.dcdReady)
302+
return new Promise((resolve, reject) => { reject(); });
303303
return this.request({ cmd: "dcd", subcmd: "restart-server" });
304304
}
305305

306+
updateImports(): Thenable<boolean> {
307+
return new Promise((resolve, reject) => {
308+
if (!this.dubReady)
309+
reject();
310+
this.request({ cmd: "dub", subcmd: "update" }).then((success) => {
311+
if (!success)
312+
return resolve(success);
313+
if (this.dcdReady) {
314+
this.request({ cmd: "dcd", subcmd: "refresh-imports" }).then(() => {
315+
resolve(true);
316+
this.request({ cmd: "dub", subcmd: "list:import" }).then(console.log);
317+
});
318+
} else {
319+
vscode.window.showWarningMessage("Could not update DCD. Please restart DCD if its not working properly");
320+
resolve(true);
321+
}
322+
});
323+
});
324+
}
325+
306326
private mapLintType(type: string): vscode.DiagnosticSeverity {
307327
switch (type) {
308328
case "warn":

0 commit comments

Comments
 (0)