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