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
This commit is contained in:
Jacob Dufault 2017-07-15 17:25:52 -07:00
parent 152e98363f
commit 22bb89fca1
3 changed files with 24 additions and 12 deletions

View File

@ -290,7 +290,7 @@ void EnsureDocumentParsed(ClangCompleteManager* manager,
std::cerr << "[complete] Done creating active; did_fail=" << (*tu)->did_fail << std::endl; std::cerr << "[complete] Done creating active; did_fail=" << (*tu)->did_fail << std::endl;
// Build diagnostics. // Build diagnostics.
if (!(*tu)->did_fail) { if (manager->config_->diagnosticsOnParse && !(*tu)->did_fail) {
NonElidedVector<lsDiagnostic> ls_diagnostics; NonElidedVector<lsDiagnostic> ls_diagnostics;
unsigned num_diagnostics = clang_getNumDiagnostics((*tu)->cx_tu); unsigned num_diagnostics = clang_getNumDiagnostics((*tu)->cx_tu);
for (unsigned i = 0; i < num_diagnostics; ++i) { 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"); timer.ResetAndPrint("[complete] Running user-given completion func");
} }
unsigned num_diagnostics = clang_codeCompleteGetNumDiagnostics(cx_results); if (completion_manager->config_->diagnosticsOnCodeCompletion) {
NonElidedVector<lsDiagnostic> ls_diagnostics; unsigned num_diagnostics = clang_codeCompleteGetNumDiagnostics(cx_results);
for (unsigned i = 0; i < num_diagnostics; ++i) { NonElidedVector<lsDiagnostic> ls_diagnostics;
CXDiagnostic cx_diag = clang_codeCompleteGetDiagnostic(cx_results, i); for (unsigned i = 0; i < num_diagnostics; ++i) {
optional<lsDiagnostic> diagnostic = BuildAndDisposeDiagnostic(cx_diag, path); CXDiagnostic cx_diag = clang_codeCompleteGetDiagnostic(cx_results, i);
if (diagnostic) optional<lsDiagnostic> diagnostic = BuildAndDisposeDiagnostic(cx_diag, path);
ls_diagnostics.push_back(*diagnostic); 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|. // Make sure |ls_results| is destroyed before clearing |cx_results|.
clang_disposeCodeCompleteResults(cx_results); clang_disposeCodeCompleteResults(cx_results);
timer.ResetAndPrint("[complete] clang_disposeCodeCompleteResults"); timer.ResetAndPrint("[complete] clang_disposeCodeCompleteResults");
if (request->is_user_completion) { if (completion_manager->config_->diagnosticsOnCodeCompletion &&
request->is_user_completion) {
{ {
std::lock_guard<std::mutex> lock(completion_manager->delayed_diagnostic_wakeup_mtx_); std::lock_guard<std::mutex> lock(completion_manager->delayed_diagnostic_wakeup_mtx_);
completion_manager->delayed_diagnostic_last_completion_position_ = request->location; completion_manager->delayed_diagnostic_last_completion_position_ = request->location;

View File

@ -902,7 +902,7 @@ void ParseFile(Config* config,
} }
// Publish diagnostics for non-interactive index. // Publish diagnostics for non-interactive index.
else { else if (config->diagnosticsOnParse) {
EmitDiagnostics(working_files, new_index->path, new_index->diagnostics_); EmitDiagnostics(working_files, new_index->path, new_index->diagnostics_);
} }

View File

@ -7,6 +7,7 @@
struct Config { struct Config {
// Root directory of the project. **Not serialized** // Root directory of the project. **Not serialized**
std::string projectRoot; std::string projectRoot;
// Cache directory for indexed files.
std::string cacheDirectory; std::string cacheDirectory;
std::vector<std::string> extraClangArguments; std::vector<std::string> extraClangArguments;
@ -50,6 +51,11 @@ struct Config {
std::vector<std::string> includeCompletionWhitelist; std::vector<std::string> includeCompletionWhitelist;
std::vector<std::string> includeCompletionBlacklist; std::vector<std::string> 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. // Enables code lens on parameter and function variables.
bool codeLensOnLocalVariables = true; bool codeLensOnLocalVariables = true;
@ -74,6 +80,9 @@ MAKE_REFLECT_STRUCT(Config,
showDocumentLinksOnIncludes, showDocumentLinksOnIncludes,
diagnosticsOnParse,
diagnosticsOnCodeCompletion,
codeLensOnLocalVariables, codeLensOnLocalVariables,
clientVersion); clientVersion);