mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-29 11:01:57 +00:00
Deduplicate Query*; add local variables to outline but not in documentSymbol
This commit is contained in:
parent
01fe19f280
commit
892f2ebfc7
@ -42,6 +42,16 @@ struct TextDocumentDocumentSymbolHandler
|
|||||||
GetSymbolInfo(db, working_files, sym, true /*use_short_name*/);
|
GetSymbolInfo(db, working_files, sym, true /*use_short_name*/);
|
||||||
if (!info)
|
if (!info)
|
||||||
continue;
|
continue;
|
||||||
|
if (sym.kind == SymbolKind::Var) {
|
||||||
|
QueryVar& var = db->GetVar(sym);
|
||||||
|
auto* def = var.AnyDef();
|
||||||
|
if (!def || !def->spell) continue;
|
||||||
|
// Ignore local variables.
|
||||||
|
if (def->spell->kind == SymbolKind::Func &&
|
||||||
|
def->storage != StorageClass::Static &&
|
||||||
|
def->storage != StorageClass::Extern)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (optional<lsLocation> location = GetLsLocation(
|
if (optional<lsLocation> location = GetLsLocation(
|
||||||
db, working_files,
|
db, working_files,
|
||||||
|
15
src/query.cc
15
src/query.cc
@ -278,17 +278,13 @@ QueryFile::DefUpdate BuildFileDefUpdate(const IdMap& id_map,
|
|||||||
}
|
}
|
||||||
for (const IndexVar& var : indexed.vars) {
|
for (const IndexVar& var : indexed.vars) {
|
||||||
QueryVarId id = id_map.ToQuery(var.id);
|
QueryVarId id = id_map.ToQuery(var.id);
|
||||||
if (var.def.spell) {
|
if (var.def.spell)
|
||||||
add_all_symbols(*var.def.spell, id, SymbolKind::Var);
|
add_all_symbols(*var.def.spell, id, SymbolKind::Var);
|
||||||
if (var.def.extent && (var.def.spell->kind != SymbolKind::Func ||
|
if (var.def.extent)
|
||||||
var.def.storage == StorageClass::Static))
|
add_outline(*var.def.extent, id, SymbolKind::Var);
|
||||||
add_outline(*var.def.extent, id, SymbolKind::Var);
|
|
||||||
}
|
|
||||||
for (Use decl : var.declarations) {
|
for (Use decl : var.declarations) {
|
||||||
add_all_symbols(decl, id, SymbolKind::Var);
|
add_all_symbols(decl, id, SymbolKind::Var);
|
||||||
if (decl.kind != SymbolKind::Func ||
|
add_outline(decl, id, SymbolKind::Var);
|
||||||
var.def.storage == StorageClass::Static)
|
|
||||||
add_outline(decl, id, SymbolKind::Var);
|
|
||||||
}
|
}
|
||||||
for (Use use : var.uses)
|
for (Use use : var.uses)
|
||||||
add_all_symbols(use, id, SymbolKind::Var);
|
add_all_symbols(use, id, SymbolKind::Var);
|
||||||
@ -425,9 +421,6 @@ QueryTypeId IdMap::ToQuery(IndexTypeId id) const {
|
|||||||
return QueryTypeId(cached_type_ids_.find(id)->second);
|
return QueryTypeId(cached_type_ids_.find(id)->second);
|
||||||
}
|
}
|
||||||
QueryFuncId IdMap::ToQuery(IndexFuncId id) const {
|
QueryFuncId IdMap::ToQuery(IndexFuncId id) const {
|
||||||
// FIXME id shouldn't be invalid
|
|
||||||
if (id == IndexFuncId())
|
|
||||||
return QueryFuncId();
|
|
||||||
assert(cached_func_ids_.find(id) != cached_func_ids_.end());
|
assert(cached_func_ids_.find(id) != cached_func_ids_.end());
|
||||||
return QueryFuncId(cached_func_ids_.find(id)->second);
|
return QueryFuncId(cached_func_ids_.find(id)->second);
|
||||||
}
|
}
|
||||||
|
19
src/query.h
19
src/query.h
@ -134,8 +134,12 @@ MAKE_REFLECT_STRUCT(QueryFile::Def,
|
|||||||
inactive_regions,
|
inactive_regions,
|
||||||
dependencies);
|
dependencies);
|
||||||
|
|
||||||
template <typename Q, typename Def>
|
template <typename Q, typename QDef>
|
||||||
struct QueryEntity {
|
struct QueryEntity {
|
||||||
|
using Def = QDef;
|
||||||
|
using DefUpdate = WithUsr<Def>;
|
||||||
|
using DeclarationsUpdate = MergeableUpdate<Id<Q>, Use>;
|
||||||
|
using UsesUpdate = MergeableUpdate<Id<Q>, Use>;
|
||||||
Def* AnyDef() {
|
Def* AnyDef() {
|
||||||
Def* ret = nullptr;
|
Def* ret = nullptr;
|
||||||
for (auto& i : static_cast<Q*>(this)->def) {
|
for (auto& i : static_cast<Q*>(this)->def) {
|
||||||
@ -149,12 +153,8 @@ struct QueryEntity {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct QueryType : QueryEntity<QueryType, TypeDefDefinitionData<QueryFamily>> {
|
struct QueryType : QueryEntity<QueryType, TypeDefDefinitionData<QueryFamily>> {
|
||||||
using Def = TypeDefDefinitionData<QueryFamily>;
|
|
||||||
using DefUpdate = WithUsr<Def>;
|
|
||||||
using DeclarationsUpdate = MergeableUpdate<QueryTypeId, Use>;
|
|
||||||
using DerivedUpdate = MergeableUpdate<QueryTypeId, QueryTypeId>;
|
using DerivedUpdate = MergeableUpdate<QueryTypeId, QueryTypeId>;
|
||||||
using InstancesUpdate = MergeableUpdate<QueryTypeId, QueryVarId>;
|
using InstancesUpdate = MergeableUpdate<QueryTypeId, QueryVarId>;
|
||||||
using UsesUpdate = MergeableUpdate<QueryTypeId, Use>;
|
|
||||||
|
|
||||||
Usr usr;
|
Usr usr;
|
||||||
Maybe<Id<void>> symbol_idx;
|
Maybe<Id<void>> symbol_idx;
|
||||||
@ -168,11 +168,7 @@ struct QueryType : QueryEntity<QueryType, TypeDefDefinitionData<QueryFamily>> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct QueryFunc : QueryEntity<QueryFunc, FuncDefDefinitionData<QueryFamily>> {
|
struct QueryFunc : QueryEntity<QueryFunc, FuncDefDefinitionData<QueryFamily>> {
|
||||||
using Def = FuncDefDefinitionData<QueryFamily>;
|
|
||||||
using DefUpdate = WithUsr<Def>;
|
|
||||||
using DeclarationsUpdate = MergeableUpdate<QueryFuncId, Use>;
|
|
||||||
using DerivedUpdate = MergeableUpdate<QueryFuncId, QueryFuncId>;
|
using DerivedUpdate = MergeableUpdate<QueryFuncId, QueryFuncId>;
|
||||||
using UsesUpdate = MergeableUpdate<QueryFuncId, Use>;
|
|
||||||
|
|
||||||
Usr usr;
|
Usr usr;
|
||||||
Maybe<Id<void>> symbol_idx;
|
Maybe<Id<void>> symbol_idx;
|
||||||
@ -185,11 +181,6 @@ struct QueryFunc : QueryEntity<QueryFunc, FuncDefDefinitionData<QueryFamily>> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct QueryVar : QueryEntity<QueryVar, VarDefDefinitionData<QueryFamily>> {
|
struct QueryVar : QueryEntity<QueryVar, VarDefDefinitionData<QueryFamily>> {
|
||||||
using Def = VarDefDefinitionData<QueryFamily>;
|
|
||||||
using DefUpdate = WithUsr<Def>;
|
|
||||||
using DeclarationsUpdate = MergeableUpdate<QueryVarId, Use>;
|
|
||||||
using UsesUpdate = MergeableUpdate<QueryVarId, Use>;
|
|
||||||
|
|
||||||
Usr usr;
|
Usr usr;
|
||||||
Maybe<Id<void>> symbol_idx;
|
Maybe<Id<void>> symbol_idx;
|
||||||
std::forward_list<Def> def;
|
std::forward_list<Def> def;
|
||||||
|
Loading…
Reference in New Issue
Block a user