mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-31 09:50:26 +00:00
Add lexical parent to Func
This commit is contained in:
parent
9a6cbafa04
commit
e019968f51
@ -1594,8 +1594,8 @@ void OnIndexDeclaration(CXClientData client_data, const CXIdxDeclInfo* decl) {
|
||||
if (decl->isDefinition && !is_template_specialization) {
|
||||
// assert(!func->def.spell);
|
||||
// assert(!func->def.extent);
|
||||
func->def.spell = decl_spelling;
|
||||
func->def.extent = decl_extent;
|
||||
SetUse(db, &func->def.spell, decl_spelling, lex_parent, Role::Definition);
|
||||
SetUse(db, &func->def.extent, decl_extent, lex_parent, Role::None);
|
||||
} else {
|
||||
IndexFunc::Declaration declaration;
|
||||
declaration.spelling = decl_spelling;
|
||||
|
@ -260,8 +260,8 @@ struct FuncDefDefinitionData {
|
||||
std::string detailed_name;
|
||||
std::string hover;
|
||||
std::string comments;
|
||||
Maybe<typename F::Range> spell;
|
||||
Maybe<typename F::Range> extent;
|
||||
Maybe<Use> spell;
|
||||
Maybe<Use> extent;
|
||||
|
||||
// Method this method overrides.
|
||||
std::vector<typename F::FuncId> base;
|
||||
|
@ -175,7 +175,7 @@ struct TextDocumentCodeLensHandler
|
||||
// extent since that is better for outline. This tries to convert the
|
||||
// extent location to the spelling location.
|
||||
auto try_ensure_spelling = [&](SymbolRef sym) {
|
||||
Maybe<Reference> def = GetDefinitionSpellingOfSymbol(db, sym);
|
||||
Maybe<Use> def = GetDefinitionSpellingOfSymbol(db, sym);
|
||||
if (!def || db->GetFileId(*def) != db->GetFileId(sym) ||
|
||||
def->range.start.line != sym.range.start.line) {
|
||||
return sym;
|
||||
@ -213,7 +213,7 @@ struct TextDocumentCodeLensHandler
|
||||
|
||||
// "Base"
|
||||
if (func.def->base.size() == 1) {
|
||||
Maybe<Reference> base_loc =
|
||||
Maybe<Use> base_loc =
|
||||
GetDefinitionSpellingOfSymbol(db, func.def->base[0]);
|
||||
if (base_loc) {
|
||||
optional<lsLocation> ls_base =
|
||||
|
@ -74,7 +74,7 @@ struct TextDocumentDefinitionHandler
|
||||
// - start at spelling but end at extent for better mouse tooltip
|
||||
// - goto declaration while in definition of recursive type
|
||||
|
||||
Maybe<Reference> def_loc = GetDefinitionSpellingOfSymbol(db, sym);
|
||||
Maybe<Use> def_loc = GetDefinitionSpellingOfSymbol(db, sym);
|
||||
|
||||
// We use spelling start and extent end because this causes vscode to
|
||||
// highlight the entire definition when previewing / hoving with the
|
||||
|
16
src/query.cc
16
src/query.cc
@ -67,12 +67,8 @@ optional<QueryFunc::Def> ToQuery(const IdMap& id_map,
|
||||
result.hover = func.hover;
|
||||
result.comments = func.comments;
|
||||
result.file = id_map.primary_file;
|
||||
if (func.spell)
|
||||
result.spell =
|
||||
id_map.ToQuery(*func.spell, Role::Definition);
|
||||
if (func.extent)
|
||||
result.extent =
|
||||
id_map.ToQuery(*func.extent, Role::None);
|
||||
result.spell = id_map.ToQuery(func.spell);
|
||||
result.extent = id_map.ToQuery(func.extent);
|
||||
result.declaring_type = id_map.ToQuery(func.declaring_type);
|
||||
result.base = id_map.ToQuery(func.base);
|
||||
result.locals = id_map.ToQuery(func.locals);
|
||||
@ -274,11 +270,9 @@ QueryFile::DefUpdate BuildFileDefUpdate(const IdMap& id_map, const IndexFile& in
|
||||
for (const IndexFunc& func : indexed.funcs) {
|
||||
QueryFuncId id = id_map.ToQuery(func.id);
|
||||
if (func.def.spell.has_value())
|
||||
add_all_symbols(*func.def.spell, id, SymbolKind::Func,
|
||||
Role::Definition);
|
||||
add_all_symbols_use(*func.def.spell, id, SymbolKind::Func);
|
||||
if (func.def.extent.has_value())
|
||||
add_outline(*func.def.extent, id,
|
||||
SymbolKind::Func, Role::None);
|
||||
add_outline_use(*func.def.extent, id, SymbolKind::Func);
|
||||
for (const IndexFunc::Declaration& decl : func.declarations) {
|
||||
add_all_symbols(decl.spelling, id, SymbolKind::Func,
|
||||
Role::Declaration);
|
||||
@ -1023,7 +1017,7 @@ TEST_SUITE("query") {
|
||||
previous.Resolve(previous.ToTypeId(HashUsr("usr1")))
|
||||
->def.spell = Use(Range(Position(1, 0)), Id<void>(), SymbolKind::File, Role::None);
|
||||
previous.Resolve(previous.ToFuncId(HashUsr("usr2")))
|
||||
->def.spell = Range(Position(2, 0));
|
||||
->def.spell = Use(Range(Position(2, 0)), Id<void>(), SymbolKind::File, Role::None);
|
||||
previous.Resolve(previous.ToVarId(HashUsr("usr3")))
|
||||
->def.spell = Use(Range(Position(3, 0)), Id<void>(), SymbolKind::File, Role::None);
|
||||
|
||||
|
@ -18,21 +18,21 @@ int ComputeRangeSize(const Range& range) {
|
||||
|
||||
} // namespace
|
||||
|
||||
Maybe<Reference> GetDefinitionSpellingOfSymbol(QueryDatabase* db,
|
||||
QueryFuncId id) {
|
||||
Maybe<Use> GetDefinitionSpellingOfSymbol(QueryDatabase* db,
|
||||
QueryFuncId id) {
|
||||
QueryFunc& func = db->funcs[id.id];
|
||||
if (func.def)
|
||||
return func.def->spell;
|
||||
return nullopt;
|
||||
}
|
||||
|
||||
Maybe<Reference> GetDefinitionSpellingOfSymbol(QueryDatabase* db,
|
||||
SymbolRef sym) {
|
||||
Maybe<Use> GetDefinitionSpellingOfSymbol(QueryDatabase* db,
|
||||
SymbolRef sym) {
|
||||
switch (sym.kind) {
|
||||
case SymbolKind::Type: {
|
||||
QueryType& type = db->GetType(sym);
|
||||
if (type.def)
|
||||
return *type.def->spell;
|
||||
return type.def->spell;
|
||||
break;
|
||||
}
|
||||
case SymbolKind::Func: {
|
||||
@ -44,7 +44,7 @@ Maybe<Reference> GetDefinitionSpellingOfSymbol(QueryDatabase* db,
|
||||
case SymbolKind::Var: {
|
||||
QueryVar& var = db->GetVar(sym);
|
||||
if (var.def)
|
||||
return *var.def->spell;
|
||||
return var.def->spell;
|
||||
break;
|
||||
}
|
||||
case SymbolKind::File:
|
||||
|
@ -7,10 +7,10 @@
|
||||
|
||||
#include <optional.h>
|
||||
|
||||
Maybe<Reference> GetDefinitionSpellingOfSymbol(QueryDatabase* db,
|
||||
QueryFuncId id);
|
||||
Maybe<Reference> GetDefinitionSpellingOfSymbol(QueryDatabase* db,
|
||||
SymbolRef sym);
|
||||
Maybe<Use> GetDefinitionSpellingOfSymbol(QueryDatabase* db,
|
||||
QueryFuncId id);
|
||||
Maybe<Use> GetDefinitionSpellingOfSymbol(QueryDatabase* db,
|
||||
SymbolRef sym);
|
||||
Maybe<Use> GetDefinitionExtentOfSymbol(QueryDatabase* db, SymbolRef sym);
|
||||
Maybe<QueryFileId> GetDeclarationFileForSymbol(QueryDatabase* db,
|
||||
SymbolRef sym);
|
||||
|
Loading…
Reference in New Issue
Block a user