Add diagnostics.onSave

This commit is contained in:
Fangrui Song 2018-09-08 16:00:14 -07:00
parent 1df131d411
commit 68a27e746d
5 changed files with 13 additions and 13 deletions

View File

@ -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<std::string> 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,

View File

@ -484,8 +484,7 @@ struct Handler_Initialize : BaseMessageHandler<In_InitializeRequest> {
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();
}

View File

@ -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);

View File

@ -153,8 +153,7 @@ std::unique_ptr<IndexFile> 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<Index_Request> opt_request = index_request->TryPopFront();
if (!opt_request)
@ -337,13 +336,11 @@ void Init() {
for_stdout = new ThreadedQueue<Stdout_Request>(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);
}

View File

@ -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<std::string> &args,