@@ -66,10 +66,28 @@ export function activate(context: ExtensionContext) {
6666 const started = await startLanguageServer ( context , config ) ;
6767 languageServerIsRunning = started ;
6868 return languageServerIsRunning ? config . board . fqbn : undefined ;
69+ } catch ( e ) {
70+ console . log ( e ) ;
71+ languageServerIsRunning = false ;
72+ throw e ;
6973 } finally {
7074 unlock ( ) ;
7175 }
7276 } ) ,
77+ vscode . commands . registerCommand ( 'arduino.languageserver.stop' , async ( ) => {
78+ const unlock = await languageServerStartMutex . acquire ( ) ;
79+ try {
80+ await stopLanguageServer ( context ) ;
81+ languageServerIsRunning = false ;
82+ } finally {
83+ unlock ( ) ;
84+ }
85+ } ) ,
86+ vscode . commands . registerCommand ( 'arduino.languageserver.restart' , async ( ) => {
87+ if ( latestConfig ) {
88+ return vscode . commands . executeCommand ( 'arduino.languageserver.start' , latestConfig ) ;
89+ }
90+ } ) ,
7391 vscode . commands . registerCommand ( 'arduino.debug.start' , ( config : DebugConfig ) => startDebug ( context , config ) )
7492 ) ;
7593}
@@ -141,7 +159,7 @@ async function startDebug(_: ExtensionContext, config: DebugConfig): Promise<boo
141159 return vscode . debug . startDebugging ( undefined , mergedDebugConfig ) ;
142160}
143161
144- async function startLanguageServer ( context : ExtensionContext , config : LanguageServerConfig ) : Promise < boolean > {
162+ async function stopLanguageServer ( context : ExtensionContext ) : Promise < void > {
145163 if ( languageClient ) {
146164 if ( languageClient . diagnostics ) {
147165 languageClient . diagnostics . clear ( ) ;
@@ -151,6 +169,10 @@ async function startLanguageServer(context: ExtensionContext, config: LanguageSe
151169 languageServerDisposable . dispose ( ) ;
152170 }
153171 }
172+ }
173+
174+ async function startLanguageServer ( context : ExtensionContext , config : LanguageServerConfig ) : Promise < boolean > {
175+ await stopLanguageServer ( context ) ;
154176 if ( ! languageClient || ! deepEqual ( latestConfig , config ) ) {
155177 latestConfig = config ;
156178 languageClient = await buildLanguageClient ( config ) ;
0 commit comments