File tree Expand file tree Collapse file tree 4 files changed +26
-3
lines changed Expand file tree Collapse file tree 4 files changed +26
-3
lines changed Original file line number Diff line number Diff line change 234234 "category" : " clangd" ,
235235 "title" : " Restart language server"
236236 },
237+ {
238+ "command" : " clangd.shutdown" ,
239+ "category" : " clangd" ,
240+ "title" : " Shutdown language server"
241+ },
237242 {
238243 "command" : " clangd.typeHierarchy" ,
239244 "category" : " clangd" ,
Original file line number Diff line number Diff line change @@ -242,6 +242,10 @@ export class ClangdContext implements vscode.Disposable {
242242 return this . client && this . client . state == vscodelc . State . Starting ;
243243 }
244244
245+ clientIsRunning ( ) {
246+ return this . client && this . client . state == vscodelc . State . Running ;
247+ }
248+
245249 dispose ( ) {
246250 this . subscriptions . forEach ( ( d ) => { d . dispose ( ) ; } ) ;
247251 if ( this . client )
Original file line number Diff line number Diff line change @@ -19,10 +19,14 @@ export async function activate(context: vscode.ExtensionContext):
1919
2020 let clangdContext : ClangdContext | null = null ;
2121
22- // An empty place holder for the activate command, otherwise we'll get an
23- // "command is not registered" error.
2422 context . subscriptions . push (
25- vscode . commands . registerCommand ( 'clangd.activate' , async ( ) => { } ) ) ;
23+ vscode . commands . registerCommand ( 'clangd.activate' , async ( ) => {
24+ if ( clangdContext && ( clangdContext . clientIsStarting ( ) ||
25+ clangdContext . clientIsRunning ( ) ) ) {
26+ return ;
27+ }
28+ vscode . commands . executeCommand ( 'clangd.restart' ) ;
29+ } ) ) ;
2630 context . subscriptions . push (
2731 vscode . commands . registerCommand ( 'clangd.restart' , async ( ) => {
2832 if ( ! get < boolean > ( 'enable' ) ) {
@@ -58,6 +62,14 @@ export async function activate(context: vscode.ExtensionContext):
5862 apiInstance . client = clangdContext ?. client ;
5963 }
6064 } ) ) ;
65+ context . subscriptions . push (
66+ vscode . commands . registerCommand ( 'clangd.shutdown' , async ( ) => {
67+ if ( clangdContext && clangdContext . clientIsStarting ( ) ) {
68+ return ;
69+ }
70+ if ( clangdContext )
71+ clangdContext . dispose ( ) ;
72+ } ) ) ;
6173
6274 let shouldCheck = false ;
6375
Original file line number Diff line number Diff line change @@ -20,6 +20,8 @@ class MockClangdContext implements ClangdContext {
2020
2121 clientIsStarting ( ) { return false ; }
2222
23+ clientIsRunning ( ) { return true ; }
24+
2325 dispose ( ) { throw new Error ( 'Method not implemented.' ) ; }
2426}
2527
You can’t perform that action at this time.
0 commit comments