Skip to content

Commit a781a58

Browse files
TimmmmTim Hutt
authored andcommitted
Throw error if no folder is opened
1 parent 6e53591 commit a781a58

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

editors/code/src/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ export function configToServerOptions(config: Config) {
3030
};
3131
}
3232

33-
export async function createClient(config: Config, serverPath: string, workspaceFolder: vscode.WorkspaceFolder | null): Promise<lc.LanguageClient> {
33+
export async function createClient(config: Config, serverPath: string, workspaceFolder: vscode.WorkspaceFolder): Promise<lc.LanguageClient> {
3434
// '.' Is the fallback if no folder is open
3535
// TODO?: Workspace folders support Uri's (eg: file://test.txt).
3636
// It might be a good idea to test if the uri points to a file.
3737

3838
const run: lc.Executable = {
3939
command: serverPath,
40-
options: { cwd: workspaceFolder?.uri.fsPath ?? '.' },
40+
options: { cwd: workspaceFolder.uri.fsPath },
4141
};
4242
const serverOptions: lc.ServerOptions = {
4343
run,

editors/code/src/ctx.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export class Ctx {
1919
config: Config,
2020
extCtx: vscode.ExtensionContext,
2121
serverPath: string,
22-
workspaceFolder: vscode.WorkspaceFolder | null,
22+
workspaceFolder: vscode.WorkspaceFolder,
2323
): Promise<Ctx> {
2424
const client = await createClient(config, serverPath, workspaceFolder);
2525
const res = new Ctx(config, extCtx, client, serverPath);

editors/code/src/main.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ export async function activate(context: vscode.ExtensionContext) {
4242
const state = new PersistentState(context.globalState);
4343
const serverPath = await bootstrap(config, state);
4444

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+
}
4651

4752
// Note: we try to start the server before we activate type hints so that it
4853
// registers its `onDidChangeDocument` handler before us.

0 commit comments

Comments
 (0)