File tree Expand file tree Collapse file tree 4 files changed +29
-3
lines changed Expand file tree Collapse file tree 4 files changed +29
-3
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 @@ -61,13 +61,14 @@ function renderHoverActions(actions: ra.CommandLinkGroup[]): vscode.MarkdownStri
6161 result . isTrusted = true ;
6262 return result ;
6363}
64-
64+ let x = 0 ;
6565export async function createClient (
6666 traceOutputChannel : vscode . OutputChannel ,
6767 outputChannel : vscode . OutputChannel ,
6868 initializationOptions : vscode . WorkspaceConfiguration ,
6969 serverOptions : lc . ServerOptions
7070) : Promise < lc . LanguageClient > {
71+ const X = x ++ ;
7172 const clientOptions : lc . LanguageClientOptions = {
7273 documentSelector : [ { scheme : "file" , language : "rust" } ] ,
7374 initializationOptions,
@@ -76,6 +77,15 @@ export async function createClient(
7677 outputChannel,
7778 middleware : {
7879 workspace : {
80+ async didChangeWatchedFile ( event , next ) {
81+ console . log ( X ) ;
82+ console . log ( client ) ;
83+ if ( client . isRunning ( ) ) {
84+ // HACK: This is a workaround, when the client has been disposed, VSCode
85+ // continues to emit this event to the client...
86+ await next ( event ) ;
87+ }
88+ } ,
7989 async configuration (
8090 params : lc . ConfigurationParams ,
8191 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