From e3a4e49ea6ef425da1cd6b5edb93ad3e06e608d9 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Sat, 8 Sep 2018 16:00:14 -0700 Subject: [PATCH] Add diagnostics.onSave --- src/config.h | 5 ++++- src/messages/initialize.cc | 3 +-- src/messages/textDocument_didSave.cc | 2 ++ src/pipeline.cc | 11 ++++------- src/pipeline.hh | 5 ++--- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/config.h b/src/config.h index b7e1c850..0f675813 100644 --- a/src/config.h +++ b/src/config.h @@ -142,6 +142,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; @@ -228,7 +231,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 f860f4b6..32059de9 100644 --- a/src/messages/initialize.cc +++ b/src/messages/initialize.cc @@ -484,8 +484,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 25c8bc81..9d9b7101 100644 --- a/src/messages/textDocument_didSave.cc +++ b/src/messages/textDocument_didSave.cc @@ -37,6 +37,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 27a414b5..c477fb90 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -153,8 +153,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) @@ -337,13 +336,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 4ebd5f43..a22c059a 100644 --- a/src/pipeline.hh +++ b/src/pipeline.hh @@ -41,9 +41,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,