Skip to content

Commit 7db0b85

Browse files
author
WebFreak001
committed
Added version check
1 parent 02db8c0 commit 7db0b85

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

src/workspace-d.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ function config() {
66
return vscode.workspace.getConfiguration("d");
77
}
88

9+
const TARGET_VERSION = [2, 1, 0];
10+
911
export class WorkspaceD extends EventEmitter implements
1012
vscode.CompletionItemProvider,
1113
vscode.SignatureHelpProvider,
@@ -59,7 +61,7 @@ export class WorkspaceD extends EventEmitter implements
5961
self.startWorkspaceD.call(self);
6062
});
6163
});
62-
this.setupDub();
64+
this.checkVersion();
6365
}
6466

6567
provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Thenable<vscode.CompletionItem[]> {
@@ -362,6 +364,20 @@ export class WorkspaceD extends EventEmitter implements
362364
}
363365
}
364366

367+
private checkVersion() {
368+
this.request({ cmd: "version" }).then(version => {
369+
if (version.major < TARGET_VERSION[0])
370+
return vscode.window.showErrorMessage("workspace-d is outdated! (target=" + formatVersion(TARGET_VERSION) + ", workspaced=" + formatVersion([version.major, version.minor, version.patch]) + ")");
371+
if (version.minor < TARGET_VERSION[1])
372+
return vscode.window.showErrorMessage("workspace-d is outdated! (target=" + formatVersion(TARGET_VERSION) + ", workspaced=" + formatVersion([version.major, version.minor, version.patch]) + ")");
373+
if (version.path < TARGET_VERSION[2])
374+
return vscode.window.showErrorMessage("workspace-d is outdated! (target=" + formatVersion(TARGET_VERSION) + ", workspaced=" + formatVersion([version.major, version.minor, version.patch]) + ")");
375+
this.setupDub();
376+
}, () => {
377+
vscode.window.showErrorMessage("Could not identify workspace-d version. Please update workspace-d!");
378+
});
379+
}
380+
365381
private setupDub() {
366382
let self = this;
367383
this.request({ cmd: "load", components: ["dub"], dir: this.projectRoot }).then((data) => {
@@ -547,4 +563,8 @@ export class WorkspaceD extends EventEmitter implements
547563
t: vscode.CompletionItemKind.Property,
548564
T: vscode.CompletionItemKind.Property,
549565
};
566+
}
567+
568+
function formatVersion(version: number[]): string {
569+
return version[0] + "." + version[1] + "." + version[2];
550570
}

0 commit comments

Comments
 (0)