From 16a0eb1829b569e2d1e1046a60fd7e25aa35bfcf Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 23 Aug 2022 15:45:02 +0200 Subject: [PATCH 1/2] Avoid error popup when using in Live Share --- editors/code/src/main.ts | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index a9847dd2a652..ae145234792c 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 { + // 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 - 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. From dcbbb7f211771fc08281312310067469e58efa0b Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 23 Aug 2022 15:56:02 +0200 Subject: [PATCH 2/2] =?UTF-8?q?ForGoT=20tO=20RuN=20prEttIeR=C2=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- editors/code/src/main.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index ae145234792c..e9b62e0cc257 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -51,14 +51,14 @@ async function tryActivate(context: vscode.ExtensionContext): Promise - folder.uri.scheme == "file" + 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) { + 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