1
1
import * as vscode from 'vscode' ;
2
2
import * as lc from 'vscode-languageclient' ;
3
- import { strict as assert } from "assert" ;
4
3
5
4
import { Config } from './config' ;
6
5
import { createClient } from './client' ;
@@ -15,23 +14,21 @@ export class Ctx {
15
14
// FIXME: this actually needs syncronization of some kind (check how
16
15
// vscode deals with `deactivate()` call when extension has some work scheduled
17
16
// on the event loop to get a better picture of what we can do here)
18
- client : lc . LanguageClient | null = null ;
17
+ client : lc . LanguageClient ;
19
18
private extCtx : vscode . ExtensionContext ;
20
19
21
- constructor ( extCtx : vscode . ExtensionContext ) {
22
- this . config = new Config ( extCtx ) ;
23
- this . extCtx = extCtx ;
24
- }
25
-
26
- async startServer ( serverPath : string ) {
27
- assert ( this . client == null ) ;
28
-
29
- const client = await createClient ( this . config , serverPath ) ;
30
-
31
- this . pushCleanup ( client . start ( ) ) ;
20
+ static async create ( config : Config , extCtx : vscode . ExtensionContext , serverPath : string ) : Promise < Ctx > {
21
+ const client = await createClient ( config , serverPath ) ;
22
+ const res = new Ctx ( config , extCtx , client ) ;
23
+ res . pushCleanup ( client . start ( ) ) ;
32
24
await client . onReady ( ) ;
25
+ return res ;
26
+ }
33
27
34
- this . client = client ;
28
+ private constructor ( config : Config , extCtx : vscode . ExtensionContext , client : lc . LanguageClient ) {
29
+ this . config = config ;
30
+ this . extCtx = extCtx ;
31
+ this . client = client
35
32
}
36
33
37
34
get activeRustEditor ( ) : vscode . TextEditor | undefined {
0 commit comments