@@ -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" )
@@ -604,6 +606,11 @@ func (handler *InoHandler) refreshCppDocumentSymbols(prefix string) error {
604
606
symbols = symbols [:i ]
605
607
606
608
canary := ""
609
+ for _ , line := range strings .Split (handler .sketchMapper .CppText .Text , "\n " ) {
610
+ if strings .Contains (line , "#include <" ) {
611
+ canary += line
612
+ }
613
+ }
607
614
for _ , symbol := range symbols {
608
615
log .Printf (prefix + " symbol: %s %s %s" , symbol .Kind , symbol .Name , symbol .Range )
609
616
if symbolText , err := textutils .ExtractRange (handler .sketchMapper .CppText .Text , symbol .Range ); err != nil {
@@ -648,9 +655,10 @@ func (handler *InoHandler) CheckCppDocumentSymbols() error {
648
655
return nil
649
656
}
650
657
651
- func startClangd (compileCommandsDir , sketchCpp * paths.Path ) (io. WriteCloser , io. ReadCloser , io. ReadCloser ) {
658
+ func examineCompileCommandsJSON (compileCommandsDir * paths.Path ) map [ string ] bool {
652
659
// Open compile_commands.json and find the main cross-compiler executable
653
- compileCommands , err := builder .LoadCompilationDatabase (compileCommandsDir .Join ("compile_commands.json" ))
660
+ compileCommandsJSONPath := compileCommandsDir .Join ("compile_commands.json" )
661
+ compileCommands , err := builder .LoadCompilationDatabase (compileCommandsJSONPath )
654
662
if err != nil {
655
663
panic ("could not find compile_commands.json" )
656
664
}
@@ -676,6 +684,10 @@ func startClangd(compileCommandsDir, sketchCpp *paths.Path) (io.WriteCloser, io.
676
684
// Save back compile_commands.json with OS native file separator and extension
677
685
compileCommands .SaveToFile ()
678
686
687
+ return compilers
688
+ }
689
+
690
+ func startClangd (compileCommandsDir , sketchCpp * paths.Path , compilers map [string ]bool ) (io.WriteCloser , io.ReadCloser , io.ReadCloser ) {
679
691
// Start clangd
680
692
args := []string {
681
693
globalClangdPath ,
@@ -1596,7 +1608,8 @@ func (handler *InoHandler) FromClangd(ctx context.Context, connection *jsonrpc2.
1596
1608
for _ , diag := range inoDiag .Diagnostics {
1597
1609
if diag .Code == "undeclared_var_use_suggest" ||
1598
1610
diag .Code == "undeclared_var_use" ||
1599
- diag .Code == "ovl_no_viable_function_in_call" {
1611
+ diag .Code == "ovl_no_viable_function_in_call" ||
1612
+ diag .Code == "pp_file_not_found" {
1600
1613
handler .buildSketchSymbolsCheck = true
1601
1614
}
1602
1615
}
0 commit comments