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

Sign up
Appearance settings

Commit c9d249d

Browse files
author
Akos Kitta
committed
Added stop/restart LS commands.
No `when` context for now but executing the new commands are a NOOP if stop/restart is not legit. Signed-off-by: Akos Kitta <kittaakos@typefox.io>
1 parent ddb2799 commit c9d249d

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

‎package.json‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@
7070
"activationEvents": [
7171
"onLanguage:ino",
7272
"onCommand:arduino.debug.start",
73-
"onCommand:arduino.languageserver.start"
73+
"onCommand:arduino.languageserver.start",
74+
"onCommand:arduino.languageserver.stop",
75+
"onCommand:arduino.languageserver.restart"
7476
],
7577
"contributes": {
7678
"languages": [
@@ -105,6 +107,16 @@
105107
"title": "Start Language Server",
106108
"category": "Arduino"
107109
},
110+
{
111+
"command": "arduino.languageserver.stop",
112+
"title": "Stop Language Server",
113+
"category": "Arduino"
114+
},
115+
{
116+
"command": "arduino.languageserver.restart",
117+
"title": "Restart Language Server",
118+
"category": "Arduino"
119+
},
108120
{
109121
"command": "arduino.debug.start",
110122
"title": "Start Debug",

‎src/extension.ts‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,28 @@ export function activate(context: ExtensionContext) {
6666
const started = await startLanguageServer(context, config);
6767
languageServerIsRunning = started;
6868
return languageServerIsRunning ? config.board.fqbn : undefined;
69+
} catch (e) {
70+
console.log(e);
71+
languageServerIsRunning = false;
72+
throw e;
6973
} finally {
7074
unlock();
7175
}
7276
}),
77+
vscode.commands.registerCommand('arduino.languageserver.stop', async () => {
78+
const unlock = await languageServerStartMutex.acquire();
79+
try {
80+
await stopLanguageServer(context);
81+
languageServerIsRunning = false;
82+
} finally {
83+
unlock();
84+
}
85+
}),
86+
vscode.commands.registerCommand('arduino.languageserver.restart', async () => {
87+
if (latestConfig) {
88+
return vscode.commands.executeCommand('arduino.languageserver.start', latestConfig);
89+
}
90+
}),
7391
vscode.commands.registerCommand('arduino.debug.start', (config: DebugConfig) => startDebug(context, config))
7492
);
7593
}
@@ -141,7 +159,7 @@ async function startDebug(_: ExtensionContext, config: DebugConfig): Promise<boo
141159
return vscode.debug.startDebugging(undefined, mergedDebugConfig);
142160
}
143161

144-
async function startLanguageServer(context: ExtensionContext,config: LanguageServerConfig): Promise<boolean> {
162+
async function stopLanguageServer(context: ExtensionContext): Promise<void> {
145163
if (languageClient) {
146164
if (languageClient.diagnostics) {
147165
languageClient.diagnostics.clear();
@@ -151,6 +169,10 @@ async function startLanguageServer(context: ExtensionContext, config: LanguageSe
151169
languageServerDisposable.dispose();
152170
}
153171
}
172+
}
173+
174+
async function startLanguageServer(context: ExtensionContext, config: LanguageServerConfig): Promise<boolean> {
175+
await stopLanguageServer(context);
154176
if (!languageClient || !deepEqual(latestConfig, config)) {
155177
latestConfig = config;
156178
languageClient = await buildLanguageClient(config);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /