mirror of
https://github.com/astral-sh/ruff
synced 2026-01-21 05:20:49 -05:00
[ty] More sensible sorting for results returned by all_symbols
Previously, we would only sort by name and file path (unless the symbol refers to an entire module). This led to somewhat confusing ordering, since the file path is absolute and can be anything. Sorting by module name after symbol name gives a more predictable ordering in common practice. This is mostly just an improvement for debugging purposes, i.e., when looking at the output of `all_symbols` directly. This mostly shouldn't impact completion ordering since completions do their own ranking.
This commit is contained in:
committed by
Andrew Gallant
parent
f1bd5f1941
commit
eef34958f9
@@ -64,7 +64,11 @@ pub fn all_symbols<'db>(
|
||||
continue;
|
||||
}
|
||||
s.spawn(move |_| {
|
||||
let symbols_for_file_span = tracing::debug_span!(parent: all_symbols_span, "symbols_for_file_global_only", ?file);
|
||||
let symbols_for_file_span = tracing::debug_span!(
|
||||
parent: all_symbols_span,
|
||||
"symbols_for_file_global_only",
|
||||
path = %file.path(&*db),
|
||||
);
|
||||
let _entered = symbols_for_file_span.entered();
|
||||
|
||||
if query.is_match_symbol_name(module.name(&*db)) {
|
||||
@@ -94,11 +98,13 @@ pub fn all_symbols<'db>(
|
||||
let key1 = (
|
||||
s1.name_in_file()
|
||||
.unwrap_or_else(|| s1.module().name(db).as_str()),
|
||||
s1.module().name(db).as_str(),
|
||||
s1.file.path(db).as_str(),
|
||||
);
|
||||
let key2 = (
|
||||
s2.name_in_file()
|
||||
.unwrap_or_else(|| s2.module().name(db).as_str()),
|
||||
s2.module().name(db).as_str(),
|
||||
s2.file.path(db).as_str(),
|
||||
);
|
||||
key1.cmp(&key2)
|
||||
|
||||
Reference in New Issue
Block a user