@@ -11,7 +11,34 @@ let ctx: Ctx | undefined;
1111export async function activate ( context : vscode . ExtensionContext ) {
1212 ctx = new Ctx ( context ) ;
1313
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+
1424 // 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+
1542 ctx . registerCommand ( 'analyzerStatus' , commands . analyzerStatus ) ;
1643 ctx . registerCommand ( 'collectGarbage' , commands . collectGarbage ) ;
1744 ctx . registerCommand ( 'matchingBrace' , commands . matchingBrace ) ;
@@ -20,7 +47,6 @@ export async function activate(context: vscode.ExtensionContext) {
2047 ctx . registerCommand ( 'syntaxTree' , commands . syntaxTree ) ;
2148 ctx . registerCommand ( 'expandMacro' , commands . expandMacro ) ;
2249 ctx . registerCommand ( 'run' , commands . run ) ;
23- ctx . registerCommand ( 'reload' , commands . reload ) ;
2450 ctx . registerCommand ( 'onEnter' , commands . onEnter ) ;
2551 ctx . registerCommand ( 'ssr' , commands . ssr )
2652
@@ -33,18 +59,10 @@ export async function activate(context: vscode.ExtensionContext) {
3359 activateStatusDisplay ( ctx ) ;
3460
3561 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- }
4562 activateInlayHints ( ctx ) ;
4663}
4764
4865export async function deactivate ( ) {
4966 await ctx ?. client ?. stop ( ) ;
67+ ctx = undefined ;
5068}
0 commit comments