diff --git a/src/config.h b/src/config.h index 565c671c..310d8dba 100644 --- a/src/config.h +++ b/src/config.h @@ -154,6 +154,9 @@ struct Config { // If true, diagnostics will be reported for textDocument/didOpen. bool onOpen = true; + // If true, diagnostics will be reported for textDocument/didSave. + bool onSave = true; + bool spellChecking = true; std::vector whitelist; @@ -240,7 +243,7 @@ MAKE_REFLECT_STRUCT(Config::Completion, caseSensitivity, dropOldRequests, includeMaxPathSize, includeSuffixWhitelist, includeWhitelist); MAKE_REFLECT_STRUCT(Config::Diagnostics, blacklist, frequencyMs, onChange, - onOpen, spellChecking, whitelist) + onOpen, onSave, spellChecking, whitelist) MAKE_REFLECT_STRUCT(Config::Highlight, lsRanges, blacklist, whitelist) MAKE_REFLECT_STRUCT(Config::Index, blacklist, comments, enabled, multiVersion, multiVersionBlacklist, multiVersionWhitelist, onChange, diff --git a/src/messages/initialize.cc b/src/messages/initialize.cc index 332f8c5b..c4516ef1 100644 --- a/src/messages/initialize.cc +++ b/src/messages/initialize.cc @@ -496,8 +496,7 @@ struct Handler_Initialize : BaseMessageHandler { g_thread_id = i + 1; std::string name = "indexer" + std::to_string(i); set_thread_name(name.c_str()); - pipeline::Indexer_Main(clang_complete, diag_pub, vfs, project, - working_files); + pipeline::Indexer_Main(clang_complete, vfs, project, working_files); }) .detach(); } diff --git a/src/messages/textDocument_didSave.cc b/src/messages/textDocument_didSave.cc index 0badb21c..08520a92 100644 --- a/src/messages/textDocument_didSave.cc +++ b/src/messages/textDocument_didSave.cc @@ -49,6 +49,8 @@ struct Handler_TextDocumentDidSave Project::Entry entry = project->FindCompilationEntryForFile(path); pipeline::Index(entry.filename, entry.args, IndexMode::Normal); clang_complete->NotifySave(path); + if (g_config->diagnostics.onSave) + clang_complete->DiagnosticsUpdate(params.textDocument); } }; REGISTER_MESSAGE_HANDLER(Handler_TextDocumentDidSave); diff --git a/src/pipeline.cc b/src/pipeline.cc index ffab9e29..e6df6fd9 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -165,8 +165,7 @@ std::unique_ptr RawCacheLoad(const std::string &path) { IndexFile::kMajorVersion); } -bool Indexer_Parse(CompletionManager *completion, - DiagnosticsPublisher *diag_pub, WorkingFiles *wfiles, +bool Indexer_Parse(CompletionManager *completion, WorkingFiles *wfiles, Project *project, VFS *vfs, const GroupMatch &matcher) { std::optional opt_request = index_request->TryPopFront(); if (!opt_request) @@ -349,13 +348,11 @@ void Init() { for_stdout = new ThreadedQueue(stdout_waiter); } -void Indexer_Main(CompletionManager *completion, - DiagnosticsPublisher *diag_pub, VFS *vfs, Project *project, - WorkingFiles *working_files) { +void Indexer_Main(CompletionManager *completion, VFS *vfs, Project *project, + WorkingFiles *wfiles) { GroupMatch matcher(g_config->index.whitelist, g_config->index.blacklist); while (true) - if (!Indexer_Parse(completion, diag_pub, working_files, project, vfs, - matcher)) + if (!Indexer_Parse(completion, wfiles, project, vfs, matcher)) indexer_waiter->Wait(index_request); } diff --git a/src/pipeline.hh b/src/pipeline.hh index da9bfc9e..6e311d5c 100644 --- a/src/pipeline.hh +++ b/src/pipeline.hh @@ -38,9 +38,8 @@ namespace pipeline { void Init(); void LaunchStdin(); void LaunchStdout(); -void Indexer_Main(CompletionManager *complete, - DiagnosticsPublisher *diag_pub, VFS *vfs, Project *project, - WorkingFiles *working_files); +void Indexer_Main(CompletionManager *completion, VFS *vfs, Project *project, + WorkingFiles *wfiles); void MainLoop(); void Index(const std::string &path, const std::vector &args,