diff options
| author | Tim <tdhutt@gmail.com> | 2020-03-31 09:05:22 +0100 |
|---|---|---|
| committer | Tim Hutt <timh@graphcore.ai> | 2020-03-31 09:06:52 +0100 |
| commit | a781a58fe2cefefbf9bf505247df78fd750a8f13 (patch) | |
| tree | b0a332117f094a98ca9818bb1da53df2a29f3262 /editors/code/src | |
| parent | 6e535915bda524de34f011f75067132e88a3a3cc (diff) | |
| download | rust-a781a58fe2cefefbf9bf505247df78fd750a8f13.tar.gz rust-a781a58fe2cefefbf9bf505247df78fd750a8f13.zip | |
Throw error if no folder is opened
Diffstat (limited to 'editors/code/src')
| -rw-r--r-- | editors/code/src/client.ts | 4 | ||||
| -rw-r--r-- | editors/code/src/ctx.ts | 2 | ||||
| -rw-r--r-- | editors/code/src/main.ts | 7 |
3 files changed, 9 insertions, 4 deletions
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts index c9819e4573f..0de45bb3040 100644 --- a/editors/code/src/client.ts +++ b/editors/code/src/client.ts @@ -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 // 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. const run: lc.Executable = { command: serverPath, - options: { cwd: workspaceFolder?.uri.fsPath ?? '.' }, + options: { cwd: workspaceFolder.uri.fsPath }, }; const serverOptions: lc.ServerOptions = { run, diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts index 0e705bc8460..255d57f5e7e 100644 --- a/editors/code/src/ctx.ts +++ b/editors/code/src/ctx.ts @@ -19,7 +19,7 @@ export class Ctx { config: Config, extCtx: vscode.ExtensionContext, serverPath: string, - workspaceFolder: vscode.WorkspaceFolder | null, + workspaceFolder: vscode.WorkspaceFolder, ): Promise<Ctx> { const client = await createClient(config, serverPath, workspaceFolder); const res = new Ctx(config, extCtx, client, serverPath); diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts index 40701e4f54e..ee6e712a42d 100644 --- a/editors/code/src/main.ts +++ b/editors/code/src/main.ts @@ -42,7 +42,12 @@ export async function activate(context: vscode.ExtensionContext) { const state = new PersistentState(context.globalState); 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 // registers its `onDidChangeDocument` handler before us. |
