diff --git a/handler/handler.go b/handler/handler.go index 416c461..c7cc2a4 100644 --- a/handler/handler.go +++ b/handler/handler.go @@ -514,6 +514,8 @@ func (handler *InoHandler) initializeWorkbench(ctx context.Context, params *lsp. return errors.WithMessage(err, "reading generated cpp file from sketch") } + compilers := examineCompileCommandsJSON(handler.buildPath) + if params == nil { // If we are restarting re-synchronize clangd cppURI := lsp.NewDocumentURIFromPath(handler.buildSketchCpp) @@ -535,7 +537,7 @@ func (handler *InoHandler) initializeWorkbench(ctx context.Context, params *lsp. } } else { // Otherwise start clangd! - clangdStdout, clangdStdin, clangdStderr := startClangd(handler.buildPath, handler.buildSketchCpp) + clangdStdout, clangdStdin, clangdStderr := startClangd(handler.buildPath, handler.buildSketchCpp, compilers) clangdStdio := streams.NewReadWriteCloser(clangdStdin, clangdStdout) if enableLogging { clangdStdio = streams.LogReadWriteCloserAs(clangdStdio, "inols-clangd.log") @@ -604,6 +606,11 @@ func (handler *InoHandler) refreshCppDocumentSymbols(prefix string) error { symbols = symbols[:i] canary := "" + for _, line := range strings.Split(handler.sketchMapper.CppText.Text, "\n") { + if strings.Contains(line, "#include <") { + canary += line + } + } for _, symbol := range symbols { log.Printf(prefix+" symbol: %s %s %s", symbol.Kind, symbol.Name, symbol.Range) if symbolText, err := textutils.ExtractRange(handler.sketchMapper.CppText.Text, symbol.Range); err != nil { @@ -648,9 +655,10 @@ func (handler *InoHandler) CheckCppDocumentSymbols() error { return nil } -func startClangd(compileCommandsDir, sketchCpp *paths.Path) (io.WriteCloser, io.ReadCloser, io.ReadCloser) { +func examineCompileCommandsJSON(compileCommandsDir *paths.Path) map[string]bool { // Open compile_commands.json and find the main cross-compiler executable - compileCommands, err := builder.LoadCompilationDatabase(compileCommandsDir.Join("compile_commands.json")) + compileCommandsJSONPath := compileCommandsDir.Join("compile_commands.json") + compileCommands, err := builder.LoadCompilationDatabase(compileCommandsJSONPath) if err != nil { panic("could not find compile_commands.json") } @@ -676,6 +684,10 @@ func startClangd(compileCommandsDir, sketchCpp *paths.Path) (io.WriteCloser, io. // Save back compile_commands.json with OS native file separator and extension compileCommands.SaveToFile() + return compilers +} + +func startClangd(compileCommandsDir, sketchCpp *paths.Path, compilers map[string]bool) (io.WriteCloser, io.ReadCloser, io.ReadCloser) { // Start clangd args := []string{ globalClangdPath, @@ -1596,7 +1608,8 @@ func (handler *InoHandler) FromClangd(ctx context.Context, connection *jsonrpc2. for _, diag := range inoDiag.Diagnostics { if diag.Code == "undeclared_var_use_suggest" || diag.Code == "undeclared_var_use" || - diag.Code == "ovl_no_viable_function_in_call" { + diag.Code == "ovl_no_viable_function_in_call" || + diag.Code == "pp_file_not_found" { handler.buildSketchSymbolsCheck = true } }