@@ -11,7 +11,34 @@ let ctx: Ctx | undefined;
11
11
export async function activate ( context : vscode . ExtensionContext ) {
12
12
ctx = new Ctx ( context ) ;
13
13
14
+ // Note: we try to start the server before we activate type hints so that it
15
+ // registers its `onDidChangeDocument` handler before us.
16
+ //
17
+ // This a horribly, horribly wrong way to deal with this problem.
18
+ try {
19
+ await ctx . startServer ( ) ;
20
+ } catch ( e ) {
21
+ vscode . window . showErrorMessage ( e . message ) ;
22
+ }
23
+
14
24
// Commands which invokes manually via command palette, shortcut, etc.
25
+ ctx . registerCommand ( 'reload' , ( ctx ) => {
26
+ return async ( ) => {
27
+ vscode . window . showInformationMessage ( 'Reloading rust-analyzer...' ) ;
28
+ // @DanTup maneuver
29
+ // https://github.com/microsoft/vscode/issues/45774#issuecomment-373423895
30
+ await deactivate ( )
31
+ for ( const sub of ctx . subscriptions ) {
32
+ try {
33
+ sub . dispose ( ) ;
34
+ } catch ( e ) {
35
+ console . error ( e ) ;
36
+ }
37
+ }
38
+ await activate ( context )
39
+ }
40
+ } )
41
+
15
42
ctx . registerCommand ( 'analyzerStatus' , commands . analyzerStatus ) ;
16
43
ctx . registerCommand ( 'collectGarbage' , commands . collectGarbage ) ;
17
44
ctx . registerCommand ( 'matchingBrace' , commands . matchingBrace ) ;
@@ -20,7 +47,6 @@ export async function activate(context: vscode.ExtensionContext) {
20
47
ctx . registerCommand ( 'syntaxTree' , commands . syntaxTree ) ;
21
48
ctx . registerCommand ( 'expandMacro' , commands . expandMacro ) ;
22
49
ctx . registerCommand ( 'run' , commands . run ) ;
23
- ctx . registerCommand ( 'reload' , commands . reload ) ;
24
50
ctx . registerCommand ( 'onEnter' , commands . onEnter ) ;
25
51
ctx . registerCommand ( 'ssr' , commands . ssr )
26
52
@@ -33,18 +59,10 @@ export async function activate(context: vscode.ExtensionContext) {
33
59
activateStatusDisplay ( ctx ) ;
34
60
35
61
activateHighlighting ( ctx ) ;
36
- // Note: we try to start the server before we activate type hints so that it
37
- // registers its `onDidChangeDocument` handler before us.
38
- //
39
- // This a horribly, horribly wrong way to deal with this problem.
40
- try {
41
- await ctx . restartServer ( ) ;
42
- } catch ( e ) {
43
- vscode . window . showErrorMessage ( e . message ) ;
44
- }
45
62
activateInlayHints ( ctx ) ;
46
63
}
47
64
48
65
export async function deactivate ( ) {
49
66
await ctx ?. client ?. stop ( ) ;
67
+ ctx = undefined ;
50
68
}
0 commit comments