mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-19 03:55:49 +00:00
Remove QueryLocation and clean up
This commit is contained in:
parent
50cf05763b
commit
c28426bbb4
@ -117,7 +117,7 @@ void EmitSemanticHighlighting(QueryDatabase* db,
|
||||
// This switch statement also filters out symbols that are not highlighted.
|
||||
switch (sym.kind) {
|
||||
case SymbolKind::Func: {
|
||||
QueryFunc& func = sym.Func(db);
|
||||
QueryFunc& func = db->GetFunc(sym);
|
||||
if (!func.def)
|
||||
continue; // applies to for loop
|
||||
// Don't highlight overloadable operators or implicit lambda ->
|
||||
@ -148,7 +148,7 @@ void EmitSemanticHighlighting(QueryDatabase* db,
|
||||
break;
|
||||
}
|
||||
case SymbolKind::Var: {
|
||||
QueryVar& var = sym.Var(db);
|
||||
QueryVar& var = db->GetVar(sym);
|
||||
if (!var.def)
|
||||
continue; // applies to for loop
|
||||
parent_kind = var.def->parent_kind;
|
||||
@ -158,7 +158,7 @@ void EmitSemanticHighlighting(QueryDatabase* db,
|
||||
break;
|
||||
}
|
||||
case SymbolKind::Type: {
|
||||
QueryType& type = sym.Type(db);
|
||||
QueryType& type = db->GetType(sym);
|
||||
if (!type.def)
|
||||
continue; // applies to for loop
|
||||
kind = type.def->kind;
|
||||
|
@ -35,13 +35,13 @@ struct CqueryBaseHandler : BaseMessageHandler<Ipc_CqueryBase> {
|
||||
});
|
||||
for (const SymbolRef& sym : syms) {
|
||||
if (sym.kind == SymbolKind::Type) {
|
||||
QueryType& type = sym.Type(db);
|
||||
QueryType& type = db->GetType(sym);
|
||||
if (type.def)
|
||||
out.result = GetLsLocations(db, working_files,
|
||||
ToReference(db, type.def->parents));
|
||||
break;
|
||||
} else if (sym.kind == SymbolKind::Func) {
|
||||
QueryFunc& func = sym.Func(db);
|
||||
QueryFunc& func = db->GetFunc(sym);
|
||||
if (func.def)
|
||||
out.result =
|
||||
GetLsLocations(db, working_files, ToReference(db, func.def->base));
|
||||
|
@ -79,7 +79,6 @@ std::vector<Out_CqueryCallTree::CallEntry> BuildExpandCallTree(
|
||||
return {};
|
||||
|
||||
std::vector<Out_CqueryCallTree::CallEntry> result;
|
||||
std::unordered_set<QueryLocation> seen_locations;
|
||||
|
||||
auto handle_caller = [&](QueryFuncRef caller,
|
||||
Out_CqueryCallTree::CallType call_type) {
|
||||
|
@ -35,12 +35,12 @@ struct CqueryDerivedHandler : BaseMessageHandler<Ipc_CqueryDerived> {
|
||||
});
|
||||
for (const SymbolRef& sym : syms) {
|
||||
if (sym.kind == SymbolKind::Type) {
|
||||
QueryType& type = sym.Type(db);
|
||||
QueryType& type = db->GetType(sym);
|
||||
out.result =
|
||||
GetLsLocations(db, working_files, ToReference(db, type.derived));
|
||||
break;
|
||||
} else if (sym.kind == SymbolKind::Func) {
|
||||
QueryFunc& func = sym.Func(db);
|
||||
QueryFunc& func = db->GetFunc(sym);
|
||||
out.result =
|
||||
GetLsLocations(db, working_files, ToReference(db, func.derived));
|
||||
break;
|
||||
|
@ -99,7 +99,7 @@ struct CqueryMemberHierarchyInitialHandler
|
||||
break;
|
||||
}
|
||||
if (sym.kind == SymbolKind::Var) {
|
||||
QueryVar& var = sym.Var(db);
|
||||
QueryVar& var = db->GetVar(sym);
|
||||
if (var.def && var.def->variable_type)
|
||||
out.result = BuildInitial(db, working_files, *var.def->variable_type);
|
||||
break;
|
||||
|
@ -168,7 +168,7 @@ struct CqueryTypeHierarchyTreeHandler
|
||||
for (const SymbolRef& sym :
|
||||
FindSymbolsAtLocation(working_file, file, request->params.position)) {
|
||||
if (sym.kind == SymbolKind::Type) {
|
||||
QueryType& type = sym.Type(db);
|
||||
QueryType& type = db->GetType(sym);
|
||||
if (type.def)
|
||||
out.result =
|
||||
BuildInheritanceHierarchyForType(db, working_files, type);
|
||||
|
@ -69,22 +69,22 @@ optional<QueryFileId> GetImplementationFile(QueryDatabase* db,
|
||||
for (SymbolRef sym : file->def->outline) {
|
||||
switch (sym.kind) {
|
||||
case SymbolKind::Func: {
|
||||
QueryFunc& func = sym.Func(db);
|
||||
QueryFunc& func = db->GetFunc(sym);
|
||||
// Note: we ignore the definition if it is in the same file (ie,
|
||||
// possibly a header).
|
||||
if (func.def && func.def->definition_extent) {
|
||||
QueryFileId t = GetFileId(db, *func.def->definition_extent);
|
||||
QueryFileId t = db->GetFileId(*func.def->definition_extent);
|
||||
if (t != file_id)
|
||||
return t;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SymbolKind::Var: {
|
||||
QueryVar& var = sym.Var(db);
|
||||
QueryVar& var = db->GetVar(sym);
|
||||
// Note: we ignore the definition if it is in the same file (ie,
|
||||
// possibly a header).
|
||||
if (var.def && var.def->definition_extent) {
|
||||
QueryFileId t = GetFileId(db, *var.def->definition_extent);
|
||||
QueryFileId t = db->GetFileId(*var.def->definition_extent);
|
||||
if (t != file_id)
|
||||
return t;
|
||||
}
|
||||
@ -151,7 +151,7 @@ optional<lsTextEdit> BuildAutoImplementForFunction(QueryDatabase* db,
|
||||
QueryFunc& func) {
|
||||
assert(func.def);
|
||||
for (const Reference& decl : func.declarations) {
|
||||
if (GetFileId(db, decl) != decl_file_id)
|
||||
if (db->GetFileId(decl) != decl_file_id)
|
||||
continue;
|
||||
|
||||
optional<lsRange> ls_decl = GetLsRange(working_file, decl.range);
|
||||
@ -200,12 +200,12 @@ optional<lsTextEdit> BuildAutoImplementForFunction(QueryDatabase* db,
|
||||
for (SymbolRef sym : file.def->outline) {
|
||||
switch (sym.kind) {
|
||||
case SymbolKind::Func: {
|
||||
QueryFunc& sym_func = sym.Func(db);
|
||||
QueryFunc& sym_func = db->GetFunc(sym);
|
||||
if (!sym_func.def || !sym_func.def->definition_extent)
|
||||
break;
|
||||
|
||||
for (const Reference& func_decl : sym_func.declarations) {
|
||||
if (GetFileId(db, func_decl) == decl_file_id) {
|
||||
if (db->GetFileId(func_decl) == decl_file_id) {
|
||||
int dist = func_decl.range.start.line - decl.range.start.line;
|
||||
if (abs(dist) < abs(best_dist)) {
|
||||
optional<lsLocation> def_loc = GetLsLocation(
|
||||
@ -346,7 +346,7 @@ struct TextDocumentCodeActionHandler
|
||||
for (SymbolRef sym : syms) {
|
||||
switch (sym.kind) {
|
||||
case SymbolKind::Type: {
|
||||
QueryType& type = sym.Type(db);
|
||||
QueryType& type = db->GetType(sym);
|
||||
if (!type.def)
|
||||
break;
|
||||
|
||||
@ -397,7 +397,7 @@ struct TextDocumentCodeActionHandler
|
||||
}
|
||||
|
||||
case SymbolKind::Func: {
|
||||
QueryFunc& func = sym.Func(db);
|
||||
QueryFunc& func = db->GetFunc(sym);
|
||||
if (!func.def || func.def->definition_extent)
|
||||
break;
|
||||
|
||||
|
@ -76,11 +76,15 @@ struct CommonCodeLensParams {
|
||||
WorkingFile* working_file;
|
||||
};
|
||||
|
||||
// FIXME Reference
|
||||
SymbolRef OffsetStartColumn(SymbolRef sym, int16_t offset) {
|
||||
sym.range.start.column += offset;
|
||||
return sym;
|
||||
}
|
||||
|
||||
void AddCodeLens(const char* singular,
|
||||
const char* plural,
|
||||
CommonCodeLensParams* common,
|
||||
QueryLocation loc,
|
||||
SymbolRef loc,
|
||||
const std::vector<Reference>& uses,
|
||||
bool force_display) {
|
||||
TCodeLens code_lens;
|
||||
@ -90,7 +94,8 @@ void AddCodeLens(const char* singular,
|
||||
code_lens.range = *range;
|
||||
code_lens.command = lsCommand<lsCodeLensCommandArguments>();
|
||||
code_lens.command->command = "cquery.showReferences";
|
||||
code_lens.command->arguments.uri = GetLsDocumentUri(common->db, loc.FileId());
|
||||
code_lens.command->arguments.uri =
|
||||
GetLsDocumentUri(common->db, common->db->GetFileId(loc));
|
||||
code_lens.command->arguments.position = code_lens.range.start;
|
||||
|
||||
// Add unique uses.
|
||||
@ -146,22 +151,21 @@ struct TextDocumentCodeLensHandler
|
||||
|
||||
switch (sym.kind) {
|
||||
case SymbolKind::Type: {
|
||||
QueryType& type = sym.Type(db);
|
||||
QueryType& type = db->GetType(sym);
|
||||
if (!type.def)
|
||||
continue;
|
||||
if (type.def->kind == ClangSymbolKind::Namespace)
|
||||
continue;
|
||||
AddCodeLens("ref", "refs", &common, sym.OffsetStartColumn(db, 0),
|
||||
AddCodeLens("ref", "refs", &common, OffsetStartColumn(sym, 0),
|
||||
type.uses, true /*force_display*/);
|
||||
AddCodeLens("derived", "derived", &common,
|
||||
sym.OffsetStartColumn(db, 1),
|
||||
AddCodeLens("derived", "derived", &common, OffsetStartColumn(sym, 1),
|
||||
ToReference(db, type.derived), false /*force_display*/);
|
||||
AddCodeLens("var", "vars", &common, sym.OffsetStartColumn(db, 2),
|
||||
AddCodeLens("var", "vars", &common, OffsetStartColumn(sym, 2),
|
||||
ToReference(db, type.instances), false /*force_display*/);
|
||||
break;
|
||||
}
|
||||
case SymbolKind::Func: {
|
||||
QueryFunc& func = sym.Func(db);
|
||||
QueryFunc& func = db->GetFunc(sym);
|
||||
if (!func.def)
|
||||
continue;
|
||||
|
||||
@ -187,27 +191,27 @@ struct TextDocumentCodeLensHandler
|
||||
if (base_callers.empty() && derived_callers.empty()) {
|
||||
SymbolRef loc = try_ensure_spelling(sym);
|
||||
AddCodeLens("call", "calls", &common,
|
||||
loc.OffsetStartColumn(db, offset++),
|
||||
OffsetStartColumn(loc, offset++),
|
||||
ToReference(db, func.callers), true /*force_display*/);
|
||||
} else {
|
||||
SymbolRef loc = try_ensure_spelling(sym);
|
||||
AddCodeLens("direct call", "direct calls", &common,
|
||||
loc.OffsetStartColumn(db, offset++),
|
||||
OffsetStartColumn(loc, offset++),
|
||||
ToReference(db, func.callers), false /*force_display*/);
|
||||
if (!base_callers.empty())
|
||||
AddCodeLens("base call", "base calls", &common,
|
||||
loc.OffsetStartColumn(db, offset++),
|
||||
OffsetStartColumn(loc, offset++),
|
||||
ToReference(db, base_callers),
|
||||
false /*force_display*/);
|
||||
if (!derived_callers.empty())
|
||||
AddCodeLens("derived call", "derived calls", &common,
|
||||
loc.OffsetStartColumn(db, offset++),
|
||||
OffsetStartColumn(loc, offset++),
|
||||
ToReference(db, derived_callers),
|
||||
false /*force_display*/);
|
||||
}
|
||||
|
||||
AddCodeLens("derived", "derived", &common,
|
||||
sym.OffsetStartColumn(db, offset++),
|
||||
OffsetStartColumn(sym, offset++),
|
||||
ToReference(db, func.derived), false /*force_display*/);
|
||||
|
||||
// "Base"
|
||||
@ -234,7 +238,7 @@ struct TextDocumentCodeLensHandler
|
||||
}
|
||||
}
|
||||
} else {
|
||||
AddCodeLens("base", "base", &common, sym.OffsetStartColumn(db, 1),
|
||||
AddCodeLens("base", "base", &common, OffsetStartColumn(sym, 1),
|
||||
ToReference(db, func.def->base),
|
||||
false /*force_display*/);
|
||||
}
|
||||
@ -242,7 +246,7 @@ struct TextDocumentCodeLensHandler
|
||||
break;
|
||||
}
|
||||
case SymbolKind::Var: {
|
||||
QueryVar& var = sym.Var(db);
|
||||
QueryVar& var = db->GetVar(sym);
|
||||
if (!var.def)
|
||||
continue;
|
||||
|
||||
@ -255,7 +259,7 @@ struct TextDocumentCodeLensHandler
|
||||
if (var.def->is_macro())
|
||||
force_display = false;
|
||||
|
||||
AddCodeLens("ref", "refs", &common, sym.OffsetStartColumn(db, 0),
|
||||
AddCodeLens("ref", "refs", &common, OffsetStartColumn(sym, 0),
|
||||
var.uses, force_display);
|
||||
break;
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ std::vector<Reference> GetGotoDefinitionTargets(QueryDatabase* db,
|
||||
case SymbolKind::Var: {
|
||||
std::vector<Reference> ret =
|
||||
GetDeclarationsOfSymbolForGotoDefinition(db, sym);
|
||||
QueryVar& var = sym.Var(db);
|
||||
QueryVar& var = db->GetVar(sym);
|
||||
if (var.def && var.def->variable_type) {
|
||||
std::vector<Reference> types = GetDeclarationsOfSymbolForGotoDefinition(
|
||||
db, SymbolRef(Range(), Id<void>(var.def->variable_type->id),
|
||||
|
@ -41,7 +41,7 @@ struct TextDocumentDocumentHighlightHandler
|
||||
std::vector<Reference> uses = GetUsesOfSymbol(db, sym, true);
|
||||
out.result.reserve(uses.size());
|
||||
for (const Reference& use : uses) {
|
||||
if (GetFileId(db, use) != file_id)
|
||||
if (db->GetFileId(use) != file_id)
|
||||
continue;
|
||||
|
||||
optional<lsLocation> ls_location =
|
||||
|
@ -16,7 +16,7 @@ lsWorkspaceEdit BuildWorkspaceEdit(QueryDatabase* db,
|
||||
if (!ls_location)
|
||||
continue;
|
||||
|
||||
QueryFileId file_id = GetFileId(db, ref);
|
||||
QueryFileId file_id = db->GetFileId(ref);
|
||||
if (path_to_edit.find(file_id) == path_to_edit.end()) {
|
||||
path_to_edit[file_id] = lsTextDocumentEdit();
|
||||
|
||||
|
15
src/query.cc
15
src/query.cc
@ -393,21 +393,6 @@ Maybe<QueryVarId> GetQueryVarIdFromUsr(QueryDatabase* query_db,
|
||||
|
||||
} // namespace
|
||||
|
||||
// FIXME Reference Remove
|
||||
QueryFileId GetFileId(QueryDatabase* db, Reference ref) {
|
||||
return db->GetFileId(ref);
|
||||
}
|
||||
|
||||
QueryFunc& SymbolRef::Func(QueryDatabase* db) const {
|
||||
return db->funcs[Idx()];
|
||||
}
|
||||
QueryType& SymbolRef::Type(QueryDatabase* db) const {
|
||||
return db->types[Idx()];
|
||||
}
|
||||
QueryVar& SymbolRef::Var(QueryDatabase* db) const {
|
||||
return db->vars[Idx()];
|
||||
}
|
||||
|
||||
Maybe<QueryFileId> QueryDatabase::GetQueryFileIdFromPath(
|
||||
const std::string& path) {
|
||||
return ::GetQueryFileIdFromPath(this, path, false);
|
||||
|
37
src/query.h
37
src/query.h
@ -20,32 +20,6 @@ using QueryVarId = Id<QueryVar>;
|
||||
|
||||
struct IdMap;
|
||||
|
||||
struct QueryLocation {
|
||||
Range range;
|
||||
QueryFileId path;
|
||||
SymbolRole role;
|
||||
|
||||
bool HasValue() const { return range.HasValue(); }
|
||||
QueryFileId FileId() const { return path; }
|
||||
|
||||
operator Reference() const {
|
||||
return Reference{range, Id<void>(path), SymbolKind::File, role};
|
||||
}
|
||||
|
||||
std::tuple<Range, QueryFileId, SymbolRole> ToTuple() const {
|
||||
return std::make_tuple(range, path, role);
|
||||
}
|
||||
bool operator==(const QueryLocation& o) const {
|
||||
return ToTuple() == o.ToTuple();
|
||||
}
|
||||
bool operator!=(const QueryLocation& o) const { return !(*this == o); }
|
||||
bool operator<(const QueryLocation& o) const {
|
||||
return ToTuple() < o.ToTuple();
|
||||
}
|
||||
};
|
||||
MAKE_REFLECT_STRUCT(QueryLocation, range, path, role);
|
||||
MAKE_HASHABLE(QueryLocation, t.range, t.path, t.role);
|
||||
|
||||
struct SymbolIdx {
|
||||
RawId idx;
|
||||
SymbolKind kind;
|
||||
@ -63,8 +37,6 @@ struct SymbolIdx {
|
||||
MAKE_REFLECT_STRUCT(SymbolIdx, kind, idx);
|
||||
MAKE_HASHABLE(SymbolIdx, t.kind, t.idx);
|
||||
|
||||
QueryFileId GetFileId(QueryDatabase* db, Reference ref);
|
||||
|
||||
struct SymbolRef : Reference {
|
||||
SymbolRef() = default;
|
||||
SymbolRef(Range range, Id<void> id, SymbolKind kind, SymbolRole role)
|
||||
@ -75,15 +47,6 @@ struct SymbolRef : Reference {
|
||||
|
||||
RawId Idx() const { return RawId(id); }
|
||||
operator SymbolIdx() const { return SymbolIdx{Idx(), kind, }; }
|
||||
QueryFunc& Func(QueryDatabase* db) const;
|
||||
QueryType& Type(QueryDatabase* db) const;
|
||||
QueryVar& Var(QueryDatabase* db) const;
|
||||
|
||||
QueryLocation OffsetStartColumn(QueryDatabase* db, int16_t offset) const {
|
||||
QueryLocation ret = {range, GetFileId(db, *this), role};
|
||||
ret.range.start.column += offset;
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
struct QueryFuncRef : Reference {
|
||||
|
@ -46,19 +46,19 @@ optional<Reference> GetDefinitionSpellingOfSymbol(QueryDatabase* db,
|
||||
SymbolRef sym) {
|
||||
switch (sym.kind) {
|
||||
case SymbolKind::Type: {
|
||||
QueryType& type = sym.Type(db);
|
||||
QueryType& type = db->GetType(sym);
|
||||
if (type.def)
|
||||
return *type.def->definition_spelling;
|
||||
break;
|
||||
}
|
||||
case SymbolKind::Func: {
|
||||
QueryFunc& func = sym.Func(db);
|
||||
QueryFunc& func = db->GetFunc(sym);
|
||||
if (func.def)
|
||||
return func.def->definition_spelling;
|
||||
break;
|
||||
}
|
||||
case SymbolKind::Var: {
|
||||
QueryVar& var = sym.Var(db);
|
||||
QueryVar& var = db->GetVar(sym);
|
||||
if (var.def)
|
||||
return var.def->definition_spelling;
|
||||
break;
|
||||
@ -76,19 +76,19 @@ optional<Reference> GetDefinitionExtentOfSymbol(QueryDatabase* db,
|
||||
SymbolRef sym) {
|
||||
switch (sym.kind) {
|
||||
case SymbolKind::Type: {
|
||||
QueryType& type = sym.Type(db);
|
||||
QueryType& type = db->GetType(sym);
|
||||
if (type.def)
|
||||
return type.def->definition_extent;
|
||||
break;
|
||||
}
|
||||
case SymbolKind::Func: {
|
||||
QueryFunc& func = sym.Func(db);
|
||||
QueryFunc& func = db->GetFunc(sym);
|
||||
if (func.def)
|
||||
return func.def->definition_extent;
|
||||
break;
|
||||
}
|
||||
case SymbolKind::Var: {
|
||||
QueryVar& var = sym.Var(db);
|
||||
QueryVar& var = db->GetVar(sym);
|
||||
if (var.def)
|
||||
return var.def->definition_extent;
|
||||
break;
|
||||
@ -107,13 +107,13 @@ optional<QueryFileId> GetDeclarationFileForSymbol(QueryDatabase* db,
|
||||
SymbolRef sym) {
|
||||
switch (sym.kind) {
|
||||
case SymbolKind::Type: {
|
||||
QueryType& type = sym.Type(db);
|
||||
QueryType& type = db->GetType(sym);
|
||||
if (type.def && type.def->definition_spelling)
|
||||
return db->GetFileId(*type.def->definition_spelling);
|
||||
break;
|
||||
}
|
||||
case SymbolKind::Func: {
|
||||
QueryFunc& func = sym.Func(db);
|
||||
QueryFunc& func = db->GetFunc(sym);
|
||||
if (!func.declarations.empty())
|
||||
return db->GetFileId(func.declarations[0]);
|
||||
if (func.def && func.def->definition_spelling)
|
||||
@ -121,7 +121,7 @@ optional<QueryFileId> GetDeclarationFileForSymbol(QueryDatabase* db,
|
||||
break;
|
||||
}
|
||||
case SymbolKind::Var: {
|
||||
QueryVar& var = sym.Var(db);
|
||||
QueryVar& var = db->GetVar(sym);
|
||||
if (var.def && var.def->definition_spelling)
|
||||
return db->GetFileId(*var.def->definition_spelling);
|
||||
break;
|
||||
@ -366,7 +366,7 @@ optional<lsLocation> GetLsLocation(QueryDatabase* db,
|
||||
WorkingFiles* working_files,
|
||||
Reference ref) {
|
||||
std::string path;
|
||||
QueryFileId file_id = GetFileId(db, ref);
|
||||
QueryFileId file_id = db->GetFileId(ref);
|
||||
if (!file_id.HasValue())
|
||||
return nullopt;
|
||||
lsDocumentUri uri = GetLsDocumentUri(db, file_id, &path);
|
||||
@ -413,7 +413,7 @@ optional<lsSymbolInformation> GetSymbolInfo(QueryDatabase* db,
|
||||
return info;
|
||||
}
|
||||
case SymbolKind::Type: {
|
||||
QueryType& type = sym.Type(db);
|
||||
QueryType& type = db->GetType(sym);
|
||||
if (!type.def)
|
||||
break;
|
||||
|
||||
@ -436,7 +436,7 @@ optional<lsSymbolInformation> GetSymbolInfo(QueryDatabase* db,
|
||||
return info;
|
||||
}
|
||||
case SymbolKind::Func: {
|
||||
QueryFunc& func = sym.Func(db);
|
||||
QueryFunc& func = db->GetFunc(sym);
|
||||
if (!func.def)
|
||||
break;
|
||||
|
||||
@ -457,7 +457,7 @@ optional<lsSymbolInformation> GetSymbolInfo(QueryDatabase* db,
|
||||
return info;
|
||||
}
|
||||
case SymbolKind::Var: {
|
||||
QueryVar& var = sym.Var(db);
|
||||
QueryVar& var = db->GetVar(sym);
|
||||
if (!var.def)
|
||||
break;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user