Skip to content

Commit 9448951

Browse files
author
WebFreak001
committed
Added support for switching configurations
1 parent eb96b34 commit 9448951

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

package.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,13 @@
8686
"description": "Start dcd-server at startup and complete using dcd-client."
8787
}
8888
}
89-
}
89+
},
90+
"commands": [
91+
{
92+
"command": "code-d.switchConfiguration",
93+
"title": "code-d: Switch Configuration"
94+
}
95+
]
9096
},
9197
"scripts": {
9298
"vscode:prepublish": "node ./node_modules/vscode/bin/compile",

src/extension.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,20 @@ export function activate(context: vscode.ExtensionContext) {
3030
context.subscriptions.push(vscode.workspace.onDidSaveTextDocument(document => {
3131
if (document.languageId != "d")
3232
return;
33-
if(config().get("enableLinting", true))
33+
if (config().get("enableLinting", true))
3434
workspaced.lint(document).then(errors => {
3535
diagnosticCollection.delete(document.uri);
3636
diagnosticCollection.set(document.uri, errors);
3737
});
3838
}));
3939

40+
vscode.commands.registerCommand("code-d.switchConfiguration", () => {
41+
let self = <WorkspaceD>workspaced;
42+
vscode.window.showQuickPick(self.listConfigurations()).then((config) => {
43+
if (config)
44+
self.setConfiguration(config);
45+
});
46+
});
47+
4048
console.log("Initialized code-d");
4149
}

src/workspace-d.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,22 @@ export class WorkspaceD extends EventEmitter implements
274274
this.instance.kill();
275275
}
276276

277+
listConfigurations(): Thenable<string[]> {
278+
return this.request({ cmd: "dub", subcmd: "list:configurations" });
279+
}
280+
281+
setConfiguration(config: string) {
282+
this.request({ cmd: "dub", subcmd: "set:configuration", configuration: config }).then((success) => {
283+
console.log("Configuration: " + config + " = " + success);
284+
if (!success)
285+
vscode.window.showInformationMessage("No import paths available for this project. Autocompletion could be broken!", "Switch Configuration").then((s) => {
286+
if (s == "Switch Configuration") {
287+
vscode.commands.executeCommand("code-d.switchConfiguration");
288+
}
289+
});
290+
});
291+
}
292+
277293
private mapLintType(type: string): vscode.DiagnosticSeverity {
278294
switch (type) {
279295
case "warn":
@@ -292,6 +308,13 @@ export class WorkspaceD extends EventEmitter implements
292308
self.setupDCD();
293309
self.setupDScanner();
294310
self.setupDfmt();
311+
self.listConfigurations().then((configs) => {
312+
if (configs.length == 0) {
313+
vscode.window.showInformationMessage("No configurations available for this project. Autocompletion could be broken!");
314+
} else {
315+
self.setConfiguration(configs[0]);
316+
}
317+
});
295318
}, (err) => {
296319
vscode.window.showErrorMessage("Could not initialize dub. See console for details!");
297320
});

0 commit comments

Comments
 (0)