mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-22 07:35:08 +00:00
diagnostics
This commit is contained in:
parent
2682964039
commit
b784685c61
@ -2054,7 +2054,7 @@ std::vector<std::unique_ptr<IndexFile>> ClangIndexer::Index(
|
||||
|
||||
file = NormalizePath(file);
|
||||
|
||||
Timer timer("parse", "parse tu");
|
||||
static Timer timer("parse", "parse tu");
|
||||
timer.startTimer();
|
||||
|
||||
std::vector<CXUnsavedFile> unsaved_files;
|
||||
|
@ -164,7 +164,7 @@ void FilterAndSortCompletionResponse(
|
||||
if (!g_config->completion.filterAndSort)
|
||||
return;
|
||||
|
||||
Timer timer("FilterAndSortCompletionResponse", "");
|
||||
static Timer timer("FilterAndSortCompletionResponse", "");
|
||||
TimeRegion region(timer);
|
||||
|
||||
auto& items = complete_response->result.items;
|
||||
|
@ -9,9 +9,10 @@ MethodType kMethodType = "textDocument/documentSymbol";
|
||||
|
||||
struct lsDocumentSymbolParams {
|
||||
lsTextDocumentIdentifier textDocument;
|
||||
bool all = false;
|
||||
int startLine = -1;
|
||||
int endLine = -1;
|
||||
};
|
||||
MAKE_REFLECT_STRUCT(lsDocumentSymbolParams, textDocument, all);
|
||||
MAKE_REFLECT_STRUCT(lsDocumentSymbolParams, textDocument, startLine, endLine);
|
||||
|
||||
struct In_TextDocumentDocumentSymbol : public RequestInMessage {
|
||||
MethodType GetMethodType() const override { return kMethodType; }
|
||||
@ -20,18 +21,10 @@ struct In_TextDocumentDocumentSymbol : public RequestInMessage {
|
||||
MAKE_REFLECT_STRUCT(In_TextDocumentDocumentSymbol, id, params);
|
||||
REGISTER_IN_MESSAGE(In_TextDocumentDocumentSymbol);
|
||||
|
||||
struct lsSimpleLocation {
|
||||
lsRange range;
|
||||
};
|
||||
MAKE_REFLECT_STRUCT(lsSimpleLocation, range);
|
||||
struct lsSimpleSymbolInformation {
|
||||
lsSimpleLocation location;
|
||||
};
|
||||
MAKE_REFLECT_STRUCT(lsSimpleSymbolInformation, location);
|
||||
struct Out_SimpleDocumentSymbol
|
||||
: public lsOutMessage<Out_SimpleDocumentSymbol> {
|
||||
lsRequestId id;
|
||||
std::vector<lsSimpleSymbolInformation> result;
|
||||
std::vector<lsRange> result;
|
||||
};
|
||||
MAKE_REFLECT_STRUCT(Out_SimpleDocumentSymbol, jsonrpc, id, result);
|
||||
|
||||
@ -54,14 +47,18 @@ struct Handler_TextDocumentDocumentSymbol
|
||||
params.textDocument.uri.GetPath(), &file, &file_id))
|
||||
return;
|
||||
|
||||
if (params.all) {
|
||||
if (params.startLine >= 0) {
|
||||
Out_SimpleDocumentSymbol out;
|
||||
out.id = request->id;
|
||||
for (SymbolRef sym : file->def->all_symbols)
|
||||
if (std::optional<lsLocation> location = GetLsLocation(
|
||||
db, working_files,
|
||||
Use{{sym.range, sym.usr, sym.kind, sym.role}, file_id}))
|
||||
out.result.push_back({{location->range}});
|
||||
Use{{sym.range, sym.usr, sym.kind, sym.role}, file_id})) {
|
||||
if (params.startLine <= sym.range.start.line &&
|
||||
sym.range.start.line <= params.endLine)
|
||||
out.result.push_back(location->range);
|
||||
}
|
||||
std::sort(out.result.begin(), out.result.end());
|
||||
pipeline::WriteStdout(kMethodType, out);
|
||||
} else {
|
||||
Out_TextDocumentDocumentSymbol out;
|
||||
|
@ -18,6 +18,9 @@ using namespace llvm;
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
void DiagnosticsPublisher::Init() {
|
||||
frequencyMs_ = g_config->diagnostics.frequencyMs;
|
||||
@ -28,17 +31,21 @@ void DiagnosticsPublisher::Init() {
|
||||
void DiagnosticsPublisher::Publish(WorkingFiles* working_files,
|
||||
std::string path,
|
||||
std::vector<lsDiagnostic> diagnostics) {
|
||||
bool good = true;
|
||||
// Cache diagnostics so we can show fixits.
|
||||
working_files->DoActionOnFile(path, [&](WorkingFile* working_file) {
|
||||
if (working_file)
|
||||
if (working_file) {
|
||||
good = working_file->diagnostics_.empty();
|
||||
working_file->diagnostics_ = diagnostics;
|
||||
}
|
||||
});
|
||||
|
||||
int64_t now =
|
||||
std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::high_resolution_clock::now().time_since_epoch())
|
||||
.count();
|
||||
if (frequencyMs_ >= 0 && (nextPublish_ <= now || diagnostics.empty()) &&
|
||||
if (frequencyMs_ >= 0 &&
|
||||
(nextPublish_ <= now || (!good && diagnostics.empty())) &&
|
||||
match_->IsMatch(path)) {
|
||||
nextPublish_ = now + frequencyMs_;
|
||||
|
||||
@ -258,7 +265,7 @@ bool Indexer_Parse(DiagnosticsPublisher* diag_pub,
|
||||
// Write current index to disk if requested.
|
||||
LOG_S(INFO) << "store index for " << path;
|
||||
{
|
||||
Timer timer("write", "store index");
|
||||
static Timer timer("write", "store index");
|
||||
timer.startTimer();
|
||||
std::string cache_path = GetCachePath(path);
|
||||
WriteToFile(cache_path, curr->file_contents);
|
||||
@ -328,7 +335,7 @@ void Main_OnIndexed(DB* db,
|
||||
return;
|
||||
}
|
||||
|
||||
Timer timer("apply", "apply index");
|
||||
static Timer timer("apply", "apply index");
|
||||
timer.startTimer();
|
||||
db->ApplyIndexUpdate(update);
|
||||
timer.stopTimer();
|
||||
@ -397,8 +404,12 @@ void LaunchStdout() {
|
||||
}
|
||||
|
||||
for (auto& message : messages) {
|
||||
#ifdef _WIN32
|
||||
fwrite(message.content.c_str(), message.content.size(), 1, stdout);
|
||||
fflush(stdout);
|
||||
#else
|
||||
write(1, message.content.c_str(), message.content.size());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}).detach();
|
||||
|
Loading…
Reference in New Issue
Block a user