Skip to content

Commit 55e78b8

Browse files
Build changes and minor tweaks (#6)
* Add VSCode workspace files for local development * Minor code cleanup * Re-label "Restart LSP Server" command for clarity * Tweak how output channels are handled when running Brioche builds * Tweak "Show output" button labels * Add missing new line --------- Co-authored-by: Ashley Hutson <[email protected]>
1 parent c326679 commit 55e78b8

File tree

7 files changed

+100
-33
lines changed

7 files changed

+100
-33
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ dist
33
node_modules
44
.vscode-test/
55
*.vsix
6+
7+
# Include .vscode even when excluded globally
8+
!.vscode

.vscode/extensions.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
// See http://go.microsoft.com/fwlink/?LinkId=827846
3+
// for the documentation about the extensions.json format
4+
"recommendations": [
5+
"dbaeumer.vscode-eslint",
6+
"ms-vscode.extension-test-runner"
7+
]
8+
}

.vscode/launch.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// A launch configuration that compiles the extension and then opens it inside a new window
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
{
6+
"version": "0.2.0",
7+
"configurations": [
8+
{
9+
"name": "Run Extension",
10+
"type": "extensionHost",
11+
"request": "launch",
12+
"args": [
13+
"--extensionDevelopmentPath=${workspaceFolder}"
14+
],
15+
"outFiles": [
16+
"${workspaceFolder}/out/**/*.js"
17+
],
18+
"preLaunchTask": "${defaultBuildTask}"
19+
}
20+
]
21+
}

.vscode/settings.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Place your settings in this file to overwrite default and user settings.
2+
{
3+
"files.exclude": {
4+
"out": false // set this to true to hide the "out" folder with the compiled JS files
5+
},
6+
"search.exclude": {
7+
"out": true // set this to false to include "out" folder in search results
8+
},
9+
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
10+
"typescript.tsc.autoDetect": "off"
11+
}

.vscode/tasks.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// See https://go.microsoft.com/fwlink/?LinkId=733558
2+
// for the documentation about the tasks.json format
3+
{
4+
"version": "2.0.0",
5+
"tasks": [
6+
{
7+
"type": "npm",
8+
"script": "watch",
9+
"problemMatcher": "$tsc-watch",
10+
"isBackground": true,
11+
"presentation": {
12+
"reveal": "never"
13+
},
14+
"group": {
15+
"kind": "build",
16+
"isDefault": true
17+
}
18+
}
19+
]
20+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"commands": [
2626
{
2727
"command": "brioche-vscode.restartLsp",
28-
"title": "Brioche LSP: Restart LSP Server"
28+
"title": "Brioche: Restart LSP Server"
2929
},
3030
{
3131
"command": "brioche-vscode.runBriocheBuild",

src/extension.ts

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ let lspOutputChannel: OutputChannel;
3535
function getBriocheBinaryPath(): string {
3636
const configPath = workspace
3737
.getConfiguration("brioche")
38-
.get<string>("binaryPath");
39-
return configPath && configPath.trim() ? configPath.trim() : "brioche";
38+
.get<string>("binaryPath")
39+
?.trim();
40+
return configPath || "brioche";
4041
}
4142

4243
/**
@@ -67,22 +68,7 @@ function getBriocheLogLevel(): string | undefined {
6768
const logLevel =
6869
workspace.getConfiguration("brioche").get<string>("log.level") || "off";
6970

70-
switch (logLevel) {
71-
case "off":
72-
return "brioche=off";
73-
case "error":
74-
return "brioche=error";
75-
case "warn":
76-
return "brioche=warn";
77-
case "info":
78-
return "brioche=info";
79-
case "debug":
80-
return "brioche=debug";
81-
case "trace":
82-
return "brioche=trace";
83-
default:
84-
return undefined;
85-
}
71+
return `brioche=${logLevel}`;
8672
}
8773

8874
async function startClient(): Promise<void> {
@@ -98,17 +84,12 @@ async function startClient(): Promise<void> {
9884
const rustLogLevel = getBriocheLogLevel();
9985

10086
// Build environment variables for LSP
101-
let env = {
87+
const env = {
10288
...process.env,
89+
...(rustLogLevel ? {RUST_LOG: rustLogLevel} : {}),
90+
...lspEnvVars,
10391
};
10492

105-
// Add RUST_LOG if specified
106-
if (rustLogLevel) {
107-
env["RUST_LOG"] = rustLogLevel;
108-
}
109-
110-
env = { ...env, ...lspEnvVars };
111-
11293
// Configure server options
11394
const serverOptions: ServerOptions = {
11495
command: briochePath,
@@ -288,13 +269,12 @@ async function runBriocheBuild(): Promise<void> {
288269
process.stdout?.on("data", (data: Buffer) => {
289270
const output = data.toString();
290271
outputChannel.append(output);
291-
outputChannel.show(true); // Force the output channel to remain visible
292272
progress.report({ message: "Building project..." });
293273
});
294274

295275
process.stderr?.on("data", (data: Buffer) => {
296276
outputChannel.append(data.toString());
297-
outputChannel.show(true); // Show output immediately for errors
277+
progress.report({ message: "Building project..." });
298278
});
299279

300280
token.onCancellationRequested(() => {
@@ -304,15 +284,39 @@ async function runBriocheBuild(): Promise<void> {
304284
});
305285

306286
process.on("close", (code: number | null) => {
287+
const showOutputButton = "Show output";
288+
307289
if (code === 0) {
308290
outputChannel.appendLine("\nBuild completed successfully!");
309-
window.showInformationMessage("Build completed successfully!");
291+
window.showInformationMessage("Build completed successfully!", showOutputButton).then((item) => {
292+
// Show the output if the user clicks "Show output"
293+
if (item === showOutputButton) {
294+
outputChannel.show(true);
295+
}
296+
});
297+
resolve();
298+
} else if (code != null) {
299+
const message = `Build failed with exit code ${code}`;
300+
outputChannel.appendLine(`\n${message}`);
301+
302+
window.showErrorMessage(message, showOutputButton).then((item) => {
303+
// Show the output if the user clicks "Show output"
304+
if (item === showOutputButton) {
305+
outputChannel.show(true);
306+
}
307+
});
310308
resolve();
311309
} else {
312-
const message = `Build failed with code ${code}`;
310+
const message = "Build stopped";
313311
outputChannel.appendLine(`\n${message}`);
314-
window.showErrorMessage(message);
315-
reject(new Error(message));
312+
313+
window.showErrorMessage(message, showOutputButton).then((item) => {
314+
// Show the output if the user clicks "Show output"
315+
if (item === showOutputButton) {
316+
outputChannel.show(true);
317+
}
318+
});
319+
resolve();
316320
}
317321
});
318322

0 commit comments

Comments
 (0)