Skip to content

Commit 02db8c0

Browse files
author
WebFreak001
committed
Added config and build type to status bar
1 parent 8569aef commit 02db8c0

4 files changed

Lines changed: 112 additions & 1 deletion

File tree

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@
9292
"command": "code-d.switchConfiguration",
9393
"title": "code-d: Switch Configuration"
9494
},
95+
{
96+
"command": "code-d.switchBuildType",
97+
"title": "code-d: Switch Build Type"
98+
},
9599
{
96100
"command": "code-d.killServer",
97101
"title": "code-d: Kill DCD Server"

src/extension.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as vscode from 'vscode';
22
import { D_MODE } from "./dmode"
33
import { WorkspaceD } from "./workspace-d"
4+
import * as statusbar from "./statusbar"
45

56
let diagnosticCollection: vscode.DiagnosticCollection;
67

@@ -21,6 +22,7 @@ export function activate(context: vscode.ExtensionContext) {
2122
context.subscriptions.push(vscode.languages.registerDefinitionProvider(D_MODE, workspaced));
2223
context.subscriptions.push(vscode.languages.registerDocumentFormattingEditProvider(D_MODE, workspaced));
2324
context.subscriptions.push(workspaced);
25+
context.subscriptions.push(statusbar.setup(workspaced));
2426

2527
vscode.languages.setLanguageConfiguration(D_MODE.language, {
2628
__electricCharacterSupport: {
@@ -69,6 +71,16 @@ export function activate(context: vscode.ExtensionContext) {
6971
vscode.window.showErrorMessage("Failed to switch configuration. See console for details.");
7072
});
7173

74+
vscode.commands.registerCommand("code-d.switchBuildType", () => {
75+
vscode.window.showQuickPick(workspaced.listBuildTypes()).then((config) => {
76+
if (config)
77+
workspaced.setBuildType(config);
78+
});
79+
}, (err) => {
80+
console.error(err);
81+
vscode.window.showErrorMessage("Failed to switch build type. See console for details.");
82+
});
83+
7284
vscode.commands.registerCommand("code-d.killServer", () => {
7385
workspaced.killServer().then((res) => {
7486
vscode.window.showInformationMessage("Killed DCD-Server", "Restart").then((pick) => {

src/statusbar.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import * as vscode from 'vscode';
2+
import { D_MODE } from "./dmode"
3+
import { WorkspaceD } from "./workspace-d"
4+
5+
export function setup(workspaced: WorkspaceD): vscode.Disposable {
6+
let subscriptions: vscode.Disposable[] = [];
7+
8+
subscriptions.push(new ConfigSelector(workspaced));
9+
subscriptions.push(new BuildSelector(workspaced));
10+
11+
return vscode.Disposable.from(...subscriptions);
12+
}
13+
14+
class ConfigSelector implements vscode.Disposable {
15+
subscriptions: vscode.Disposable[] = [];
16+
private item: vscode.StatusBarItem;
17+
18+
constructor(private workspaced: WorkspaceD) {
19+
workspaced.once("dub-ready", this.create.bind(this));
20+
}
21+
22+
private create() {
23+
this.item = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 2);
24+
this.item.command = "code-d.switchConfiguration";
25+
this.item.show();
26+
this.workspaced.on("configuration-change", config => {
27+
this.item.text = config;
28+
});
29+
this.workspaced.getConfiguration().then(config => {
30+
this.item.text = config;
31+
});
32+
}
33+
34+
dispose() {
35+
vscode.Disposable.from(...this.subscriptions).dispose();
36+
}
37+
}
38+
39+
class BuildSelector implements vscode.Disposable {
40+
subscriptions: vscode.Disposable[] = [];
41+
private item: vscode.StatusBarItem;
42+
43+
constructor(private workspaced: WorkspaceD) {
44+
workspaced.once("dub-ready", this.create.bind(this));
45+
}
46+
47+
private create() {
48+
this.item = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 1);
49+
this.item.command = "code-d.switchBuildType";
50+
this.item.show();
51+
this.workspaced.on("build-type-change", config => {
52+
this.item.text = config;
53+
});
54+
this.workspaced.getBuildType().then(config => {
55+
this.item.text = config;
56+
});
57+
}
58+
59+
dispose() {
60+
vscode.Disposable.from(...this.subscriptions).dispose();
61+
}
62+
}

src/workspace-d.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,16 @@ export class WorkspaceD extends EventEmitter implements
278278
return this.request({ cmd: "dub", subcmd: "list:configurations" });
279279
}
280280

281+
getConfiguration(): Thenable<string> {
282+
return this.request({ cmd: "dub", subcmd: "get:configuration" });
283+
}
284+
281285
setConfiguration(config: string) {
282286
this.request({ cmd: "dub", subcmd: "set:configuration", configuration: config }).then((success) => {
283-
if (success)
287+
if (success) {
284288
this.request({ cmd: "dub", subcmd: "list:import" }).then(console.log);
289+
this.emit("configuration-change", config);
290+
}
285291
else
286292
vscode.window.showInformationMessage("No import paths available for this project. Autocompletion could be broken!", "Switch Configuration").then((s) => {
287293
if (s == "Switch Configuration") {
@@ -291,6 +297,29 @@ export class WorkspaceD extends EventEmitter implements
291297
});
292298
}
293299

300+
listBuildTypes(): Thenable<string[]> {
301+
return this.request({ cmd: "dub", subcmd: "list:build-types" });
302+
}
303+
304+
getBuildType(): Thenable<string> {
305+
return this.request({ cmd: "dub", subcmd: "get:build-type" });
306+
}
307+
308+
setBuildType(config: string) {
309+
this.request({ cmd: "dub", subcmd: "set:build-type", "build-type": config }).then((success) => {
310+
if (success) {
311+
this.request({ cmd: "dub", subcmd: "list:import" }).then(console.log);
312+
this.emit("build-type-change", config);
313+
}
314+
else
315+
vscode.window.showInformationMessage("No import paths available for this build type. Autocompletion could be broken!", "Switch Build Type").then((s) => {
316+
if (s == "Switch Build Type") {
317+
vscode.commands.executeCommand("code-d.switchBuildType");
318+
}
319+
});
320+
});
321+
}
322+
294323
killServer(): Thenable<any> {
295324
if (!this.dcdReady)
296325
return new Promise((resolve, reject) => { reject(); });
@@ -338,6 +367,7 @@ export class WorkspaceD extends EventEmitter implements
338367
this.request({ cmd: "load", components: ["dub"], dir: this.projectRoot }).then((data) => {
339368
console.log("dub is ready");
340369
self.dubReady = true;
370+
self.emit("dub-ready");
341371
self.setupDCD();
342372
self.setupDScanner();
343373
self.setupDfmt();
@@ -357,6 +387,7 @@ export class WorkspaceD extends EventEmitter implements
357387
let self = this;
358388
this.request({ cmd: "load", components: ["dscanner"], dir: this.projectRoot, dscannerPath: config().get("dscannerPath", "dscanner") }).then((data) => {
359389
console.log("DScanner is ready");
390+
self.emit("dscanner-ready");
360391
self.dscannerReady = true;
361392
});
362393
}
@@ -381,6 +412,7 @@ export class WorkspaceD extends EventEmitter implements
381412
let self = this;
382413
this.request({ cmd: "load", components: ["dfmt"], dir: this.projectRoot, dfmtPath: config().get("dfmtPath", "dfmt") }).then((data) => {
383414
console.log("Dfmt is ready");
415+
self.emit("dfmt-ready");
384416
self.dfmtReady = true;
385417
});
386418
}
@@ -413,6 +445,7 @@ export class WorkspaceD extends EventEmitter implements
413445
this.request({ cmd: "dcd", subcmd: "setup-server" }).then((data) => {
414446
this.request({ cmd: "dcd", subcmd: "add-imports", imports: ["/usr/include/dmd/druntime/import", "/usr/include/dmd/phobos"] }).then((data) => {
415447
console.log("DCD is ready");
448+
this.emit("dcd-ready");
416449
this.dcdReady = true;
417450
}, (err) => {
418451
vscode.window.showErrorMessage("Could not initialize DCD. See console for details!");

0 commit comments

Comments
 (0)