diff --git a/CMakeLists.txt b/CMakeLists.txt index d48f36b6..9574aad8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -209,7 +209,6 @@ target_sources(ccls PRIVATE ) target_sources(ccls PRIVATE - src/messages/ccls_base.cc src/messages/ccls_callHierarchy.cc src/messages/ccls_callers.cc src/messages/ccls_fileInfo.cc diff --git a/src/clang_complete.cc b/src/clang_complete.cc index 2bf26e9f..f9373e60 100644 --- a/src/clang_complete.cc +++ b/src/clang_complete.cc @@ -538,7 +538,7 @@ void CompletionPreloadMain(ClangCompleteManager *completion_manager) { } } -void CompletionQueryMain(ClangCompleteManager *completion_manager) { +void CompletionMain(ClangCompleteManager *completion_manager) { while (true) { // Fetching the completion request blocks until we have a request. std::unique_ptr request = @@ -576,7 +576,7 @@ void CompletionQueryMain(ClangCompleteManager *completion_manager) { FOpts.SkipFunctionBodies = true; CI->getLangOpts()->CommentOpts.ParseAllComments = true; - StoreDiags DC; + DiagnosticConsumer DC; WorkingFiles::Snapshot snapshot = completion_manager->working_files_->AsSnapshot({StripFileType(path)}); std::vector> Bufs; @@ -595,7 +595,7 @@ void CompletionQueryMain(ClangCompleteManager *completion_manager) { } } -void DiagnosticQueryMain(ClangCompleteManager *manager) { +void DiagnosticMain(ClangCompleteManager *manager) { while (true) { // Fetching the completion request blocks until we have a request. ClangCompleteManager::DiagnosticRequest request = @@ -698,8 +698,8 @@ ClangCompleteManager::ClangCompleteManager(Project *project, completion_sessions_(kMaxCompletionSessions), PCH(std::make_shared()) { std::thread([&]() { - set_thread_name("comp-query"); - ccls::CompletionQueryMain(this); + set_thread_name("comp"); + ccls::CompletionMain(this); }) .detach(); std::thread([&]() { @@ -708,8 +708,8 @@ ClangCompleteManager::ClangCompleteManager(Project *project, }) .detach(); std::thread([&]() { - set_thread_name("diag-query"); - ccls::DiagnosticQueryMain(this); + set_thread_name("diag"); + ccls::DiagnosticMain(this); }) .detach(); } diff --git a/src/indexer.cc b/src/indexer.cc index 203d08e8..4b73ba71 100644 --- a/src/indexer.cc +++ b/src/indexer.cc @@ -999,7 +999,6 @@ public: break; case Decl::EnumConstant: var->def.kind = lsSymbolKind::EnumMember; - // TODO Pretty printer may print = if (is_def && strchr(var->def.detailed_name, '=') == nullptr) { auto *ECD = cast(D); const auto &Val = ECD->getInitVal(); diff --git a/src/messages/ccls_base.cc b/src/messages/ccls_base.cc deleted file mode 100644 index 03184462..00000000 --- a/src/messages/ccls_base.cc +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2017-2018 ccls Authors -// SPDX-License-Identifier: Apache-2.0 - -#include "message_handler.h" -#include "pipeline.hh" -#include "query_utils.h" -using namespace ccls; - -namespace { - -MethodType kMethodType = "$ccls/base"; - -struct In_CclsBase : public RequestInMessage { - MethodType GetMethodType() const override { return kMethodType; } - - lsTextDocumentPositionParams params; -}; -MAKE_REFLECT_STRUCT(In_CclsBase, id, params); -REGISTER_IN_MESSAGE(In_CclsBase); - -struct Handler_CclsBase : BaseMessageHandler { - MethodType GetMethodType() const override { return kMethodType; } - - void Run(In_CclsBase *request) override { - QueryFile *file; - if (!FindFileOrFail(db, project, request->id, - request->params.textDocument.uri.GetPath(), &file)) { - return; - } - - WorkingFile *working_file = - working_files->GetFileByFilename(file->def->path); - - Out_LocationList out; - out.id = request->id; - for (SymbolRef sym : - FindSymbolsAtLocation(working_file, file, request->params.position)) { - if (sym.kind == SymbolKind::Type) { - if (const auto *def = db->GetType(sym).AnyDef()) - out.result = GetLsLocationExs(db, working_files, - GetTypeDeclarations(db, def->bases)); - break; - } else if (sym.kind == SymbolKind::Func) { - if (const auto *def = db->GetFunc(sym).AnyDef()) - out.result = GetLsLocationExs(db, working_files, - GetFuncDeclarations(db, def->bases)); - break; - } - } - pipeline::WriteStdout(kMethodType, out); - } -}; -REGISTER_MESSAGE_HANDLER(Handler_CclsBase); -} // namespace diff --git a/src/messages/ccls_callHierarchy.cc b/src/messages/ccls_callHierarchy.cc index c5cf5748..b53f574e 100644 --- a/src/messages/ccls_callHierarchy.cc +++ b/src/messages/ccls_callHierarchy.cc @@ -3,7 +3,6 @@ #include "message_handler.h" #include "pipeline.hh" -using namespace ccls; #include "query_utils.h" using namespace ccls; diff --git a/src/messages/textDocument_codeLens.cc b/src/messages/textDocument_codeLens.cc index 1713a6d1..c7b62e8e 100644 --- a/src/messages/textDocument_codeLens.cc +++ b/src/messages/textDocument_codeLens.cc @@ -8,19 +8,19 @@ #include "query_utils.h" using namespace ccls; +#include + namespace { MethodType kMethodType = "textDocument/codeLens"; -struct lsDocumentCodeLensParams { - lsTextDocumentIdentifier textDocument; -}; -MAKE_REFLECT_STRUCT(lsDocumentCodeLensParams, textDocument); - using TCodeLens = lsCodeLens; struct In_TextDocumentCodeLens : public RequestInMessage { MethodType GetMethodType() const override { return kMethodType; } - lsDocumentCodeLensParams params; + struct Params { + lsTextDocumentIdentifier textDocument; + } params; }; +MAKE_REFLECT_STRUCT(In_TextDocumentCodeLens::Params, textDocument); MAKE_REFLECT_STRUCT(In_TextDocumentCodeLens, id, params); REGISTER_IN_MESSAGE(In_TextDocumentCodeLens); @@ -84,19 +84,17 @@ struct Handler_TextDocumentCodeLens : BaseMessageHandler { MethodType GetMethodType() const override { return kMethodType; } void Run(In_TextDocumentCodeLens *request) override { + auto ¶ms = request->params; Out_TextDocumentCodeLens out; out.id = request->id; - lsDocumentUri file_as_uri = request->params.textDocument.uri; - std::string path = file_as_uri.GetPath(); - + std::string path = params.textDocument.uri.GetPath(); clang_complete->NotifyView(path); QueryFile *file; if (!FindFileOrFail(db, project, request->id, - request->params.textDocument.uri.GetPath(), &file)) { + params.textDocument.uri.GetPath(), &file)) return; - } CommonCodeLensParams common; common.result = &out.result; @@ -104,8 +102,10 @@ struct Handler_TextDocumentCodeLens common.working_files = working_files; common.working_file = working_files->GetFileByFilename(file->def->path); + std::unordered_set seen; for (auto [sym, refcnt] : file->outline2refcnt) { - if (refcnt <= 0) continue; + if (refcnt <= 0 || !seen.insert(sym.range).second) + continue; // NOTE: We OffsetColumn so that the code lens always show up in a // predictable order. Otherwise, the client may randomize it. Use use{{sym.range, sym.usr, sym.kind, sym.role}, file->id};