Skip to content

Commit b332a05

Browse files
authored
Merge pull request #19161 from Veykril/push-prmuyxlnxzxo
fix: Improve sort order of runnables
2 parents 7128701 + e0d1fba commit b332a05

File tree

2 files changed

+45
-33
lines changed

2 files changed

+45
-33
lines changed

crates/ide/src/annotations.rs

+43-31
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use hir::{HasSource, InFile, InRealFile, Semantics};
22
use ide_db::{
3-
defs::Definition, helpers::visit_file_defs, FileId, FilePosition, FileRange, FxHashSet,
3+
defs::Definition, helpers::visit_file_defs, FileId, FilePosition, FileRange, FxIndexSet,
44
RootDatabase,
55
};
66
use itertools::Itertools;
@@ -55,7 +55,7 @@ pub(crate) fn annotations(
5555
config: &AnnotationConfig,
5656
file_id: FileId,
5757
) -> Vec<Annotation> {
58-
let mut annotations = FxHashSet::default();
58+
let mut annotations = FxIndexSet::default();
5959

6060
if config.annotate_runnables {
6161
for runnable in runnables(db, file_id) {
@@ -170,7 +170,19 @@ pub(crate) fn annotations(
170170
}));
171171
}
172172

173-
annotations.into_iter().sorted_by_key(|a| (a.range.start(), a.range.end())).collect()
173+
annotations
174+
.into_iter()
175+
.sorted_by_key(|a| {
176+
(
177+
a.range.start(),
178+
a.range.end(),
179+
match &a.kind {
180+
AnnotationKind::Runnable(runnable) => Some(runnable.nav.name.clone()),
181+
_ => None,
182+
},
183+
)
184+
})
185+
.collect()
174186
}
175187

176188
pub(crate) fn resolve_annotation(db: &RootDatabase, mut annotation: Annotation) -> Annotation {
@@ -535,6 +547,20 @@ fn main() {
535547
),
536548
},
537549
},
550+
Annotation {
551+
range: 69..73,
552+
kind: HasReferences {
553+
pos: FilePositionWrapper {
554+
file_id: FileId(
555+
0,
556+
),
557+
offset: 69,
558+
},
559+
data: Some(
560+
[],
561+
),
562+
},
563+
},
538564
Annotation {
539565
range: 69..73,
540566
kind: Runnable(
@@ -559,20 +585,6 @@ fn main() {
559585
},
560586
),
561587
},
562-
Annotation {
563-
range: 69..73,
564-
kind: HasReferences {
565-
pos: FilePositionWrapper {
566-
file_id: FileId(
567-
0,
568-
),
569-
offset: 69,
570-
},
571-
data: Some(
572-
[],
573-
),
574-
},
575-
},
576588
]
577589
"#]],
578590
);
@@ -717,6 +729,20 @@ fn main() {
717729
),
718730
},
719731
},
732+
Annotation {
733+
range: 61..65,
734+
kind: HasReferences {
735+
pos: FilePositionWrapper {
736+
file_id: FileId(
737+
0,
738+
),
739+
offset: 61,
740+
},
741+
data: Some(
742+
[],
743+
),
744+
},
745+
},
720746
Annotation {
721747
range: 61..65,
722748
kind: Runnable(
@@ -741,20 +767,6 @@ fn main() {
741767
},
742768
),
743769
},
744-
Annotation {
745-
range: 61..65,
746-
kind: HasReferences {
747-
pos: FilePositionWrapper {
748-
file_id: FileId(
749-
0,
750-
),
751-
offset: 61,
752-
},
753-
data: Some(
754-
[],
755-
),
756-
},
757-
},
758770
]
759771
"#]],
760772
);

crates/ide/src/runnables.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use ide_db::{
1313
documentation::docs_from_attrs,
1414
helpers::visit_file_defs,
1515
search::{FileReferenceNode, SearchScope},
16-
FilePosition, FxHashMap, FxHashSet, RootDatabase, SymbolKind,
16+
FilePosition, FxHashMap, FxHashSet, FxIndexMap, RootDatabase, SymbolKind,
1717
};
1818
use itertools::Itertools;
1919
use smallvec::SmallVec;
@@ -130,7 +130,7 @@ pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> {
130130
let mut res = Vec::new();
131131
// Record all runnables that come from macro expansions here instead.
132132
// In case an expansion creates multiple runnables we want to name them to avoid emitting a bunch of equally named runnables.
133-
let mut in_macro_expansion = FxHashMap::<hir::HirFileId, Vec<Runnable>>::default();
133+
let mut in_macro_expansion = FxIndexMap::<hir::HirFileId, Vec<Runnable>>::default();
134134
let mut add_opt = |runnable: Option<Runnable>, def| {
135135
if let Some(runnable) = runnable.filter(|runnable| runnable.nav.file_id == file_id) {
136136
if let Some(def) = def {

0 commit comments

Comments
 (0)