File tree Expand file tree Collapse file tree 4 files changed +26
-2
lines changed Expand file tree Collapse file tree 4 files changed +26
-2
lines changed Original file line number Diff line number Diff line change 6060 " onCommand:rust-analyzer.analyzerStatus" ,
6161 " onCommand:rust-analyzer.memoryUsage" ,
6262 " onCommand:rust-analyzer.reloadWorkspace" ,
63+ " onCommand:rust-analyzer.startServer" ,
6364 " workspaceContains:*/Cargo.toml" ,
6465 " workspaceContains:*/rust-project.json"
6566 ],
191192 "title" : " Restart server" ,
192193 "category" : " rust-analyzer"
193194 },
195+ {
196+ "command" : " rust-analyzer.startServer" ,
197+ "title" : " Start server" ,
198+ "category" : " rust-analyzer"
199+ },
200+ {
201+ "command" : " rust-analyzer.stopServer" ,
202+ "title" : " Stop server" ,
203+ "category" : " rust-analyzer"
204+ },
194205 {
195206 "command" : " rust-analyzer.onEnter" ,
196207 "title" : " Enhanced enter key" ,
Original file line number Diff line number Diff line change @@ -76,6 +76,14 @@ export async function createClient(
7676 outputChannel,
7777 middleware : {
7878 workspace : {
79+ // HACK: This is a workaround, when the client has been disposed, VSCode
80+ // continues to emit events to the client and the default one for this event
81+ // attempt to restart the client for no reason
82+ async didChangeWatchedFile ( event , next ) {
83+ if ( client . isRunning ( ) ) {
84+ await next ( event ) ;
85+ }
86+ } ,
7987 async configuration (
8088 params : lc . ConfigurationParams ,
8189 token : vscode . CancellationToken ,
Original file line number Diff line number Diff line change @@ -68,8 +68,6 @@ export class Ctx {
6868 }
6969
7070 if ( ! this . client ) {
71- log . info ( "Creating language client" ) ;
72-
7371 this . _serverPath = await bootstrap ( this . extCtx , this . config , this . state ) . catch (
7472 ( err ) => {
7573 let message = "bootstrap error. " ;
Original file line number Diff line number Diff line change @@ -126,6 +126,13 @@ async function initCommonContext(ctx: Ctx) {
126126 await ctx . activate ( ) ;
127127 } ) ;
128128
129+ ctx . registerCommand ( "startServer" , ( _ ) => async ( ) => {
130+ await ctx . activate ( ) ;
131+ } ) ;
132+ ctx . registerCommand ( "stopServer" , ( _ ) => async ( ) => {
133+ // FIXME: We should re-use the client, that is ctx.deactivate() if none of the configs have changed
134+ await ctx . disposeClient ( ) ;
135+ } ) ;
129136 ctx . registerCommand ( "analyzerStatus" , commands . analyzerStatus ) ;
130137 ctx . registerCommand ( "memoryUsage" , commands . memoryUsage ) ;
131138 ctx . registerCommand ( "shuffleCrateGraph" , commands . shuffleCrateGraph ) ;
You can’t perform that action at this time.
0 commit comments