Skip to content

Commit 0421756

Browse files
committed
Implement stop and start server commands
1 parent d68616a commit 0421756

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

editors/code/package.json

+11
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"onCommand:rust-analyzer.analyzerStatus",
6161
"onCommand:rust-analyzer.memoryUsage",
6262
"onCommand:rust-analyzer.reloadWorkspace",
63+
"onCommand:rust-analyzer.startServer",
6364
"workspaceContains:*/Cargo.toml",
6465
"workspaceContains:*/rust-project.json"
6566
],
@@ -191,6 +192,16 @@
191192
"title": "Restart server",
192193
"category": "rust-analyzer"
193194
},
195+
{
196+
"command": "rust-analyzer.startServer",
197+
"title": "Start server",
198+
"category": "rust-analyzer"
199+
},
200+
{
201+
"command": "rust-analyzer.stopServer",
202+
"title": "Stop server",
203+
"category": "rust-analyzer"
204+
},
194205
{
195206
"command": "rust-analyzer.onEnter",
196207
"title": "Enhanced enter key",

editors/code/src/client.ts

+8
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ export async function createClient(
7676
outputChannel,
7777
middleware: {
7878
workspace: {
79+
// HACK: This is a workaround, when the client has been disposed, VSCode
80+
// continues to emit events to the client and the default one for this event
81+
// attempt to restart the client for no reason
82+
async didChangeWatchedFile(event, next) {
83+
if (client.isRunning()) {
84+
await next(event);
85+
}
86+
},
7987
async configuration(
8088
params: lc.ConfigurationParams,
8189
token: vscode.CancellationToken,

editors/code/src/ctx.ts

-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ export class Ctx {
6868
}
6969

7070
if (!this.client) {
71-
log.info("Creating language client");
72-
7371
this._serverPath = await bootstrap(this.extCtx, this.config, this.state).catch(
7472
(err) => {
7573
let message = "bootstrap error. ";

editors/code/src/main.ts

+7
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ async function initCommonContext(ctx: Ctx) {
126126
await ctx.activate();
127127
});
128128

129+
ctx.registerCommand("startServer", (_) => async () => {
130+
await ctx.activate();
131+
});
132+
ctx.registerCommand("stopServer", (_) => async () => {
133+
// FIXME: We should re-use the client, that is ctx.deactivate() if none of the configs have changed
134+
await ctx.disposeClient();
135+
});
129136
ctx.registerCommand("analyzerStatus", commands.analyzerStatus);
130137
ctx.registerCommand("memoryUsage", commands.memoryUsage);
131138
ctx.registerCommand("shuffleCrateGraph", commands.shuffleCrateGraph);

0 commit comments

Comments
 (0)