about summary refs log tree commit diff
path: root/editors/code
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2022-10-17 15:43:15 +0200
committerLukas Wirth <lukastw97@gmail.com>2022-10-17 15:45:57 +0200
commit0421756b4256b8edf739b5889e754d7bc733ed38 (patch)
tree829aef24fb671930e5e6f49acc149e36e68c3181 /editors/code
parentd68616a140b35dd9bc4e2982e0993257ab0942e0 (diff)
downloadrust-0421756b4256b8edf739b5889e754d7bc733ed38.tar.gz
rust-0421756b4256b8edf739b5889e754d7bc733ed38.zip
Implement stop and start server commands
Diffstat (limited to 'editors/code')
-rw-r--r--editors/code/package.json11
-rw-r--r--editors/code/src/client.ts8
-rw-r--r--editors/code/src/ctx.ts2
-rw-r--r--editors/code/src/main.ts7
4 files changed, 26 insertions, 2 deletions
diff --git a/editors/code/package.json b/editors/code/package.json
index da4bac5ad84..10558e8c018 100644
--- a/editors/code/package.json
+++ b/editors/code/package.json
@@ -60,6 +60,7 @@
         "onCommand:rust-analyzer.analyzerStatus",
         "onCommand:rust-analyzer.memoryUsage",
         "onCommand:rust-analyzer.reloadWorkspace",
+        "onCommand:rust-analyzer.startServer",
         "workspaceContains:*/Cargo.toml",
         "workspaceContains:*/rust-project.json"
     ],
@@ -192,6 +193,16 @@
                 "category": "rust-analyzer"
             },
             {
+                "command": "rust-analyzer.startServer",
+                "title": "Start server",
+                "category": "rust-analyzer"
+            },
+            {
+                "command": "rust-analyzer.stopServer",
+                "title": "Stop server",
+                "category": "rust-analyzer"
+            },
+            {
                 "command": "rust-analyzer.onEnter",
                 "title": "Enhanced enter key",
                 "category": "rust-analyzer"
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts
index 3408a2ee84e..fb667619c86 100644
--- a/editors/code/src/client.ts
+++ b/editors/code/src/client.ts
@@ -76,6 +76,14 @@ export async function createClient(
         outputChannel,
         middleware: {
             workspace: {
+                // HACK: This is a workaround, when the client has been disposed, VSCode
+                // continues to emit events to the client and the default one for this event
+                // attempt to restart the client for no reason
+                async didChangeWatchedFile(event, next) {
+                    if (client.isRunning()) {
+                        await next(event);
+                    }
+                },
                 async configuration(
                     params: lc.ConfigurationParams,
                     token: vscode.CancellationToken,
diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts
index 6b12d9ca1ec..2080db7a2c1 100644
--- a/editors/code/src/ctx.ts
+++ b/editors/code/src/ctx.ts
@@ -68,8 +68,6 @@ export class Ctx {
         }
 
         if (!this.client) {
-            log.info("Creating language client");
-
             this._serverPath = await bootstrap(this.extCtx, this.config, this.state).catch(
                 (err) => {
                     let message = "bootstrap error. ";
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index 97ec41dce3a..f65620aebc6 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -126,6 +126,13 @@ async function initCommonContext(ctx: Ctx) {
         await ctx.activate();
     });
 
+    ctx.registerCommand("startServer", (_) => async () => {
+        await ctx.activate();
+    });
+    ctx.registerCommand("stopServer", (_) => async () => {
+        // FIXME: We should re-use the client, that is ctx.deactivate() if none of the configs have changed
+        await ctx.disposeClient();
+    });
     ctx.registerCommand("analyzerStatus", commands.analyzerStatus);
     ctx.registerCommand("memoryUsage", commands.memoryUsage);
     ctx.registerCommand("shuffleCrateGraph", commands.shuffleCrateGraph);