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