From 22bb89fca1c13b06597729b866037b59e079990d Mon Sep 17 00:00:00 2001 From: Jacob Dufault Date: Sat, 15 Jul 2017 17:25:52 -0700 Subject: [PATCH] Add options to turn off diagnostics. diagnostics.onParse: semi-real time diagnostics that reported when a file is indexed or prepared for code completion diagnostics.onCodeComplete: real time diagnostics that are reported as you type --- src/clang_complete.cc | 25 ++++++++++++++----------- src/command_line.cc | 2 +- src/config.h | 9 +++++++++ 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/clang_complete.cc b/src/clang_complete.cc index 3eaeb89c..68268a58 100644 --- a/src/clang_complete.cc +++ b/src/clang_complete.cc @@ -290,7 +290,7 @@ void EnsureDocumentParsed(ClangCompleteManager* manager, std::cerr << "[complete] Done creating active; did_fail=" << (*tu)->did_fail << std::endl; // Build diagnostics. - if (!(*tu)->did_fail) { + if (manager->config_->diagnosticsOnParse && !(*tu)->did_fail) { NonElidedVector ls_diagnostics; unsigned num_diagnostics = clang_getNumDiagnostics((*tu)->cx_tu); for (unsigned i = 0; i < num_diagnostics; ++i) { @@ -449,23 +449,26 @@ void CompletionQueryMain(ClangCompleteManager* completion_manager) { timer.ResetAndPrint("[complete] Running user-given completion func"); } - unsigned num_diagnostics = clang_codeCompleteGetNumDiagnostics(cx_results); - NonElidedVector ls_diagnostics; - for (unsigned i = 0; i < num_diagnostics; ++i) { - CXDiagnostic cx_diag = clang_codeCompleteGetDiagnostic(cx_results, i); - optional diagnostic = BuildAndDisposeDiagnostic(cx_diag, path); - if (diagnostic) - ls_diagnostics.push_back(*diagnostic); + if (completion_manager->config_->diagnosticsOnCodeCompletion) { + unsigned num_diagnostics = clang_codeCompleteGetNumDiagnostics(cx_results); + NonElidedVector ls_diagnostics; + for (unsigned i = 0; i < num_diagnostics; ++i) { + CXDiagnostic cx_diag = clang_codeCompleteGetDiagnostic(cx_results, i); + optional diagnostic = BuildAndDisposeDiagnostic(cx_diag, path); + if (diagnostic) + ls_diagnostics.push_back(*diagnostic); + } + completion_manager->on_diagnostic_(session->file.filename, ls_diagnostics); + timer.ResetAndPrint("[complete] Build diagnostics"); } - completion_manager->on_diagnostic_(session->file.filename, ls_diagnostics); - timer.ResetAndPrint("[complete] Build diagnostics"); } // Make sure |ls_results| is destroyed before clearing |cx_results|. clang_disposeCodeCompleteResults(cx_results); timer.ResetAndPrint("[complete] clang_disposeCodeCompleteResults"); - if (request->is_user_completion) { + if (completion_manager->config_->diagnosticsOnCodeCompletion && + request->is_user_completion) { { std::lock_guard lock(completion_manager->delayed_diagnostic_wakeup_mtx_); completion_manager->delayed_diagnostic_last_completion_position_ = request->location; diff --git a/src/command_line.cc b/src/command_line.cc index ba3181ed..3eabc908 100644 --- a/src/command_line.cc +++ b/src/command_line.cc @@ -902,7 +902,7 @@ void ParseFile(Config* config, } // Publish diagnostics for non-interactive index. - else { + else if (config->diagnosticsOnParse) { EmitDiagnostics(working_files, new_index->path, new_index->diagnostics_); } diff --git a/src/config.h b/src/config.h index 62799700..94003840 100644 --- a/src/config.h +++ b/src/config.h @@ -7,6 +7,7 @@ struct Config { // Root directory of the project. **Not serialized** std::string projectRoot; + // Cache directory for indexed files. std::string cacheDirectory; std::vector extraClangArguments; @@ -50,6 +51,11 @@ struct Config { std::vector includeCompletionWhitelist; std::vector includeCompletionBlacklist; + // If true, diagnostics from a full document parse will be reported. + bool diagnosticsOnParse = true; + // If true, diagnostics from code completion will be reported. + bool diagnosticsOnCodeCompletion = true; + // Enables code lens on parameter and function variables. bool codeLensOnLocalVariables = true; @@ -74,6 +80,9 @@ MAKE_REFLECT_STRUCT(Config, showDocumentLinksOnIncludes, + diagnosticsOnParse, + diagnosticsOnCodeCompletion, + codeLensOnLocalVariables, clientVersion); \ No newline at end of file