File tree Expand file tree Collapse file tree 3 files changed +13
-14
lines changed Expand file tree Collapse file tree 3 files changed +13
-14
lines changed Original file line number Diff line number Diff line change @@ -2,18 +2,14 @@ import * as lc from 'vscode-languageclient';
2
2
import * as vscode from 'vscode' ;
3
3
4
4
import { Config } from './config' ;
5
- import { ensureServerBinary } from './installation/server' ;
6
5
import { CallHierarchyFeature } from 'vscode-languageclient/lib/callHierarchy.proposed' ;
7
6
8
- export async function createClient ( config : Config ) : Promise < null | lc . LanguageClient > {
7
+ export async function createClient ( config : Config , serverPath : string ) : Promise < lc . LanguageClient > {
9
8
// '.' Is the fallback if no folder is open
10
9
// TODO?: Workspace folders support Uri's (eg: file://test.txt).
11
10
// It might be a good idea to test if the uri points to a file.
12
11
const workspaceFolderPath = vscode . workspace . workspaceFolders ?. [ 0 ] ?. uri . fsPath ?? '.' ;
13
12
14
- const serverPath = await ensureServerBinary ( config . serverSource ) ;
15
- if ( ! serverPath ) return null ;
16
-
17
13
const run : lc . Executable = {
18
14
command : serverPath ,
19
15
options : { cwd : workspaceFolderPath } ,
Original file line number Diff line number Diff line change @@ -23,16 +23,10 @@ export class Ctx {
23
23
this . extCtx = extCtx ;
24
24
}
25
25
26
- async startServer ( ) {
26
+ async startServer ( serverPath : string ) {
27
27
assert ( this . client == null ) ;
28
28
29
- const client = await createClient ( this . config ) ;
30
- if ( ! client ) {
31
- throw new Error (
32
- "Rust Analyzer Language Server is not available. " +
33
- "Please, ensure its [proper installation](https://github.com/rust-analyzer/rust-analyzer/tree/master/docs/user#vs-code)."
34
- ) ;
35
- }
29
+ const client = await createClient ( this . config , serverPath ) ;
36
30
37
31
this . pushCleanup ( client . start ( ) ) ;
38
32
await client . onReady ( ) ;
Original file line number Diff line number Diff line change @@ -5,18 +5,27 @@ import { activateInlayHints } from './inlay_hints';
5
5
import { activateStatusDisplay } from './status_display' ;
6
6
import { Ctx } from './ctx' ;
7
7
import { activateHighlighting } from './highlighting' ;
8
+ import { ensureServerBinary } from './installation/server' ;
8
9
9
10
let ctx : Ctx | undefined ;
10
11
11
12
export async function activate ( context : vscode . ExtensionContext ) {
12
13
ctx = new Ctx ( context ) ;
13
14
15
+ const serverPath = await ensureServerBinary ( ctx . config . serverSource ) ;
16
+ if ( serverPath == null ) {
17
+ throw new Error (
18
+ "Rust Analyzer Language Server is not available. " +
19
+ "Please, ensure its [proper installation](https://github.com/rust-analyzer/rust-analyzer/tree/master/docs/user#vs-code)."
20
+ ) ;
21
+ }
22
+
14
23
// Note: we try to start the server before we activate type hints so that it
15
24
// registers its `onDidChangeDocument` handler before us.
16
25
//
17
26
// This a horribly, horribly wrong way to deal with this problem.
18
27
try {
19
- await ctx . startServer ( ) ;
28
+ await ctx . startServer ( serverPath ) ;
20
29
} catch ( e ) {
21
30
vscode . window . showErrorMessage ( e . message ) ;
22
31
}
You can’t perform that action at this time.
0 commit comments