Skip to content

Commit df0aafd

Browse files
Akos Kittakittaakos
Akos Kitta
authored andcommitted
GH-13: Forbid parallel LS-start command execution.
From now on, a port change won't trigger LS start. Signed-off-by: Akos Kitta <[email protected]>
1 parent ad2cfc8 commit df0aafd

File tree

3 files changed

+50
-27
lines changed

3 files changed

+50
-27
lines changed

Diff for: arduino-ide-extension/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"@types/temp": "^0.8.34",
4747
"@types/which": "^1.3.1",
4848
"ajv": "^6.5.3",
49+
"async-mutex": "^0.3.0",
4950
"css-element-queries": "^1.2.0",
5051
"dateformat": "^3.0.3",
5152
"deepmerge": "^4.2.2",

Diff for: arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx

+37-27
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const debounce = require('lodash.debounce');
1+
import { Mutex } from 'async-mutex';
22
import { MAIN_MENU_BAR, MenuContribution, MenuModelRegistry, SelectionService, ILogger } from '@theia/core';
33
import {
44
ContextMenuRenderer,
@@ -201,7 +201,6 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
201201
if (selectedBoard) {
202202
const { name, fqbn } = selectedBoard;
203203
if (fqbn) {
204-
await this.hostedPluginSupport.didStart;
205204
this.startLanguageServer(fqbn, name);
206205
}
207206
}
@@ -225,33 +224,44 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
225224
});
226225
}
227226

228-
protected startLanguageServer = debounce((fqbn: string, name: string | undefined) => this.doStartLanguageServer(fqbn, name));
229-
protected async doStartLanguageServer(fqbn: string, name: string | undefined): Promise<void> {
230-
this.logger.info(`Starting language server: ${fqbn}`);
231-
const log = this.arduinoPreferences.get('arduino.language.log');
232-
let currentSketchPath: string | undefined = undefined;
233-
if (log) {
234-
const currentSketch = await this.sketchServiceClient.currentSketch();
235-
if (currentSketch) {
236-
currentSketchPath = await this.fileSystem.fsPath(new URI(currentSketch.uri));
227+
protected languageServerFqbn?: string;
228+
protected languageServerStartMutex = new Mutex();
229+
protected async startLanguageServer(fqbn: string, name: string | undefined): Promise<void> {
230+
const release = await this.languageServerStartMutex.acquire();
231+
try {
232+
if (fqbn === this.languageServerFqbn) {
233+
// NOOP
234+
return;
237235
}
238-
}
239-
const { clangdUri, cliUri, lsUri } = await this.executableService.list();
240-
const [clangdPath, cliPath, lsPath] = await Promise.all([
241-
this.fileSystem.fsPath(new URI(clangdUri)),
242-
this.fileSystem.fsPath(new URI(cliUri)),
243-
this.fileSystem.fsPath(new URI(lsUri)),
244-
]);
245-
this.commandRegistry.executeCommand('arduino.languageserver.start', {
246-
lsPath,
247-
cliPath,
248-
clangdPath,
249-
log: currentSketchPath ? currentSketchPath : log,
250-
board: {
251-
fqbn,
252-
name: name ? `"${name}"` : undefined
236+
await this.hostedPluginSupport.didStart;
237+
this.logger.info(`Starting language server: ${fqbn}`);
238+
const log = this.arduinoPreferences.get('arduino.language.log');
239+
let currentSketchPath: string | undefined = undefined;
240+
if (log) {
241+
const currentSketch = await this.sketchServiceClient.currentSketch();
242+
if (currentSketch) {
243+
currentSketchPath = await this.fileSystem.fsPath(new URI(currentSketch.uri));
244+
}
253245
}
254-
});
246+
const { clangdUri, cliUri, lsUri } = await this.executableService.list();
247+
const [clangdPath, cliPath, lsPath] = await Promise.all([
248+
this.fileSystem.fsPath(new URI(clangdUri)),
249+
this.fileSystem.fsPath(new URI(cliUri)),
250+
this.fileSystem.fsPath(new URI(lsUri)),
251+
]);
252+
this.languageServerFqbn = await this.commandRegistry.executeCommand('arduino.languageserver.start', {
253+
lsPath,
254+
cliPath,
255+
clangdPath,
256+
log: currentSketchPath ? currentSketchPath : log,
257+
board: {
258+
fqbn,
259+
name: name ? `"${name}"` : undefined
260+
}
261+
});
262+
} finally {
263+
release();
264+
}
255265
}
256266

257267
registerToolbarItems(registry: TabBarToolbarRegistry): void {

Diff for: yarn.lock

+12
Original file line numberDiff line numberDiff line change
@@ -3804,6 +3804,13 @@ async-limiter@~1.0.0:
38043804
resolved "https://registry.yarnpkg.com/async-limiter/-/async-limiter-1.0.1.tgz#dd379e94f0db8310b08291f9d64c3209766617fd"
38053805
integrity sha512-csOlWGAcRFJaI6m+F2WKdnMKr4HhdhFVBk0H/QbJFMCr+uO2kwohwXQPxw/9OCxp05r5ghVBFSyioixx3gfkNQ==
38063806

3807+
async-mutex@^0.3.0:
3808+
version "0.3.0"
3809+
resolved "https://registry.yarnpkg.com/async-mutex/-/async-mutex-0.3.0.tgz#5bc765c271dfc05c48040c12032a92f1dbef2dc3"
3810+
integrity sha512-6VIpUM7s37EMXvnO3TvujgaS6gx4yJby13BhxovMYSap7nrbS0gJ1UzGcjD+HElNSdTz/+IlAIqj7H48N0ZlyQ==
3811+
dependencies:
3812+
tslib "^2.1.0"
3813+
38073814
38083815
version "0.9.2"
38093816
resolved "https://registry.yarnpkg.com/async/-/async-0.9.2.tgz#aea74d5e61c1f899613bf64bda66d4c78f2fd17d"
@@ -14580,6 +14587,11 @@ tslib@^1.10.0, tslib@^1.8.0, tslib@^1.8.1, tslib@^1.9.0:
1458014587
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
1458114588
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==
1458214589

14590+
tslib@^2.1.0:
14591+
version "2.1.0"
14592+
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.1.0.tgz#da60860f1c2ecaa5703ab7d39bc05b6bf988b97a"
14593+
integrity sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A==
14594+
1458314595
tslint@^5.5.0:
1458414596
version "5.20.1"
1458514597
resolved "https://registry.yarnpkg.com/tslint/-/tslint-5.20.1.tgz#e401e8aeda0152bc44dd07e614034f3f80c67b7d"

0 commit comments

Comments
 (0)