mirror of
https://github.com/MaskRay/ccls.git
synced 2025-03-30 13:32:13 +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() = default;
|
||||||
SymbolRef(Range range, Id<void> id, SymbolKind kind, Role role)
|
SymbolRef(Range range, Id<void> id, SymbolKind kind, Role role)
|
||||||
: Reference{range, id, kind, 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
|
// 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.
|
// This switch statement also filters out symbols that are not highlighted.
|
||||||
switch (sym.kind) {
|
switch (sym.kind) {
|
||||||
case SymbolKind::Func: {
|
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)
|
if (!def)
|
||||||
continue; // applies to for loop
|
continue; // applies to for loop
|
||||||
// Don't highlight overloadable operators or implicit lambda ->
|
// Don't highlight overloadable operators or implicit lambda ->
|
||||||
@ -129,6 +134,7 @@ void EmitSemanticHighlighting(QueryDatabase* db,
|
|||||||
if (def->spell)
|
if (def->spell)
|
||||||
parent_kind = def->spell->kind;
|
parent_kind = def->spell->kind;
|
||||||
kind = def->kind;
|
kind = def->kind;
|
||||||
|
storage = def->storage;
|
||||||
detailed_name = short_name;
|
detailed_name = short_name;
|
||||||
|
|
||||||
// Check whether the function name is actually there.
|
// Check whether the function name is actually there.
|
||||||
@ -149,25 +155,27 @@ void EmitSemanticHighlighting(QueryDatabase* db,
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SymbolKind::Var: {
|
case SymbolKind::Type:
|
||||||
if (const QueryVar::Def* def = db->GetVar(sym).AnyDef()) {
|
for (auto& def : db->GetType(sym).def) {
|
||||||
if (def->spell)
|
kind = def.kind;
|
||||||
parent_kind = def->spell->kind;
|
detailed_name = def.detailed_name;
|
||||||
kind = def->kind;
|
if (def.spell) {
|
||||||
storage = def->storage;
|
parent_kind = def.spell->kind;
|
||||||
detailed_name = def->ShortName();
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
case SymbolKind::Var:
|
||||||
case SymbolKind::Type: {
|
for (auto& def : db->GetVar(sym).def) {
|
||||||
if (const QueryType::Def* def = db->GetType(sym).AnyDef()) {
|
kind = def.kind;
|
||||||
if (def->spell)
|
storage = def.storage;
|
||||||
parent_kind = def->spell->kind;
|
detailed_name = def.detailed_name;
|
||||||
kind = def->kind;
|
if (def.spell) {
|
||||||
detailed_name = def->detailed_name;
|
parent_kind = def.spell->kind;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
continue; // applies to for loop
|
continue; // applies to for loop
|
||||||
}
|
}
|
||||||
|
@ -82,6 +82,8 @@ struct TextDocumentReferencesHandler
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((int)out.result.size() >= config->xref.maxNum)
|
||||||
|
out.result.resize(config->xref.maxNum);
|
||||||
QueueManager::WriteStdout(IpcId::TextDocumentReferences, out);
|
QueueManager::WriteStdout(IpcId::TextDocumentReferences, out);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -879,12 +879,7 @@ void QueryDatabase::ImportOrUpdate(
|
|||||||
|
|
||||||
assert(it->second.id >= 0 && it->second.id < types.size());
|
assert(it->second.id >= 0 && it->second.id < types.size());
|
||||||
QueryType& existing = types[it->second.id];
|
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))) {
|
||||||
//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)) {
|
|
||||||
existing.def.push_front(std::move(def.value));
|
existing.def.push_front(std::move(def.value));
|
||||||
UpdateSymbols(&existing.symbol_idx, SymbolKind::Type, it->second);
|
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,
|
inactive_regions,
|
||||||
dependencies);
|
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 Def = TypeDefDefinitionData<QueryFamily>;
|
||||||
using DefUpdate = WithUsr<Def>;
|
using DefUpdate = WithUsr<Def>;
|
||||||
using DeclarationsUpdate = MergeableUpdate<QueryTypeId, Use>;
|
using DeclarationsUpdate = MergeableUpdate<QueryTypeId, Use>;
|
||||||
@ -150,17 +166,9 @@ struct QueryType {
|
|||||||
std::vector<Use> uses;
|
std::vector<Use> uses;
|
||||||
|
|
||||||
explicit QueryType(const Usr& usr) : usr(usr) {}
|
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 Def = FuncDefDefinitionData<QueryFamily>;
|
||||||
using DefUpdate = WithUsr<Def>;
|
using DefUpdate = WithUsr<Def>;
|
||||||
using DeclarationsUpdate = MergeableUpdate<QueryFuncId, Use>;
|
using DeclarationsUpdate = MergeableUpdate<QueryFuncId, Use>;
|
||||||
@ -175,17 +183,9 @@ struct QueryFunc {
|
|||||||
std::vector<Use> uses;
|
std::vector<Use> uses;
|
||||||
|
|
||||||
explicit QueryFunc(const Usr& usr) : usr(usr) {}
|
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 Def = VarDefDefinitionData<QueryFamily>;
|
||||||
using DefUpdate = WithUsr<Def>;
|
using DefUpdate = WithUsr<Def>;
|
||||||
using DeclarationsUpdate = MergeableUpdate<QueryVarId, Use>;
|
using DeclarationsUpdate = MergeableUpdate<QueryVarId, Use>;
|
||||||
@ -198,14 +198,6 @@ struct QueryVar {
|
|||||||
std::vector<Use> uses;
|
std::vector<Use> uses;
|
||||||
|
|
||||||
explicit QueryVar(const Usr& usr) : usr(usr) {}
|
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 {
|
struct IndexUpdate {
|
||||||
|
Loading…
Reference in New Issue
Block a user