mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-19 03:55:49 +00:00
Order SymbolRef by size first, Role::Definition second
This commit is contained in:
parent
5164c4b2f6
commit
d33bf50181
@ -23,17 +23,8 @@ struct CqueryBaseHandler : BaseMessageHandler<Ipc_CqueryBase> {
|
||||
|
||||
Out_LocationList out;
|
||||
out.id = request->id;
|
||||
std::vector<SymbolRef> syms =
|
||||
FindSymbolsAtLocation(working_file, file, request->params.position);
|
||||
// A template definition may be a use of its primary template.
|
||||
// We want to get the definition instead of the use.
|
||||
// Order by |Definition| DESC, range size ASC.
|
||||
std::stable_sort(syms.begin(), syms.end(),
|
||||
[](const SymbolRef& a, const SymbolRef& b) {
|
||||
return (a.role & Role::Definition) >
|
||||
(b.role & Role::Definition);
|
||||
});
|
||||
for (SymbolRef sym : syms) {
|
||||
for (SymbolRef sym :
|
||||
FindSymbolsAtLocation(working_file, file, request->params.position)) {
|
||||
if (sym.kind == SymbolKind::Type) {
|
||||
if (const auto* def = db->GetType(sym).AnyDef())
|
||||
out.result = GetLsLocations(db, working_files,
|
||||
|
@ -23,17 +23,8 @@ struct CqueryDerivedHandler : BaseMessageHandler<Ipc_CqueryDerived> {
|
||||
|
||||
Out_LocationList out;
|
||||
out.id = request->id;
|
||||
std::vector<SymbolRef> syms =
|
||||
FindSymbolsAtLocation(working_file, file, request->params.position);
|
||||
// A template definition may be a use of its primary template.
|
||||
// We want to get the definition instead of the use.
|
||||
// Order by |Definition| DESC, range size ASC.
|
||||
std::stable_sort(syms.begin(), syms.end(),
|
||||
[](const SymbolRef& a, const SymbolRef& b) {
|
||||
return (a.role & Role::Definition) >
|
||||
(b.role & Role::Definition);
|
||||
});
|
||||
for (const SymbolRef& sym : syms) {
|
||||
for (SymbolRef sym :
|
||||
FindSymbolsAtLocation(working_file, file, request->params.position)) {
|
||||
if (sym.kind == SymbolKind::Type) {
|
||||
QueryType& type = db->GetType(sym);
|
||||
out.result =
|
||||
|
@ -534,13 +534,14 @@ std::vector<SymbolRef> FindSymbolsAtLocation(WorkingFile* working_file,
|
||||
// better on constructors.
|
||||
std::sort(symbols.begin(), symbols.end(),
|
||||
[](const SymbolRef& a, const SymbolRef& b) {
|
||||
int a_size = ComputeRangeSize(a.range);
|
||||
int b_size = ComputeRangeSize(b.range);
|
||||
|
||||
if (a_size != b_size)
|
||||
return a_size < b_size;
|
||||
int t = ComputeRangeSize(a.range) - ComputeRangeSize(b.range);
|
||||
if (t)
|
||||
return t < 0;
|
||||
t = (a.role & Role::Definition) - (b.role & Role::Definition);
|
||||
if (t)
|
||||
return t > 0;
|
||||
// operator> orders Var/Func before Type.
|
||||
int t = static_cast<int>(a.kind) - static_cast<int>(b.kind);
|
||||
t = static_cast<int>(a.kind) - static_cast<int>(b.kind);
|
||||
if (t)
|
||||
return t > 0;
|
||||
return a.id < b.id;
|
||||
|
Loading…
Reference in New Issue
Block a user