diff --git a/src/indexer.cc b/src/indexer.cc index cdd7330f..2efecd45 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -2054,7 +2054,7 @@ std::vector> ClangIndexer::Index( file = NormalizePath(file); - Timer timer("parse", "parse tu"); + static Timer timer("parse", "parse tu"); timer.startTimer(); std::vector unsaved_files; diff --git a/src/messages/textDocument_completion.cc b/src/messages/textDocument_completion.cc index a3573270..1479f803 100644 --- a/src/messages/textDocument_completion.cc +++ b/src/messages/textDocument_completion.cc @@ -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; diff --git a/src/messages/textDocument_documentSymbol.cc b/src/messages/textDocument_documentSymbol.cc index a66ffec2..288c14ad 100644 --- a/src/messages/textDocument_documentSymbol.cc +++ b/src/messages/textDocument_documentSymbol.cc @@ -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 { lsRequestId id; - std::vector result; + std::vector 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 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; diff --git a/src/pipeline.cc b/src/pipeline.cc index d511b1c3..cd8a8482 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -18,6 +18,9 @@ using namespace llvm; #include #include +#ifndef _WIN32 +#include +#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 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::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();