File tree Expand file tree Collapse file tree 3 files changed +9
-4
lines changed Expand file tree Collapse file tree 3 files changed +9
-4
lines changed Original file line number Diff line number Diff 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,
Original file line number Diff line number Diff 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 ) ;
Original file line number Diff line number Diff 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.
You can’t perform that action at this time.
0 commit comments