mirror of
https://github.com/MaskRay/ccls.git
synced 2024-12-04 13:37:08 +00:00
Remove $ccls/base and clean up; deduplicate codeLens
This commit is contained in:
parent
e28cd1733f
commit
142ff883e5
@ -209,7 +209,6 @@ target_sources(ccls PRIVATE
|
|||||||
)
|
)
|
||||||
|
|
||||||
target_sources(ccls PRIVATE
|
target_sources(ccls PRIVATE
|
||||||
src/messages/ccls_base.cc
|
|
||||||
src/messages/ccls_callHierarchy.cc
|
src/messages/ccls_callHierarchy.cc
|
||||||
src/messages/ccls_callers.cc
|
src/messages/ccls_callers.cc
|
||||||
src/messages/ccls_fileInfo.cc
|
src/messages/ccls_fileInfo.cc
|
||||||
|
@ -538,7 +538,7 @@ void CompletionPreloadMain(ClangCompleteManager *completion_manager) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CompletionQueryMain(ClangCompleteManager *completion_manager) {
|
void CompletionMain(ClangCompleteManager *completion_manager) {
|
||||||
while (true) {
|
while (true) {
|
||||||
// Fetching the completion request blocks until we have a request.
|
// Fetching the completion request blocks until we have a request.
|
||||||
std::unique_ptr<ClangCompleteManager::CompletionRequest> request =
|
std::unique_ptr<ClangCompleteManager::CompletionRequest> request =
|
||||||
@ -576,7 +576,7 @@ void CompletionQueryMain(ClangCompleteManager *completion_manager) {
|
|||||||
FOpts.SkipFunctionBodies = true;
|
FOpts.SkipFunctionBodies = true;
|
||||||
CI->getLangOpts()->CommentOpts.ParseAllComments = true;
|
CI->getLangOpts()->CommentOpts.ParseAllComments = true;
|
||||||
|
|
||||||
StoreDiags DC;
|
DiagnosticConsumer DC;
|
||||||
WorkingFiles::Snapshot snapshot =
|
WorkingFiles::Snapshot snapshot =
|
||||||
completion_manager->working_files_->AsSnapshot({StripFileType(path)});
|
completion_manager->working_files_->AsSnapshot({StripFileType(path)});
|
||||||
std::vector<std::unique_ptr<llvm::MemoryBuffer>> Bufs;
|
std::vector<std::unique_ptr<llvm::MemoryBuffer>> Bufs;
|
||||||
@ -595,7 +595,7 @@ void CompletionQueryMain(ClangCompleteManager *completion_manager) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiagnosticQueryMain(ClangCompleteManager *manager) {
|
void DiagnosticMain(ClangCompleteManager *manager) {
|
||||||
while (true) {
|
while (true) {
|
||||||
// Fetching the completion request blocks until we have a request.
|
// Fetching the completion request blocks until we have a request.
|
||||||
ClangCompleteManager::DiagnosticRequest request =
|
ClangCompleteManager::DiagnosticRequest request =
|
||||||
@ -698,8 +698,8 @@ ClangCompleteManager::ClangCompleteManager(Project *project,
|
|||||||
completion_sessions_(kMaxCompletionSessions),
|
completion_sessions_(kMaxCompletionSessions),
|
||||||
PCH(std::make_shared<PCHContainerOperations>()) {
|
PCH(std::make_shared<PCHContainerOperations>()) {
|
||||||
std::thread([&]() {
|
std::thread([&]() {
|
||||||
set_thread_name("comp-query");
|
set_thread_name("comp");
|
||||||
ccls::CompletionQueryMain(this);
|
ccls::CompletionMain(this);
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
std::thread([&]() {
|
std::thread([&]() {
|
||||||
@ -708,8 +708,8 @@ ClangCompleteManager::ClangCompleteManager(Project *project,
|
|||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
std::thread([&]() {
|
std::thread([&]() {
|
||||||
set_thread_name("diag-query");
|
set_thread_name("diag");
|
||||||
ccls::DiagnosticQueryMain(this);
|
ccls::DiagnosticMain(this);
|
||||||
})
|
})
|
||||||
.detach();
|
.detach();
|
||||||
}
|
}
|
||||||
|
@ -999,7 +999,6 @@ public:
|
|||||||
break;
|
break;
|
||||||
case Decl::EnumConstant:
|
case Decl::EnumConstant:
|
||||||
var->def.kind = lsSymbolKind::EnumMember;
|
var->def.kind = lsSymbolKind::EnumMember;
|
||||||
// TODO Pretty printer may print =
|
|
||||||
if (is_def && strchr(var->def.detailed_name, '=') == nullptr) {
|
if (is_def && strchr(var->def.detailed_name, '=') == nullptr) {
|
||||||
auto *ECD = cast<EnumConstantDecl>(D);
|
auto *ECD = cast<EnumConstantDecl>(D);
|
||||||
const auto &Val = ECD->getInitVal();
|
const auto &Val = ECD->getInitVal();
|
||||||
|
@ -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<In_CclsBase> {
|
|
||||||
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
|
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include "message_handler.h"
|
#include "message_handler.h"
|
||||||
#include "pipeline.hh"
|
#include "pipeline.hh"
|
||||||
using namespace ccls;
|
|
||||||
#include "query_utils.h"
|
#include "query_utils.h"
|
||||||
using namespace ccls;
|
using namespace ccls;
|
||||||
|
|
||||||
|
@ -8,19 +8,19 @@
|
|||||||
#include "query_utils.h"
|
#include "query_utils.h"
|
||||||
using namespace ccls;
|
using namespace ccls;
|
||||||
|
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
MethodType kMethodType = "textDocument/codeLens";
|
MethodType kMethodType = "textDocument/codeLens";
|
||||||
|
|
||||||
struct lsDocumentCodeLensParams {
|
|
||||||
lsTextDocumentIdentifier textDocument;
|
|
||||||
};
|
|
||||||
MAKE_REFLECT_STRUCT(lsDocumentCodeLensParams, textDocument);
|
|
||||||
|
|
||||||
using TCodeLens = lsCodeLens<lsCodeLensUserData, lsCodeLensCommandArguments>;
|
using TCodeLens = lsCodeLens<lsCodeLensUserData, lsCodeLensCommandArguments>;
|
||||||
struct In_TextDocumentCodeLens : public RequestInMessage {
|
struct In_TextDocumentCodeLens : public RequestInMessage {
|
||||||
MethodType GetMethodType() const override { return kMethodType; }
|
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);
|
MAKE_REFLECT_STRUCT(In_TextDocumentCodeLens, id, params);
|
||||||
REGISTER_IN_MESSAGE(In_TextDocumentCodeLens);
|
REGISTER_IN_MESSAGE(In_TextDocumentCodeLens);
|
||||||
|
|
||||||
@ -84,19 +84,17 @@ struct Handler_TextDocumentCodeLens
|
|||||||
: BaseMessageHandler<In_TextDocumentCodeLens> {
|
: BaseMessageHandler<In_TextDocumentCodeLens> {
|
||||||
MethodType GetMethodType() const override { return kMethodType; }
|
MethodType GetMethodType() const override { return kMethodType; }
|
||||||
void Run(In_TextDocumentCodeLens *request) override {
|
void Run(In_TextDocumentCodeLens *request) override {
|
||||||
|
auto ¶ms = request->params;
|
||||||
Out_TextDocumentCodeLens out;
|
Out_TextDocumentCodeLens out;
|
||||||
out.id = request->id;
|
out.id = request->id;
|
||||||
|
|
||||||
lsDocumentUri file_as_uri = request->params.textDocument.uri;
|
std::string path = params.textDocument.uri.GetPath();
|
||||||
std::string path = file_as_uri.GetPath();
|
|
||||||
|
|
||||||
clang_complete->NotifyView(path);
|
clang_complete->NotifyView(path);
|
||||||
|
|
||||||
QueryFile *file;
|
QueryFile *file;
|
||||||
if (!FindFileOrFail(db, project, request->id,
|
if (!FindFileOrFail(db, project, request->id,
|
||||||
request->params.textDocument.uri.GetPath(), &file)) {
|
params.textDocument.uri.GetPath(), &file))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
CommonCodeLensParams common;
|
CommonCodeLensParams common;
|
||||||
common.result = &out.result;
|
common.result = &out.result;
|
||||||
@ -104,8 +102,10 @@ struct Handler_TextDocumentCodeLens
|
|||||||
common.working_files = working_files;
|
common.working_files = working_files;
|
||||||
common.working_file = working_files->GetFileByFilename(file->def->path);
|
common.working_file = working_files->GetFileByFilename(file->def->path);
|
||||||
|
|
||||||
|
std::unordered_set<Range> seen;
|
||||||
for (auto [sym, refcnt] : file->outline2refcnt) {
|
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
|
// NOTE: We OffsetColumn so that the code lens always show up in a
|
||||||
// predictable order. Otherwise, the client may randomize it.
|
// predictable order. Otherwise, the client may randomize it.
|
||||||
Use use{{sym.range, sym.usr, sym.kind, sym.role}, file->id};
|
Use use{{sym.range, sym.usr, sym.kind, sym.role}, file->id};
|
||||||
|
Loading…
Reference in New Issue
Block a user