Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
}
Expand All @@ -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,
Expand Down Expand Up @@ -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
}
}
Expand Down