@@ -514,6 +514,8 @@ func (handler *InoHandler) initializeWorkbench(ctx context.Context, params *lsp.
514514 return errors .WithMessage (err , "reading generated cpp file from sketch" )
515515 }
516516
517+ compilers := examineCompileCommandsJSON (handler .buildPath )
518+
517519 if params == nil {
518520 // If we are restarting re-synchronize clangd
519521 cppURI := lsp .NewDocumentURIFromPath (handler .buildSketchCpp )
@@ -535,7 +537,7 @@ func (handler *InoHandler) initializeWorkbench(ctx context.Context, params *lsp.
535537 }
536538 } else {
537539 // Otherwise start clangd!
538- clangdStdout , clangdStdin , clangdStderr := startClangd (handler .buildPath , handler .buildSketchCpp )
540+ clangdStdout , clangdStdin , clangdStderr := startClangd (handler .buildPath , handler .buildSketchCpp , compilers )
539541 clangdStdio := streams .NewReadWriteCloser (clangdStdin , clangdStdout )
540542 if enableLogging {
541543 clangdStdio = streams .LogReadWriteCloserAs (clangdStdio , "inols-clangd.log" )
@@ -648,9 +650,10 @@ func (handler *InoHandler) CheckCppDocumentSymbols() error {
648650 return nil
649651}
650652
651- func startClangd (compileCommandsDir , sketchCpp * paths.Path ) (io. WriteCloser , io. ReadCloser , io. ReadCloser ) {
653+ func examineCompileCommandsJSON (compileCommandsDir * paths.Path ) map [ string ] bool {
652654 // 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 )
654657 if err != nil {
655658 panic ("could not find compile_commands.json" )
656659 }
@@ -676,6 +679,10 @@ func startClangd(compileCommandsDir, sketchCpp *paths.Path) (io.WriteCloser, io.
676679 // Save back compile_commands.json with OS native file separator and extension
677680 compileCommands .SaveToFile ()
678681
682+ return compilers
683+ }
684+
685+ func startClangd (compileCommandsDir , sketchCpp * paths.Path , compilers map [string ]bool ) (io.WriteCloser , io.ReadCloser , io.ReadCloser ) {
679686 // Start clangd
680687 args := []string {
681688 globalClangdPath ,
0 commit comments