mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-31 09:50:26 +00:00
Keep a list of QueryType
This commit is contained in:
parent
702cdbe9bb
commit
e785d3f477
@ -124,10 +124,6 @@ struct SymbolRef : Reference {
|
||||
SymbolRef() = default;
|
||||
SymbolRef(Range range, Id<void> id, SymbolKind kind, Role role)
|
||||
: Reference{range, id, kind, role} {}
|
||||
SymbolRef(Reference ref) : Reference(ref) {}
|
||||
// FIXME Remove
|
||||
SymbolRef(SymbolIdx si)
|
||||
: Reference{Range(), si.id, si.kind, Role::None} {}
|
||||
};
|
||||
|
||||
// Represents an occurrence of a variable/type, |id,kind| refer to the lexical
|
||||
|
@ -117,7 +117,12 @@ void EmitSemanticHighlighting(QueryDatabase* db,
|
||||
// This switch statement also filters out symbols that are not highlighted.
|
||||
switch (sym.kind) {
|
||||
case SymbolKind::Func: {
|
||||
const QueryFunc::Def* def = db->GetFunc(sym).AnyDef();
|
||||
const QueryFunc::Def* def = nullptr;
|
||||
for (auto& i : db->GetFunc(sym).def) {
|
||||
def = &i;
|
||||
if (i.spell)
|
||||
break;
|
||||
}
|
||||
if (!def)
|
||||
continue; // applies to for loop
|
||||
// Don't highlight overloadable operators or implicit lambda ->
|
||||
@ -129,6 +134,7 @@ void EmitSemanticHighlighting(QueryDatabase* db,
|
||||
if (def->spell)
|
||||
parent_kind = def->spell->kind;
|
||||
kind = def->kind;
|
||||
storage = def->storage;
|
||||
detailed_name = short_name;
|
||||
|
||||
// Check whether the function name is actually there.
|
||||
@ -149,25 +155,27 @@ void EmitSemanticHighlighting(QueryDatabase* db,
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SymbolKind::Var: {
|
||||
if (const QueryVar::Def* def = db->GetVar(sym).AnyDef()) {
|
||||
if (def->spell)
|
||||
parent_kind = def->spell->kind;
|
||||
kind = def->kind;
|
||||
storage = def->storage;
|
||||
detailed_name = def->ShortName();
|
||||
case SymbolKind::Type:
|
||||
for (auto& def : db->GetType(sym).def) {
|
||||
kind = def.kind;
|
||||
detailed_name = def.detailed_name;
|
||||
if (def.spell) {
|
||||
parent_kind = def.spell->kind;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SymbolKind::Type: {
|
||||
if (const QueryType::Def* def = db->GetType(sym).AnyDef()) {
|
||||
if (def->spell)
|
||||
parent_kind = def->spell->kind;
|
||||
kind = def->kind;
|
||||
detailed_name = def->detailed_name;
|
||||
case SymbolKind::Var:
|
||||
for (auto& def : db->GetVar(sym).def) {
|
||||
kind = def.kind;
|
||||
storage = def.storage;
|
||||
detailed_name = def.detailed_name;
|
||||
if (def.spell) {
|
||||
parent_kind = def.spell->kind;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
continue; // applies to for loop
|
||||
}
|
||||
|
@ -82,6 +82,8 @@ struct TextDocumentReferencesHandler
|
||||
break;
|
||||
}
|
||||
|
||||
if ((int)out.result.size() >= config->xref.maxNum)
|
||||
out.result.resize(config->xref.maxNum);
|
||||
QueueManager::WriteStdout(IpcId::TextDocumentReferences, out);
|
||||
}
|
||||
};
|
||||
|
@ -879,12 +879,7 @@ void QueryDatabase::ImportOrUpdate(
|
||||
|
||||
assert(it->second.id >= 0 && it->second.id < types.size());
|
||||
QueryType& existing = types[it->second.id];
|
||||
// TODO Investigate why a list of Def makes finding-definition fail.
|
||||
//if (!TryReplaceDef(existing.def, std::move(def.value))) {
|
||||
//
|
||||
// Keep the existing definition if it is higher quality.
|
||||
if (!(existing.AnyDef() && existing.AnyDef()->spell &&
|
||||
!def.value.spell)) {
|
||||
if (!TryReplaceDef(existing.def, std::move(def.value))) {
|
||||
existing.def.push_front(std::move(def.value));
|
||||
UpdateSymbols(&existing.symbol_idx, SymbolKind::Type, it->second);
|
||||
}
|
||||
|
46
src/query.h
46
src/query.h
@ -133,7 +133,23 @@ MAKE_REFLECT_STRUCT(QueryFile::Def,
|
||||
inactive_regions,
|
||||
dependencies);
|
||||
|
||||
struct QueryType {
|
||||
template <typename Q, typename Def>
|
||||
struct QueryEntity {
|
||||
Def* AnyDef() {
|
||||
Def* ret = nullptr;
|
||||
for (auto& i : static_cast<Q*>(this)->def) {
|
||||
ret = &i;
|
||||
if (i.spell)
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
const Def* AnyDef() const {
|
||||
return const_cast<QueryEntity*>(this)->AnyDef();
|
||||
}
|
||||
};
|
||||
|
||||
struct QueryType : QueryEntity<QueryType, TypeDefDefinitionData<QueryFamily>> {
|
||||
using Def = TypeDefDefinitionData<QueryFamily>;
|
||||
using DefUpdate = WithUsr<Def>;
|
||||
using DeclarationsUpdate = MergeableUpdate<QueryTypeId, Use>;
|
||||
@ -150,17 +166,9 @@ struct QueryType {
|
||||
std::vector<Use> uses;
|
||||
|
||||
explicit QueryType(const Usr& usr) : usr(usr) {}
|
||||
const Def* AnyDef() const {
|
||||
if (def.empty()) return nullptr;
|
||||
return &def.front();
|
||||
}
|
||||
Def* AnyDef() {
|
||||
if (def.empty()) return nullptr;
|
||||
return &def.front();
|
||||
}
|
||||
};
|
||||
|
||||
struct QueryFunc {
|
||||
struct QueryFunc : QueryEntity<QueryFunc, FuncDefDefinitionData<QueryFamily>> {
|
||||
using Def = FuncDefDefinitionData<QueryFamily>;
|
||||
using DefUpdate = WithUsr<Def>;
|
||||
using DeclarationsUpdate = MergeableUpdate<QueryFuncId, Use>;
|
||||
@ -175,17 +183,9 @@ struct QueryFunc {
|
||||
std::vector<Use> uses;
|
||||
|
||||
explicit QueryFunc(const Usr& usr) : usr(usr) {}
|
||||
const Def* AnyDef() const {
|
||||
if (def.empty()) return nullptr;
|
||||
return &def.front();
|
||||
}
|
||||
Def* AnyDef() {
|
||||
if (def.empty()) return nullptr;
|
||||
return &def.front();
|
||||
}
|
||||
};
|
||||
|
||||
struct QueryVar {
|
||||
struct QueryVar : QueryEntity<QueryVar, VarDefDefinitionData<QueryFamily>> {
|
||||
using Def = VarDefDefinitionData<QueryFamily>;
|
||||
using DefUpdate = WithUsr<Def>;
|
||||
using DeclarationsUpdate = MergeableUpdate<QueryVarId, Use>;
|
||||
@ -198,14 +198,6 @@ struct QueryVar {
|
||||
std::vector<Use> uses;
|
||||
|
||||
explicit QueryVar(const Usr& usr) : usr(usr) {}
|
||||
const Def* AnyDef() const {
|
||||
if (def.empty()) return nullptr;
|
||||
return &def.front();
|
||||
}
|
||||
Def* AnyDef() {
|
||||
if (def.empty()) return nullptr;
|
||||
return &def.front();
|
||||
}
|
||||
};
|
||||
|
||||
struct IndexUpdate {
|
||||
|
Loading…
Reference in New Issue
Block a user