mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-22 07:35:08 +00:00
$cquery/base for virtual void f() = 0
This commit is contained in:
parent
1342522f2a
commit
e7c90b62b5
@ -33,7 +33,7 @@ struct CqueryBaseHandler : BaseMessageHandler<Ipc_CqueryBase> {
|
||||
return (a.role & SymbolRole::Definition) >
|
||||
(b.role & SymbolRole::Definition);
|
||||
});
|
||||
for (const SymbolRef& sym : syms) {
|
||||
for (SymbolRef sym : syms) {
|
||||
if (sym.kind == SymbolKind::Type) {
|
||||
QueryType& type = db->GetType(sym);
|
||||
if (type.def)
|
||||
@ -43,8 +43,8 @@ struct CqueryBaseHandler : BaseMessageHandler<Ipc_CqueryBase> {
|
||||
} else if (sym.kind == SymbolKind::Func) {
|
||||
QueryFunc& func = db->GetFunc(sym);
|
||||
if (func.def)
|
||||
out.result =
|
||||
GetLsLocations(db, working_files, ToReference(db, func.def->base));
|
||||
out.result = GetLsLocations(db, working_files,
|
||||
ToReference(db, func.def->base));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -23,10 +23,10 @@ struct CqueryCallersHandler : BaseMessageHandler<Ipc_CqueryCallers> {
|
||||
|
||||
Out_LocationList out;
|
||||
out.id = request->id;
|
||||
for (const SymbolRef& sym :
|
||||
for (SymbolRef sym :
|
||||
FindSymbolsAtLocation(working_file, file, request->params.position)) {
|
||||
if (sym.kind == SymbolKind::Func) {
|
||||
QueryFunc& func = db->funcs[sym.Idx()];
|
||||
QueryFunc& func = db->GetFunc(sym);
|
||||
std::vector<Reference> uses = ToReference(db, func.callers);
|
||||
for (QueryFuncRef func_ref : GetCallersForAllBaseFunctions(db, func))
|
||||
uses.push_back(func_ref);
|
||||
|
@ -23,14 +23,14 @@ struct CqueryVarsHandler : BaseMessageHandler<Ipc_CqueryVars> {
|
||||
|
||||
Out_LocationList out;
|
||||
out.id = request->id;
|
||||
for (const SymbolRef& ref :
|
||||
for (SymbolRef sym :
|
||||
FindSymbolsAtLocation(working_file, file, request->params.position)) {
|
||||
RawId idx = ref.Idx();
|
||||
switch (ref.kind) {
|
||||
RawId idx = sym.Idx();
|
||||
switch (sym.kind) {
|
||||
default:
|
||||
break;
|
||||
case SymbolKind::Var: {
|
||||
QueryVar& var = db->vars[idx];
|
||||
QueryVar& var = db->GetVar(sym);
|
||||
if (!var.def || !var.def->variable_type)
|
||||
continue;
|
||||
idx = var.def->variable_type->id;
|
||||
|
@ -65,7 +65,7 @@ struct TextDocumentDefinitionHandler
|
||||
int target_line = request->params.position.line;
|
||||
int target_column = request->params.position.character;
|
||||
|
||||
for (const SymbolRef& sym :
|
||||
for (SymbolRef sym :
|
||||
FindSymbolsAtLocation(working_file, file, request->params.position)) {
|
||||
// Found symbol. Return definition.
|
||||
|
||||
|
@ -35,12 +35,12 @@ struct TextDocumentDocumentHighlightHandler
|
||||
Out_TextDocumentDocumentHighlight out;
|
||||
out.id = request->id;
|
||||
|
||||
for (const SymbolRef& sym :
|
||||
for (SymbolRef sym :
|
||||
FindSymbolsAtLocation(working_file, file, request->params.position)) {
|
||||
// Found symbol. Return references to highlight.
|
||||
std::vector<Reference> uses = GetUsesOfSymbol(db, sym, true);
|
||||
out.result.reserve(uses.size());
|
||||
for (const Reference& use : uses) {
|
||||
for (Reference use : uses) {
|
||||
if (db->GetFileId(use) != file_id)
|
||||
continue;
|
||||
|
||||
|
@ -87,7 +87,7 @@ struct TextDocumentHoverHandler : BaseMessageHandler<Ipc_TextDocumentHover> {
|
||||
Out_TextDocumentHover out;
|
||||
out.id = request->id;
|
||||
|
||||
for (const SymbolRef& sym :
|
||||
for (SymbolRef sym :
|
||||
FindSymbolsAtLocation(working_file, file, request->params.position)) {
|
||||
// Found symbol. Return hover.
|
||||
optional<lsRange> ls_range = GetLsRange(
|
||||
|
@ -95,7 +95,7 @@ struct TextDocumentRenameHandler : BaseMessageHandler<Ipc_TextDocumentRename> {
|
||||
Out_TextDocumentRename out;
|
||||
out.id = request->id;
|
||||
|
||||
for (const SymbolRef& sym :
|
||||
for (SymbolRef sym :
|
||||
FindSymbolsAtLocation(working_file, file, request->params.position)) {
|
||||
// Found symbol. Return references to rename.
|
||||
out.result = BuildWorkspaceEdit(db, working_files,
|
||||
|
@ -18,14 +18,6 @@ int ComputeRangeSize(const Range& range) {
|
||||
|
||||
} // namespace
|
||||
|
||||
optional<Reference> GetDefinitionSpellingOfSymbol(QueryDatabase* db,
|
||||
const QueryTypeId& id) {
|
||||
QueryType& type = db->types[id.id];
|
||||
if (type.def)
|
||||
return type.def->definition_spelling;
|
||||
return nullopt;
|
||||
}
|
||||
|
||||
optional<Reference> GetDefinitionSpellingOfSymbol(QueryDatabase* db,
|
||||
const QueryFuncId& id) {
|
||||
QueryFunc& func = db->funcs[id.id];
|
||||
@ -34,14 +26,6 @@ optional<Reference> GetDefinitionSpellingOfSymbol(QueryDatabase* db,
|
||||
return nullopt;
|
||||
}
|
||||
|
||||
optional<Reference> GetDefinitionSpellingOfSymbol(QueryDatabase* db,
|
||||
const QueryVarId& id) {
|
||||
QueryVar& var = db->vars[id.id];
|
||||
if (var.def)
|
||||
return var.def->definition_spelling;
|
||||
return nullopt;
|
||||
}
|
||||
|
||||
optional<Reference> GetDefinitionSpellingOfSymbol(QueryDatabase* db,
|
||||
SymbolRef sym) {
|
||||
switch (sym.kind) {
|
||||
@ -145,6 +129,46 @@ std::vector<Reference> ToReference(QueryDatabase* db,
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<Reference> ToReference(QueryDatabase* db,
|
||||
const std::vector<QueryFuncId>& ids) {
|
||||
std::vector<Reference> ret;
|
||||
ret.reserve(ids.size());
|
||||
for (auto id : ids) {
|
||||
QueryFunc& func = db->funcs[id.id];
|
||||
if (func.def && func.def->definition_spelling)
|
||||
ret.push_back(*func.def->definition_spelling);
|
||||
else if (func.declarations.size())
|
||||
ret.push_back(func.declarations[0]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<Reference> ToReference(QueryDatabase* db,
|
||||
const std::vector<QueryTypeId>& ids) {
|
||||
std::vector<Reference> ret;
|
||||
ret.reserve(ids.size());
|
||||
for (auto id : ids) {
|
||||
QueryType& type = db->types[id.id];
|
||||
if (type.def && type.def->definition_spelling)
|
||||
ret.push_back(*type.def->definition_spelling);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<Reference> ToReference(QueryDatabase* db,
|
||||
const std::vector<QueryVarId>& ids) {
|
||||
std::vector<Reference> ret;
|
||||
ret.reserve(ids.size());
|
||||
for (auto id : ids) {
|
||||
QueryVar& var = db->vars[id.id];
|
||||
if (var.def && var.def->definition_spelling)
|
||||
ret.push_back(*var.def->definition_spelling);
|
||||
else if (var.declarations.size())
|
||||
ret.push_back(var.declarations[0]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<Reference> GetUsesOfSymbol(QueryDatabase* db,
|
||||
SymbolRef sym,
|
||||
bool include_decl) {
|
||||
|
@ -7,12 +7,8 @@
|
||||
|
||||
#include <optional.h>
|
||||
|
||||
optional<Reference> GetDefinitionSpellingOfSymbol(QueryDatabase* db,
|
||||
const QueryTypeId& id);
|
||||
optional<Reference> GetDefinitionSpellingOfSymbol(QueryDatabase* db,
|
||||
const QueryFuncId& id);
|
||||
optional<Reference> GetDefinitionSpellingOfSymbol(QueryDatabase* db,
|
||||
const QueryVarId& id);
|
||||
optional<Reference> GetDefinitionSpellingOfSymbol(QueryDatabase* db,
|
||||
SymbolRef sym);
|
||||
optional<Reference> GetDefinitionExtentOfSymbol(QueryDatabase* db,
|
||||
@ -22,19 +18,12 @@ optional<QueryFileId> GetDeclarationFileForSymbol(QueryDatabase* db,
|
||||
|
||||
std::vector<Reference> ToReference(QueryDatabase* db,
|
||||
const std::vector<QueryFuncRef>& refs);
|
||||
|
||||
template <typename Q>
|
||||
std::vector<Reference> ToReference(QueryDatabase* db,
|
||||
const std::vector<Id<Q>>& ids) {
|
||||
std::vector<Reference> ret;
|
||||
ret.reserve(ids.size());
|
||||
for (auto id : ids) {
|
||||
optional<Reference> loc = GetDefinitionSpellingOfSymbol(db, id);
|
||||
if (loc)
|
||||
ret.push_back(*loc);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
const std::vector<QueryFuncId>& ids);
|
||||
std::vector<Reference> ToReference(QueryDatabase* db,
|
||||
const std::vector<QueryTypeId>& ids);
|
||||
std::vector<Reference> ToReference(QueryDatabase* db,
|
||||
const std::vector<QueryVarId>& ids);
|
||||
|
||||
std::vector<Reference> GetUsesOfSymbol(QueryDatabase* db,
|
||||
SymbolRef sym,
|
||||
|
Loading…
Reference in New Issue
Block a user