sqry_cli/commands/
sort.rs1use crate::args::SortField;
2use crate::output::DisplaySymbol;
3
4pub fn sort_symbols(symbols: &mut [DisplaySymbol], sort_field: SortField) {
5 symbols.sort_by(|a, b| match sort_field {
6 SortField::File => a
7 .file_path
8 .cmp(&b.file_path)
9 .then_with(|| a.start_line.cmp(&b.start_line))
10 .then_with(|| a.start_column.cmp(&b.start_column))
11 .then_with(|| a.name.cmp(&b.name)),
12 SortField::Line => a
13 .start_line
14 .cmp(&b.start_line)
15 .then_with(|| a.start_column.cmp(&b.start_column))
16 .then_with(|| a.file_path.cmp(&b.file_path))
17 .then_with(|| a.name.cmp(&b.name)),
18 SortField::Name => a
19 .name
20 .cmp(&b.name)
21 .then_with(|| a.file_path.cmp(&b.file_path))
22 .then_with(|| a.start_line.cmp(&b.start_line)),
23 SortField::Kind => a
24 .kind
25 .cmp(&b.kind)
26 .then_with(|| a.name.cmp(&b.name))
27 .then_with(|| a.file_path.cmp(&b.file_path)),
28 });
29}