2018-03-06 01:18:33 +00:00
|
|
|
#include "diagnostics_engine.h"
|
|
|
|
|
|
|
|
#include "queue_manager.h"
|
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
|
2018-03-06 03:03:39 +00:00
|
|
|
void DiagnosticsEngine::Init(Config* config) {
|
|
|
|
frequencyMs_ = config->diagnostics.frequencyMs;
|
2018-03-10 23:40:27 +00:00
|
|
|
match_ = std::make_unique<GroupMatch>(config->diagnostics.whitelist,
|
2018-03-20 02:51:42 +00:00
|
|
|
config->diagnostics.blacklist);
|
2018-03-06 03:03:39 +00:00
|
|
|
}
|
|
|
|
|
2018-03-06 01:18:33 +00:00
|
|
|
void DiagnosticsEngine::Publish(WorkingFiles* working_files,
|
|
|
|
std::string path,
|
|
|
|
std::vector<lsDiagnostic> diagnostics) {
|
2018-03-20 12:47:12 +00:00
|
|
|
// Cache diagnostics so we can show fixits.
|
|
|
|
working_files->DoActionOnFile(path, [&](WorkingFile* working_file) {
|
|
|
|
if (working_file)
|
|
|
|
working_file->diagnostics_ = diagnostics;
|
|
|
|
});
|
2018-03-06 01:18:33 +00:00
|
|
|
|
2018-03-20 02:51:42 +00:00
|
|
|
int64_t now =
|
|
|
|
std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
|
|
std::chrono::high_resolution_clock::now().time_since_epoch())
|
|
|
|
.count();
|
2018-03-06 01:18:33 +00:00
|
|
|
if (frequencyMs_ >= 0 && (nextPublish_ <= now || diagnostics.empty()) &&
|
2018-03-06 03:03:39 +00:00
|
|
|
match_->IsMatch(path)) {
|
2018-03-06 01:18:33 +00:00
|
|
|
nextPublish_ = now + frequencyMs_;
|
|
|
|
|
|
|
|
Out_TextDocumentPublishDiagnostics out;
|
|
|
|
out.params.uri = lsDocumentUri::FromPath(path);
|
|
|
|
out.params.diagnostics = diagnostics;
|
|
|
|
QueueManager::WriteStdout(IpcId::TextDocumentPublishDiagnostics, out);
|
|
|
|
}
|
|
|
|
}
|