@@ -223,6 +223,7 @@ function findExecutables(): LanguageServerExecutables | undefined {
223
223
224
224
interface CompileResult {
225
225
readonly builder_result : { build_path : string } ;
226
+ readonly compiler_err ?: string ;
226
227
}
227
228
interface Platform {
228
229
readonly boards : Board [ ] ;
@@ -337,10 +338,13 @@ export function activate(context: ExtensionContext) {
337
338
}
338
339
// save all dirt editor for the sketch
339
340
await Promise . all ( vscode . workspace . textDocuments . filter ( document => getSketchPath ( document . uri ) === sketch ) . filter ( document => document . isDirty ) . map ( document => document . save ( ) ) ) ;
340
- const raw = await cliExec ( [ 'compile' , '-b' , fqbn , sketch , '--format' , 'json' ] ) ;
341
+ const raw = await cliExec ( [ 'compile' , '-b' , fqbn , sketch , '--config-file' , `" ${ cliConfigPath } "` , '-- format', 'json' ] ) ;
341
342
const languageClient = sketchContext ?. languageClient ;
342
343
if ( languageClient ) {
343
344
const result = JSON . parse ( raw ) as CompileResult ;
345
+ if ( result . compiler_err ) {
346
+ vscode . window . showErrorMessage ( `Compilation failed: ${ result . compiler_err } ` ) ;
347
+ }
344
348
const buildOutputUri = Uri . file ( result . builder_result . build_path ) . toString ( ) ;
345
349
languageClient . sendNotification ( DidCompleteBuildNotification . TYPE , { buildOutputUri } ) ;
346
350
}
@@ -374,7 +378,7 @@ async function selectFqbn(): Promise<string | undefined> {
374
378
return undefined ;
375
379
}
376
380
async function coreList ( ) : Promise < Platform [ ] > {
377
- const raw = await cliExec ( [ 'core' , 'list' , '--format' , 'json' ] ) ;
381
+ const raw = await cliExec ( [ 'core' , 'list' , '--config-file' , `" ${ cliConfigPath } "` , '-- format', 'json' ] ) ;
378
382
return JSON . parse ( raw ) as Platform [ ] ;
379
383
}
380
384
async function installedBoards ( ) : Promise < ( Board & { fqbn : string } ) [ ] > {
@@ -403,6 +407,16 @@ async function cliExec(args: string[] = []): Promise<string> {
403
407
console . log ( 'cli exec OK with args: ' + JSON . stringify ( args ) , raw ) ;
404
408
return resolve ( raw ) ;
405
409
} else {
410
+ const raw = Buffer . concat ( out ) . toString ( 'utf-8' ) ;
411
+ let json : CompileResult | undefined ;
412
+ try {
413
+ json = JSON . parse ( raw ) as CompileResult ;
414
+ } catch { }
415
+ // TODO: this should not be here.
416
+ // Quick workaround for https://github.com/arduino/arduino-ide/issues/714#issuecomment-1198304868.
417
+ if ( json && json . compiler_err ) {
418
+ return resolve ( raw ) ;
419
+ }
406
420
const error = Buffer . concat ( err ) . toString ( 'utf-8' ) ;
407
421
console . error ( 'cli exec err with args: ' + JSON . stringify ( args ) , error ) ;
408
422
return reject ( error ) ;
@@ -511,9 +525,10 @@ async function startLanguageServer(context: ExtensionContext, sketchContext: Ske
511
525
return true ;
512
526
}
513
527
528
+ const cliConfigPath = path . join ( os . homedir ( ) , '.arduinoIDE/arduino-cli.yaml' ) ;
514
529
async function buildLanguageClient ( config : LanguageServerConfig & LanguageServerExecutables , sketchContext : SketchContext ) : Promise < LanguageClient > {
515
530
const { lsPath : command , clangdPath, board, flags, env, log } = config ;
516
- const args = [ '-cli' , config . cliPath , '-cli-config' , path . join ( os . homedir ( ) , '.arduinoIDE/arduino-cli.yaml' ) , '-clangd' , clangdPath , '-fqbn' , board . fqbn ?? 'arduino:avr:uno' , '-skip-libraries-discovery-on-rebuild' ] ;
531
+ const args = [ '-cli' , config . cliPath , '-cli-config' , cliConfigPath , '-clangd' , clangdPath , '-fqbn' , board . fqbn ?? 'arduino:avr:uno' , '-skip-libraries-discovery-on-rebuild' ] ;
517
532
if ( board . name ) {
518
533
args . push ( '-board-name' , board . name ) ;
519
534
}
0 commit comments