@@ -514,6 +514,8 @@ func (handler *InoHandler) initializeWorkbench(ctx context.Context, params *lsp.
514
514
return errors .WithMessage (err , "reading generated cpp file from sketch" )
515
515
}
516
516
517
+ compilers := examineCompileCommandsJSON (handler .buildPath )
518
+
517
519
if params == nil {
518
520
// If we are restarting re-synchronize clangd
519
521
cppURI := lsp .NewDocumentURIFromPath (handler .buildSketchCpp )
@@ -535,7 +537,7 @@ func (handler *InoHandler) initializeWorkbench(ctx context.Context, params *lsp.
535
537
}
536
538
} else {
537
539
// Otherwise start clangd!
538
- clangdStdout , clangdStdin , clangdStderr := startClangd (handler .buildPath , handler .buildSketchCpp )
540
+ clangdStdout , clangdStdin , clangdStderr := startClangd (handler .buildPath , handler .buildSketchCpp , compilers )
539
541
clangdStdio := streams .NewReadWriteCloser (clangdStdin , clangdStdout )
540
542
if enableLogging {
541
543
clangdStdio = streams .LogReadWriteCloserAs (clangdStdio , "inols-clangd.log" )
@@ -648,9 +650,10 @@ func (handler *InoHandler) CheckCppDocumentSymbols() error {
648
650
return nil
649
651
}
650
652
651
- func startClangd (compileCommandsDir , sketchCpp * paths.Path ) (io. WriteCloser , io. ReadCloser , io. ReadCloser ) {
653
+ func examineCompileCommandsJSON (compileCommandsDir * paths.Path ) map [ string ] bool {
652
654
// Open compile_commands.json and find the main cross-compiler executable
653
- compileCommands , err := builder .LoadCompilationDatabase (compileCommandsDir .Join ("compile_commands.json" ))
655
+ compileCommandsJSONPath := compileCommandsDir .Join ("compile_commands.json" )
656
+ compileCommands , err := builder .LoadCompilationDatabase (compileCommandsJSONPath )
654
657
if err != nil {
655
658
panic ("could not find compile_commands.json" )
656
659
}
@@ -676,6 +679,10 @@ func startClangd(compileCommandsDir, sketchCpp *paths.Path) (io.WriteCloser, io.
676
679
// Save back compile_commands.json with OS native file separator and extension
677
680
compileCommands .SaveToFile ()
678
681
682
+ return compilers
683
+ }
684
+
685
+ func startClangd (compileCommandsDir , sketchCpp * paths.Path , compilers map [string ]bool ) (io.WriteCloser , io.ReadCloser , io.ReadCloser ) {
679
686
// Start clangd
680
687
args := []string {
681
688
globalClangdPath ,
0 commit comments