Skip to content

Commit 0fb668d

Browse files
committed
VSCode extension: add support for bpp-lsp's -j/--threads
Connected to 6d721b5 The VSCode extension now has a configurable option for the number of worker threads in the language server. Both this feature and the earlier-added support for -b (target-bash-version) are now gated behind bpp-lsp version number checks. - -b was introduced in v0.8.0. If the version number < 0.8.0, the extension will ignore the configured option for -b, and show a warning to the user - -j will be introduced in the upcoming v0.8.11. As with -b, if the version number isn't high enough, the option is ignored and warning is displayed
1 parent 6d721b5 commit 0fb668d

4 files changed

Lines changed: 263 additions & 204 deletions

File tree

vscode/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Change Log
22

3+
## [0.8.1]
4+
- Added support for bpp-lsp's `-j`/`--threads` option to specify the number of worker threads in the language server
5+
- This option allows users to configure the performance of the language server by specifying how many worker threads it should use for processing requests.
6+
- Users can set this option in the VSCode extension settings under `Bash++: Language Server: Thread Count`.
7+
- By default, the language server will use a number of threads equal to the number of CPU cores available.
8+
- Gated `-b` and `-j` options behind a check for the language server's version to ensure compatibility
9+
- `-b` was introduced in bpp-lsp v0.8.0, and `-j` was introduced in bpp-lsp v0.8.11
10+
- If the language server does not support these options, the extension will fall back to default behavior without them, and will show a startup warning to the user
11+
312
## [0.8.0]
413

514
- Added support for bpp-lsp's `-b`/`--target-bash` option to specify the target Bash version for compilation

vscode/extension.js

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,52 @@
11
const vscode = require('vscode');
22
const { LanguageClient, TransportKind } = require('vscode-languageclient');
3+
const { execFile } = require('child_process');
4+
const { promisify } = require('util');
5+
const execFileAsync = promisify(execFile);
36

47
/** @type {LanguageClient | null} */
58
let client = null;
69

10+
/**
11+
* `bpp-lsp --version` outputs:
12+
* Bash++ Language Server x.y.z
13+
* .. more lines
14+
*
15+
* So here, we just call `--version`,
16+
* and scan the first line for [0-9]+\.[0-9]+\.[0-9]+
17+
*
18+
* We return it as an array of 3 elements: [major, minor, patch]
19+
* If the version cannot be determined, we return [0, 0, 0]
20+
*/
21+
async function getServerVersion(serverPath) {
22+
try {
23+
const { stdout } = await execFileAsync(serverPath, ['--version']);
24+
const firstLine = stdout.split('\n')[0];
25+
const versionMatch = firstLine.match(/(\d+)\.(\d+)\.(\d+)/);
26+
if (versionMatch) {
27+
return versionMatch.slice(1, 4).map(num => parseInt(num, 10));
28+
}
29+
} catch (err) {
30+
vscode.window.showInformationMessage('Warning: Unable to determine Bash++ Language Server version. Some features may not work as expected. Please ensure the server is installed and accessible.');
31+
}
32+
return [0, 0, 0];
33+
}
34+
35+
/**
36+
* Function to compare two version arrays [major, minor, patch]
37+
* Returns true if versionA >= versionB
38+
*/
39+
function isVersionGreaterOrEqual(versionA, versionB) {
40+
for (let i = 0; i < 3; i++) {
41+
if (versionA[i] > versionB[i]) {
42+
return true;
43+
} else if (versionA[i] < versionB[i]) {
44+
return false;
45+
}
46+
}
47+
return true; // versions are equal
48+
}
49+
750
async function stopClient() {
851
if (client) {
952
await client.stop();
@@ -32,6 +75,10 @@ async function startClient(context) {
3275
return;
3376
}
3477

78+
// First: get the server version to determine which features are supported
79+
const serverVersion = await getServerVersion(serverPath);
80+
console.log(`Bash++ Language Server version: ${serverVersion.join('.')}`);
81+
3582
const args = ['--stdio'];
3683

3784
if (!config.get('showWarnings', true)) {
@@ -51,8 +98,24 @@ async function startClient(context) {
5198
});
5299

53100
// Get the target bash version
54-
const targetBashVersion = config.get('targetBashVersion', '5.2');
55-
args.push(`-b${targetBashVersion}`);
101+
// Note: '-b' was introduced in 0.8.0
102+
if (isVersionGreaterOrEqual(serverVersion, [0, 8, 0])) {
103+
const targetBashVersion = config.get('targetBashVersion', '5.2');
104+
args.push(`-b${targetBashVersion}`);
105+
} else {
106+
vscode.window.showInformationMessage('Bash++ Language Server version does not support target bash version configuration. Please upgrade to bpp-lsp 0.8.0 or later to use this feature.');
107+
}
108+
109+
// Get the thread count for the language server
110+
// Note: '-j' was introduced in 0.8.11
111+
if (isVersionGreaterOrEqual(serverVersion, [0, 8, 11])) {
112+
const threadCount = config.get('threadCount', 0);
113+
if (threadCount > 0) {
114+
args.push(`-j${threadCount}`);
115+
}
116+
} else {
117+
vscode.window.showInformationMessage('Bash++ Language Server version does not support thread count configuration. Please upgrade to bpp-lsp 0.8.11 or later to use this feature.');
118+
}
56119

57120
const serverOptions = {
58121
run: {

0 commit comments

Comments
 (0)