mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 13:48:50 +00:00
Throw error if no folder is opened
This commit is contained in:
parent
6e535915bd
commit
a781a58fe2
3 changed files with 9 additions and 4 deletions
|
@ -30,14 +30,14 @@ export function configToServerOptions(config: Config) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createClient(config: Config, serverPath: string, workspaceFolder: vscode.WorkspaceFolder | null): Promise<lc.LanguageClient> {
|
export async function createClient(config: Config, serverPath: string, workspaceFolder: vscode.WorkspaceFolder): Promise<lc.LanguageClient> {
|
||||||
// '.' Is the fallback if no folder is open
|
// '.' Is the fallback if no folder is open
|
||||||
// TODO?: Workspace folders support Uri's (eg: file://test.txt).
|
// TODO?: Workspace folders support Uri's (eg: file://test.txt).
|
||||||
// It might be a good idea to test if the uri points to a file.
|
// It might be a good idea to test if the uri points to a file.
|
||||||
|
|
||||||
const run: lc.Executable = {
|
const run: lc.Executable = {
|
||||||
command: serverPath,
|
command: serverPath,
|
||||||
options: { cwd: workspaceFolder?.uri.fsPath ?? '.' },
|
options: { cwd: workspaceFolder.uri.fsPath },
|
||||||
};
|
};
|
||||||
const serverOptions: lc.ServerOptions = {
|
const serverOptions: lc.ServerOptions = {
|
||||||
run,
|
run,
|
||||||
|
|
|
@ -19,7 +19,7 @@ export class Ctx {
|
||||||
config: Config,
|
config: Config,
|
||||||
extCtx: vscode.ExtensionContext,
|
extCtx: vscode.ExtensionContext,
|
||||||
serverPath: string,
|
serverPath: string,
|
||||||
workspaceFolder: vscode.WorkspaceFolder | null,
|
workspaceFolder: vscode.WorkspaceFolder,
|
||||||
): Promise<Ctx> {
|
): Promise<Ctx> {
|
||||||
const client = await createClient(config, serverPath, workspaceFolder);
|
const client = await createClient(config, serverPath, workspaceFolder);
|
||||||
const res = new Ctx(config, extCtx, client, serverPath);
|
const res = new Ctx(config, extCtx, client, serverPath);
|
||||||
|
|
|
@ -42,7 +42,12 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||||
const state = new PersistentState(context.globalState);
|
const state = new PersistentState(context.globalState);
|
||||||
const serverPath = await bootstrap(config, state);
|
const serverPath = await bootstrap(config, state);
|
||||||
|
|
||||||
const workspaceFolder = vscode.workspace.workspaceFolders?.[0] ?? null;
|
const workspaceFolder = vscode.workspace.workspaceFolders?.[0];
|
||||||
|
if (workspaceFolder === undefined) {
|
||||||
|
const err = "Cannot activate rust-analyzer when no folder is opened";
|
||||||
|
void vscode.window.showErrorMessage(err);
|
||||||
|
throw new Error(err);
|
||||||
|
}
|
||||||
|
|
||||||
// Note: we try to start the server before we activate type hints so that it
|
// Note: we try to start the server before we activate type hints so that it
|
||||||
// registers its `onDidChangeDocument` handler before us.
|
// registers its `onDidChangeDocument` handler before us.
|
||||||
|
|
Loading…
Reference in a new issue