about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-08-26 18:39:53 +0000
committerbors <bors@rust-lang.org>2022-08-26 18:39:53 +0000
commit6bea872edd9523a06213270f68725c9fe33f3919 (patch)
tree77d2baf9349d6aae1166e8cc22a89e6af36bf65a
parentca4e10b7fc868830233c67bc8fcd26d889549bfd (diff)
parentdcbbb7f211771fc08281312310067469e58efa0b (diff)
downloadrust-6bea872edd9523a06213270f68725c9fe33f3919.tar.gz
rust-6bea872edd9523a06213270f68725c9fe33f3919.zip
Auto merge of #13095 - jonas-schievink:avoid-liveshare-error, r=jonas-schievink
fix: Avoid error popup when using in Live Share

cc https://github.com/rust-lang/rust-analyzer/issues/8844

Not sure if there's a better way to do this, feedback appreciated!
-rw-r--r--editors/code/src/main.ts36
1 files changed, 23 insertions, 13 deletions
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index a9847dd2a65..e9b62e0cc25 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -33,7 +33,7 @@ export function outputChannel() {
 }
 
 export interface RustAnalyzerExtensionApi {
-    client: lc.LanguageClient;
+    client?: lc.LanguageClient;
 }
 
 export async function activate(
@@ -48,6 +48,23 @@ export async function activate(
 }
 
 async function tryActivate(context: vscode.ExtensionContext): Promise<RustAnalyzerExtensionApi> {
+    // We only support local folders, not eg. Live Share (`vlsl:` scheme), so don't activate if
+    // only those are in use.
+    // (r-a still somewhat works with Live Share, because commands are tunneled to the host)
+    const folders = (vscode.workspace.workspaceFolders || []).filter(
+        (folder) => folder.uri.scheme === "file"
+    );
+    const rustDocuments = vscode.workspace.textDocuments.filter((document) =>
+        isRustDocument(document)
+    );
+
+    if (folders.length === 0 && rustDocuments.length === 0) {
+        // FIXME: Ideally we would choose not to activate at all (and avoid registering
+        // non-functional editor commands), but VS Code doesn't seem to have a good way of doing
+        // that
+        return {};
+    }
+
     const config = new Config(context);
     const state = new PersistentState(context.globalState);
     const serverPath = await bootstrap(context, config, state).catch((err) => {
@@ -60,18 +77,11 @@ async function tryActivate(context: vscode.ExtensionContext): Promise<RustAnalyz
         throw new Error(message);
     });
 
-    if ((vscode.workspace.workspaceFolders || []).length === 0) {
-        const rustDocuments = vscode.workspace.textDocuments.filter((document) =>
-            isRustDocument(document)
-        );
-        if (rustDocuments.length > 0) {
-            ctx = await Ctx.create(config, context, serverPath, {
-                kind: "Detached Files",
-                files: rustDocuments,
-            });
-        } else {
-            throw new Error("no rust files are opened");
-        }
+    if (folders.length === 0) {
+        ctx = await Ctx.create(config, context, serverPath, {
+            kind: "Detached Files",
+            files: rustDocuments,
+        });
     } else {
         // Note: we try to start the server before we activate type hints so that it
         // registers its `onDidChangeDocument` handler before us.