Generate diagnostics when indexing a file, even if non-interactive.

This commit is contained in:
Jacob Dufault 2017-06-19 18:52:25 -07:00
parent ced7c878b7
commit a005cc627d
3 changed files with 31 additions and 0 deletions

View File

@ -865,6 +865,11 @@ void ParseFile(Config* config,
}
}
// Publish diagnostics for non-interactive index.
else {
EmitDiagnostics(working_files, new_index->path, new_index->diagnostics_);
}
// Any any existing dependencies to |new_index| that were there before,
// because we will not reparse them if they haven't changed.
// TODO: indexer should always include dependencies. This doesn't let us remove old dependencies.

View File

@ -369,6 +369,29 @@ int abortQuery(CXClientData client_data, void* reserved) {
void diagnostic(CXClientData client_data,
CXDiagnosticSet diagnostics,
void* reserved) {
IndexParam* param = static_cast<IndexParam*>(client_data);
for (unsigned i = 0; i < clang_getNumDiagnosticsInSet(diagnostics); ++i) {
CXDiagnostic diagnostic = clang_getDiagnosticInSet(diagnostics, i);
// Skip diagnostics in system headers.
CXSourceLocation diag_loc = clang_getDiagnosticLocation(diagnostic);
if (clang_Location_isInSystemHeader(diag_loc))
continue;
// Get db so we can attribute diagnostic to the right indexed file.
CXFile file;
unsigned int line, column;
clang_getSpellingLocation(diag_loc, &file, &line, &column, nullptr);
IndexFile* db = ConsumeFile(param, file);
if (!db)
continue;
// Build diagnostic.
optional<lsDiagnostic> ls_diagnostic = BuildAndDisposeDiagnostic(diagnostic);
if (ls_diagnostic)
db->diagnostics_.push_back(*ls_diagnostic);
}
}
CXIdxClientFile enteredMainFile(CXClientData client_data,

View File

@ -477,6 +477,9 @@ struct IndexFile {
std::vector<IndexFunc> funcs;
std::vector<IndexVar> vars;
// Diagnostics found when indexing this file. Not serialized.
NonElidedVector<lsDiagnostic> diagnostics_;
IndexFile(const std::string& path);
IndexTypeId ToTypeId(const std::string& usr);