Skip to content

Commit 16a0eb1

Browse files
author
Jonas Schievink
committed
Avoid error popup when using in Live Share
1 parent f045f14 commit 16a0eb1

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

editors/code/src/main.ts

+23-13
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function outputChannel() {
3333
}
3434

3535
export interface RustAnalyzerExtensionApi {
36-
client: lc.LanguageClient;
36+
client?: lc.LanguageClient;
3737
}
3838

3939
export async function activate(
@@ -48,6 +48,23 @@ export async function activate(
4848
}
4949

5050
async function tryActivate(context: vscode.ExtensionContext): Promise<RustAnalyzerExtensionApi> {
51+
// We only support local folders, not eg. Live Share (`vlsl:` scheme), so don't activate if
52+
// only those are in use.
53+
// (r-a still somewhat works with Live Share, because commands are tunneled to the host)
54+
const folders = (vscode.workspace.workspaceFolders || []).filter((folder) =>
55+
folder.uri.scheme == "file"
56+
);
57+
const rustDocuments = vscode.workspace.textDocuments.filter((document) =>
58+
isRustDocument(document)
59+
);
60+
61+
if (folders.length == 0 && rustDocuments.length == 0) {
62+
// FIXME: Ideally we would choose not to activate at all (and avoid registering
63+
// non-functional editor commands), but VS Code doesn't seem to have a good way of doing
64+
// that
65+
return {};
66+
}
67+
5168
const config = new Config(context);
5269
const state = new PersistentState(context.globalState);
5370
const serverPath = await bootstrap(context, config, state).catch((err) => {
@@ -60,18 +77,11 @@ async function tryActivate(context: vscode.ExtensionContext): Promise<RustAnalyz
6077
throw new Error(message);
6178
});
6279

63-
if ((vscode.workspace.workspaceFolders || []).length === 0) {
64-
const rustDocuments = vscode.workspace.textDocuments.filter((document) =>
65-
isRustDocument(document)
66-
);
67-
if (rustDocuments.length > 0) {
68-
ctx = await Ctx.create(config, context, serverPath, {
69-
kind: "Detached Files",
70-
files: rustDocuments,
71-
});
72-
} else {
73-
throw new Error("no rust files are opened");
74-
}
80+
if (folders.length === 0) {
81+
ctx = await Ctx.create(config, context, serverPath, {
82+
kind: "Detached Files",
83+
files: rustDocuments,
84+
});
7585
} else {
7686
// Note: we try to start the server before we activate type hints so that it
7787
// registers its `onDidChangeDocument` handler before us.

0 commit comments

Comments
 (0)