aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim <[email protected]>2020-03-31 09:05:22 +0100
committerTim Hutt <[email protected]>2020-03-31 09:06:52 +0100
commita781a58fe2cefefbf9bf505247df78fd750a8f13 (patch)
treeb0a332117f094a98ca9818bb1da53df2a29f3262
parent6e535915bda524de34f011f75067132e88a3a3cc (diff)
Throw error if no folder is opened
-rw-r--r--editors/code/src/client.ts4
-rw-r--r--editors/code/src/ctx.ts2
-rw-r--r--editors/code/src/main.ts7
3 files changed, 9 insertions, 4 deletions
diff --git a/editors/code/src/client.ts b/editors/code/src/client.ts
index c9819e457..0de45bb30 100644
--- a/editors/code/src/client.ts
+++ b/editors/code/src/client.ts
@@ -30,14 +30,14 @@ export function configToServerOptions(config: Config) {
30 }; 30 };
31} 31}
32 32
33export async function createClient(config: Config, serverPath: string, workspaceFolder: vscode.WorkspaceFolder | null): Promise<lc.LanguageClient> { 33export async function createClient(config: Config, serverPath: string, workspaceFolder: vscode.WorkspaceFolder): Promise<lc.LanguageClient> {
34 // '.' Is the fallback if no folder is open 34 // '.' Is the fallback if no folder is open
35 // TODO?: Workspace folders support Uri's (eg: file://test.txt). 35 // TODO?: Workspace folders support Uri's (eg: file://test.txt).
36 // It might be a good idea to test if the uri points to a file. 36 // It might be a good idea to test if the uri points to a file.
37 37
38 const run: lc.Executable = { 38 const run: lc.Executable = {
39 command: serverPath, 39 command: serverPath,
40 options: { cwd: workspaceFolder?.uri.fsPath ?? '.' }, 40 options: { cwd: workspaceFolder.uri.fsPath },
41 }; 41 };
42 const serverOptions: lc.ServerOptions = { 42 const serverOptions: lc.ServerOptions = {
43 run, 43 run,
diff --git a/editors/code/src/ctx.ts b/editors/code/src/ctx.ts
index 0e705bc84..255d57f5e 100644
--- a/editors/code/src/ctx.ts
+++ b/editors/code/src/ctx.ts
@@ -19,7 +19,7 @@ export class Ctx {
19 config: Config, 19 config: Config,
20 extCtx: vscode.ExtensionContext, 20 extCtx: vscode.ExtensionContext,
21 serverPath: string, 21 serverPath: string,
22 workspaceFolder: vscode.WorkspaceFolder | null, 22 workspaceFolder: vscode.WorkspaceFolder,
23 ): Promise<Ctx> { 23 ): Promise<Ctx> {
24 const client = await createClient(config, serverPath, workspaceFolder); 24 const client = await createClient(config, serverPath, workspaceFolder);
25 const res = new Ctx(config, extCtx, client, serverPath); 25 const res = new Ctx(config, extCtx, client, serverPath);
diff --git a/editors/code/src/main.ts b/editors/code/src/main.ts
index 40701e4f5..ee6e712a4 100644
--- a/editors/code/src/main.ts
+++ b/editors/code/src/main.ts
@@ -42,7 +42,12 @@ export async function activate(context: vscode.ExtensionContext) {
42 const state = new PersistentState(context.globalState); 42 const state = new PersistentState(context.globalState);
43 const serverPath = await bootstrap(config, state); 43 const serverPath = await bootstrap(config, state);
44 44
45 const workspaceFolder = vscode.workspace.workspaceFolders?.[0] ?? null; 45 const workspaceFolder = vscode.workspace.workspaceFolders?.[0];
46 if (workspaceFolder === undefined) {
47 const err = "Cannot activate rust-analyzer when no folder is opened";
48 void vscode.window.showErrorMessage(err);
49 throw new Error(err);
50 }
46 51
47 // Note: we try to start the server before we activate type hints so that it 52 // Note: we try to start the server before we activate type hints so that it
48 // registers its `onDidChangeDocument` handler before us. 53 // registers its `onDidChangeDocument` handler before us.