Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8fef882

Browse filesBrowse files
authored
Merge pull request #10 from arduino/mutex-ls-start
Guard LS start with mutex.
2 parents 16db578 + 0a26e1e commit 8fef882
Copy full SHA for 8fef882

File tree

Expand file treeCollapse file tree

3 files changed

+29
-2
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+29
-2
lines changed

‎package.json

Copy file name to clipboardExpand all lines: package.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
},
4141
"dependencies": {
4242
"@types/deep-equal": "^1.0.1",
43+
"async-mutex": "^0.3.0",
4344
"deep-equal": "^2.0.3",
4445
"deepmerge": "^4.2.2",
4546
"path": "^0.12.7",

‎src/extension.ts

Copy file name to clipboardExpand all lines: src/extension.ts
+16-2Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { spawnSync } from 'child_process';
55
import deepEqual from 'deep-equal';
66
import WebRequest from 'web-request';
77
import deepmerge from 'deepmerge';
8+
import { Mutex } from 'async-mutex';
89
import vscode, { ExtensionContext } from 'vscode';
910
import { LanguageClient, CloseAction, ErrorAction, InitializeError, Message, RevealOutputChannelOn } from 'vscode-languageclient';
1011

@@ -54,10 +55,21 @@ let languageClient: LanguageClient | undefined;
5455
let languageServerDisposable: vscode.Disposable | undefined;
5556
let latestConfig: LanguageServerConfig | undefined;
5657
let crashCount = 0;
58+
const languageServerStartMutex = new Mutex();
59+
export let languageServerIsRunning = false; // TODO: use later for `start`, `stop`, and `restart` language server.
5760

5861
export function activate(context: ExtensionContext) {
5962
context.subscriptions.push(
60-
vscode.commands.registerCommand('arduino.languageserver.start', (config: LanguageServerConfig) => startLanguageServer(context, config)),
63+
vscode.commands.registerCommand('arduino.languageserver.start', async (config: LanguageServerConfig) => {
64+
const unlock = await languageServerStartMutex.acquire();
65+
try {
66+
const started = await startLanguageServer(context, config);
67+
languageServerIsRunning = started;
68+
return languageServerIsRunning ? config.board.fqbn : undefined;
69+
} finally {
70+
unlock();
71+
}
72+
}),
6173
vscode.commands.registerCommand('arduino.debug.start', (config: DebugConfig) => startDebug(context, config))
6274
);
6375
}
@@ -129,7 +141,7 @@ async function startDebug(_: ExtensionContext, config: DebugConfig): Promise<boo
129141
return vscode.debug.startDebugging(undefined, mergedDebugConfig);
130142
}
131143

132-
async function startLanguageServer(context: ExtensionContext, config: LanguageServerConfig): Promise<void> {
144+
async function startLanguageServer(context: ExtensionContext, config: LanguageServerConfig): Promise<boolean> {
133145
if (languageClient) {
134146
if (languageClient.diagnostics) {
135147
languageClient.diagnostics.clear();
@@ -147,6 +159,8 @@ async function startLanguageServer(context: ExtensionContext, config: LanguageSe
147159

148160
languageServerDisposable = languageClient.start();
149161
context.subscriptions.push(languageServerDisposable);
162+
await languageClient.onReady();
163+
return true;
150164
}
151165

152166
async function buildLanguageClient(config: LanguageServerConfig): Promise<LanguageClient> {

‎yarn.lock

Copy file name to clipboardExpand all lines: yarn.lock
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,13 @@ async-each@^1.0.1:
382382
resolved "https://registry.yarnpkg.com/async-each/-/async-each-1.0.3.tgz#b727dbf87d7651602f06f4d4ac387f47d91b0cbf"
383383
integrity sha512-z/WhQ5FPySLdvREByI2vZiTWwCnF0moMJ1hK9YQwDTHKh6I7/uSckMetoRGb5UBZPC1z0jlw+n/XCgjeH7y1AQ==
384384

385+
async-mutex@^0.3.0:
386+
version "0.3.0"
387+
resolved "https://registry.yarnpkg.com/async-mutex/-/async-mutex-0.3.0.tgz#5bc765c271dfc05c48040c12032a92f1dbef2dc3"
388+
integrity sha512-6VIpUM7s37EMXvnO3TvujgaS6gx4yJby13BhxovMYSap7nrbS0gJ1UzGcjD+HElNSdTz/+IlAIqj7H48N0ZlyQ==
389+
dependencies:
390+
tslib "^2.1.0"
391+
385392
asynckit@^0.4.0:
386393
version "0.4.0"
387394
resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79"
@@ -3763,6 +3770,11 @@ tslib@^1.9.0:
37633770
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.13.0.tgz#c881e13cc7015894ed914862d276436fa9a47043"
37643771
integrity sha512-i/6DQjL8Xf3be4K/E6Wgpekn5Qasl1usyw++dAA35Ue5orEn65VIxOA+YvNNl9HV3qv70T7CNwjODHZrLwvd1Q==
37653772

3773+
tslib@^2.1.0:
3774+
version "2.1.0"
3775+
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.1.0.tgz#da60860f1c2ecaa5703ab7d39bc05b6bf988b97a"
3776+
integrity sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A==
3777+
37663778
tty-browserify@0.0.0:
37673779
version "0.0.0"
37683780
resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.0.tgz#a157ba402da24e9bf957f9aa69d524eed42901a6"

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.