@@ -66,10 +66,28 @@ export function activate(context: ExtensionContext) {
66
66
const started = await startLanguageServer ( context , config ) ;
67
67
languageServerIsRunning = started ;
68
68
return languageServerIsRunning ? config . board . fqbn : undefined ;
69
+ } catch ( e ) {
70
+ console . log ( e ) ;
71
+ languageServerIsRunning = false ;
72
+ throw e ;
69
73
} finally {
70
74
unlock ( ) ;
71
75
}
72
76
} ) ,
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
+ } ) ,
73
91
vscode . commands . registerCommand ( 'arduino.debug.start' , ( config : DebugConfig ) => startDebug ( context , config ) )
74
92
) ;
75
93
}
@@ -141,7 +159,7 @@ async function startDebug(_: ExtensionContext, config: DebugConfig): Promise<boo
141
159
return vscode . debug . startDebugging ( undefined , mergedDebugConfig ) ;
142
160
}
143
161
144
- async function startLanguageServer ( context : ExtensionContext , config : LanguageServerConfig ) : Promise < boolean > {
162
+ async function stopLanguageServer ( context : ExtensionContext ) : Promise < void > {
145
163
if ( languageClient ) {
146
164
if ( languageClient . diagnostics ) {
147
165
languageClient . diagnostics . clear ( ) ;
@@ -151,6 +169,10 @@ async function startLanguageServer(context: ExtensionContext, config: LanguageSe
151
169
languageServerDisposable . dispose ( ) ;
152
170
}
153
171
}
172
+ }
173
+
174
+ async function startLanguageServer ( context : ExtensionContext , config : LanguageServerConfig ) : Promise < boolean > {
175
+ await stopLanguageServer ( context ) ;
154
176
if ( ! languageClient || ! deepEqual ( latestConfig , config ) ) {
155
177
latestConfig = config ;
156
178
languageClient = await buildLanguageClient ( config ) ;
0 commit comments