@@ -7,6 +7,7 @@ import deepmerge from 'deepmerge';
7
7
import { Mutex } from 'async-mutex' ;
8
8
import vscode , { ExtensionContext } from 'vscode' ;
9
9
import { LanguageClient , CloseAction , ErrorAction , InitializeError , Message , RevealOutputChannelOn } from 'vscode-languageclient' ;
10
+ import { DidCompleteBuildNotification , DidCompleteBuildParams } from './protocol' ;
10
11
11
12
interface LanguageServerConfig {
12
13
readonly lsPath : string ;
@@ -72,10 +73,10 @@ export function activate(context: ExtensionContext) {
72
73
const started = await startLanguageServer ( context , config ) ;
73
74
languageServerIsRunning = started ;
74
75
return languageServerIsRunning ? config . board . fqbn : undefined ;
75
- } catch ( e ) {
76
- console . log ( e ) ;
76
+ } catch ( err ) {
77
+ console . error ( 'Failed to start the language server.' , err ) ;
77
78
languageServerIsRunning = false ;
78
- throw e ;
79
+ throw err ;
79
80
} finally {
80
81
unlock ( ) ;
81
82
}
@@ -94,7 +95,14 @@ export function activate(context: ExtensionContext) {
94
95
return vscode . commands . executeCommand ( 'arduino.languageserver.start' , latestConfig ) ;
95
96
}
96
97
} ) ,
97
- vscode . commands . registerCommand ( 'arduino.debug.start' , ( config : DebugConfig ) => startDebug ( context , config ) )
98
+ vscode . commands . registerCommand ( 'arduino.debug.start' , ( config : DebugConfig ) => startDebug ( context , config ) ) ,
99
+ vscode . commands . registerCommand ( 'arduino.languageserver.notifyBuildDidComplete' , ( params : DidCompleteBuildParams ) => {
100
+ if ( languageClient ) {
101
+ languageClient . sendNotification ( DidCompleteBuildNotification . TYPE , params ) ;
102
+ } else {
103
+ vscode . window . showWarningMessage ( 'Language server is not running.' ) ;
104
+ }
105
+ } )
98
106
) ;
99
107
}
100
108
@@ -108,8 +116,7 @@ async function startDebug(_: ExtensionContext, config: DebugConfig): Promise<boo
108
116
rawStdout = stdout . trim ( ) ;
109
117
rawStdErr = stderr . trim ( ) ;
110
118
} catch ( err ) {
111
- const message = err instanceof Error ? err . stack || err . message : 'Unknown error' ;
112
- vscode . window . showErrorMessage ( message ) ;
119
+ showError ( err ) ;
113
120
return false ;
114
121
}
115
122
if ( ! rawStdout ) {
@@ -125,7 +132,8 @@ async function startDebug(_: ExtensionContext, config: DebugConfig): Promise<boo
125
132
try {
126
133
info = JSON . parse ( rawStdout ) ;
127
134
} catch ( err ) {
128
- vscode . window . showErrorMessage ( err ) ;
135
+ console . error ( `Could not parse JSON: <${ rawStdout } >` ) ;
136
+ showError ( err ) ;
129
137
}
130
138
if ( ! info ) {
131
139
return false ;
@@ -190,7 +198,7 @@ async function startLanguageServer(context: ExtensionContext, config: LanguageSe
190
198
191
199
async function buildLanguageClient ( config : LanguageServerConfig ) : Promise < LanguageClient > {
192
200
const { lsPath : command , clangdPath, cliDaemonAddr, cliDaemonInstance, board, flags, env, log } = config ;
193
- const args = [ '-clangd' , clangdPath , '-cli-daemon-addr' , cliDaemonAddr , '-cli-daemon-instance' , cliDaemonInstance , '-fqbn' , board . fqbn ] ;
201
+ const args = [ '-clangd' , clangdPath , '-cli-daemon-addr' , cliDaemonAddr , '-cli-daemon-instance' , cliDaemonInstance , '-fqbn' , board . fqbn , '-skip-libraries-discovery-on-rebuild' ] ;
194
202
if ( board . name ) {
195
203
args . push ( '-board-name' , board . name ) ;
196
204
}
@@ -252,6 +260,12 @@ async function buildLanguageClient(config: LanguageServerConfig): Promise<Langua
252
260
) ;
253
261
}
254
262
263
+ function showError ( err : unknown ) : void {
264
+ console . error ( err ) ;
265
+ const message = err instanceof Error ? err . message : typeof err === 'string' ? err : String ( err ) ;
266
+ vscode . window . showErrorMessage ( message ) ;
267
+ }
268
+
255
269
/**
256
270
* Instead of writing the `launch.json` to the workspace, the file is written to the temporary binary output location.
257
271
*/
0 commit comments