Skip to content

Commit

Permalink
Auto merge of #13095 - jonas-schievink:avoid-liveshare-error, r=jonas…
Browse files Browse the repository at this point in the history
…-schievink

fix: Avoid error popup when using in Live Share

cc #8844

Not sure if there's a better way to do this, feedback appreciated!
  • Loading branch information
bors committed Aug 26, 2022
2 parents ca4e10b + dcbbb7f commit 6bea872
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions editors/code/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export function outputChannel() {
}

export interface RustAnalyzerExtensionApi {
client: lc.LanguageClient;
client?: lc.LanguageClient;
}

export async function activate(
Expand All @@ -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) => {
Expand All @@ -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.
Expand Down

0 comments on commit 6bea872

Please sign in to comment.