Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide/src/runnables.rs')
-rw-r--r--crates/ide/src/runnables.rs68
1 files changed, 43 insertions, 25 deletions
diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs
index b6c6753755..64ffa59101 100644
--- a/crates/ide/src/runnables.rs
+++ b/crates/ide/src/runnables.rs
@@ -15,6 +15,7 @@ use ide_db::{
FxHashMap, FxHashSet, RootDatabase, SymbolKind,
};
use itertools::Itertools;
+use span::TextSize;
use stdx::{always, format_to};
use syntax::{
ast::{self, AstNode},
@@ -48,16 +49,15 @@ impl fmt::Display for TestId {
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub enum RunnableKind {
- Test { test_id: TestId, attr: TestAttr },
TestMod { path: String },
+ Test { test_id: TestId, attr: TestAttr },
Bench { test_id: TestId },
DocTest { test_id: TestId },
Bin,
}
-#[cfg(test)]
-#[derive(Debug, Clone, Hash, PartialEq, Eq)]
-enum RunnableTestKind {
+#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
+enum RunnableDiscKind {
Test,
TestMod,
DocTest,
@@ -65,6 +65,18 @@ enum RunnableTestKind {
Bin,
}
+impl RunnableKind {
+ fn disc(&self) -> RunnableDiscKind {
+ match self {
+ RunnableKind::TestMod { .. } => RunnableDiscKind::TestMod,
+ RunnableKind::Test { .. } => RunnableDiscKind::Test,
+ RunnableKind::DocTest { .. } => RunnableDiscKind::DocTest,
+ RunnableKind::Bench { .. } => RunnableDiscKind::Bench,
+ RunnableKind::Bin => RunnableDiscKind::Bin,
+ }
+ }
+}
+
impl Runnable {
// test package::module::testname
pub fn label(&self, target: Option<String>) -> String {
@@ -97,17 +109,6 @@ impl Runnable {
s.push_str(suffix);
s
}
-
- #[cfg(test)]
- fn test_kind(&self) -> RunnableTestKind {
- match &self.kind {
- RunnableKind::TestMod { .. } => RunnableTestKind::TestMod,
- RunnableKind::Test { .. } => RunnableTestKind::Test,
- RunnableKind::DocTest { .. } => RunnableTestKind::DocTest,
- RunnableKind::Bench { .. } => RunnableTestKind::Bench,
- RunnableKind::Bin => RunnableTestKind::Bin,
- }
- }
}
// Feature: Run
@@ -193,6 +194,20 @@ pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> {
r
})
}));
+ res.sort_by(|Runnable { nav, kind, .. }, Runnable { nav: nav_b, kind: kind_b, .. }| {
+ // full_range.start < focus_range.start < name, should give us a decent unique ordering
+ nav.full_range
+ .start()
+ .cmp(&nav_b.full_range.start())
+ .then_with(|| {
+ let t_0 = || TextSize::from(0);
+ nav.focus_range
+ .map_or_else(t_0, |it| it.start())
+ .cmp(&nav_b.focus_range.map_or_else(t_0, |it| it.start()))
+ })
+ .then_with(|| kind.disc().cmp(&kind_b.disc()))
+ .then_with(|| nav.name.cmp(&nav_b.name))
+ });
res
}
@@ -571,13 +586,12 @@ mod tests {
fn check(ra_fixture: &str, expect: Expect) {
let (analysis, position) = fixture::position(ra_fixture);
- let mut runnables = analysis.runnables(position.file_id).unwrap();
- runnables.sort_by_key(|it| (it.nav.full_range.start(), it.nav.name.clone()));
-
- let result = runnables
+ let result = analysis
+ .runnables(position.file_id)
+ .unwrap()
.into_iter()
.map(|runnable| {
- let mut a = format!("({:?}, {:?}", runnable.test_kind(), runnable.nav);
+ let mut a = format!("({:?}, {:?}", runnable.kind.disc(), runnable.nav);
if runnable.use_name_in_title {
a.push_str(", true");
}
@@ -609,6 +623,9 @@ fn main() {}
#[export_name = "main"]
fn __cortex_m_rt_main_trampoline() {}
+#[unsafe(export_name = "main")]
+fn __cortex_m_rt_main_trampoline_unsafe() {}
+
#[test]
fn test_foo() {}
@@ -628,13 +645,14 @@ mod not_a_root {
"#,
expect![[r#"
[
- "(TestMod, NavigationTarget { file_id: FileId(0), full_range: 0..253, name: \"\", kind: Module })",
+ "(TestMod, NavigationTarget { file_id: FileId(0), full_range: 0..331, name: \"\", kind: Module })",
"(Bin, NavigationTarget { file_id: FileId(0), full_range: 1..13, focus_range: 4..8, name: \"main\", kind: Function })",
"(Bin, NavigationTarget { file_id: FileId(0), full_range: 15..76, focus_range: 42..71, name: \"__cortex_m_rt_main_trampoline\", kind: Function })",
- "(Test, NavigationTarget { file_id: FileId(0), full_range: 78..102, focus_range: 89..97, name: \"test_foo\", kind: Function })",
- "(Test, NavigationTarget { file_id: FileId(0), full_range: 104..155, focus_range: 136..150, name: \"test_full_path\", kind: Function })",
- "(Test, NavigationTarget { file_id: FileId(0), full_range: 157..191, focus_range: 178..186, name: \"test_foo\", kind: Function })",
- "(Bench, NavigationTarget { file_id: FileId(0), full_range: 193..215, focus_range: 205..210, name: \"bench\", kind: Function })",
+ "(Bin, NavigationTarget { file_id: FileId(0), full_range: 78..154, focus_range: 113..149, name: \"__cortex_m_rt_main_trampoline_unsafe\", kind: Function })",
+ "(Test, NavigationTarget { file_id: FileId(0), full_range: 156..180, focus_range: 167..175, name: \"test_foo\", kind: Function })",
+ "(Test, NavigationTarget { file_id: FileId(0), full_range: 182..233, focus_range: 214..228, name: \"test_full_path\", kind: Function })",
+ "(Test, NavigationTarget { file_id: FileId(0), full_range: 235..269, focus_range: 256..264, name: \"test_foo\", kind: Function })",
+ "(Bench, NavigationTarget { file_id: FileId(0), full_range: 271..293, focus_range: 283..288, name: \"bench\", kind: Function })",
]
"#]],
);