Skip to content

Commit 9d9b343

Browse files
committed
Auto merge of #16389 - davidsemakula:order-use-tree-raw-ident, r=lnicola
internal: properly order raw idents when ordering use trees Follow up to #16352 to properly order raw identifiers.
2 parents a19372f + 84a3b52 commit 9d9b343

File tree

2 files changed

+82
-11
lines changed

2 files changed

+82
-11
lines changed

crates/ide-db/src/imports/insert_use/tests.rs

Lines changed: 77 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,16 @@ fn insert_start_indent() {
137137
use std::bar::B;
138138
use std::bar::C;",
139139
);
140+
check_none(
141+
"std::bar::r#AA",
142+
r"
143+
use std::bar::B;
144+
use std::bar::C;",
145+
r"
146+
use std::bar::r#AA;
147+
use std::bar::B;
148+
use std::bar::C;",
149+
);
140150
}
141151

142152
#[test]
@@ -173,7 +183,21 @@ fn insert_middle_indent() {
173183
use std::bar::EE;
174184
use std::bar::F;
175185
use std::bar::G;",
176-
)
186+
);
187+
check_none(
188+
"std::bar::r#EE",
189+
r"
190+
use std::bar::A;
191+
use std::bar::D;
192+
use std::bar::F;
193+
use std::bar::G;",
194+
r"
195+
use std::bar::A;
196+
use std::bar::D;
197+
use std::bar::r#EE;
198+
use std::bar::F;
199+
use std::bar::G;",
200+
);
177201
}
178202

179203
#[test]
@@ -210,7 +234,21 @@ fn insert_end_indent() {
210234
use std::bar::F;
211235
use std::bar::G;
212236
use std::bar::ZZ;",
213-
)
237+
);
238+
check_none(
239+
"std::bar::r#ZZ",
240+
r"
241+
use std::bar::A;
242+
use std::bar::D;
243+
use std::bar::F;
244+
use std::bar::G;",
245+
r"
246+
use std::bar::A;
247+
use std::bar::D;
248+
use std::bar::F;
249+
use std::bar::G;
250+
use std::bar::r#ZZ;",
251+
);
214252
}
215253

216254
#[test]
@@ -228,7 +266,21 @@ use std::bar::EE;
228266
use std::bar::{D, Z}; // example of weird imports due to user
229267
use std::bar::F;
230268
use std::bar::G;",
231-
)
269+
);
270+
check_none(
271+
"std::bar::r#EE",
272+
r"
273+
use std::bar::A;
274+
use std::bar::{D, Z}; // example of weird imports due to user
275+
use std::bar::F;
276+
use std::bar::G;",
277+
r"
278+
use std::bar::A;
279+
use std::bar::r#EE;
280+
use std::bar::{D, Z}; // example of weird imports due to user
281+
use std::bar::F;
282+
use std::bar::G;",
283+
);
232284
}
233285

234286
#[test]
@@ -596,7 +648,16 @@ fn merge_groups_full() {
596648

597649
#[test]
598650
fn merge_groups_long_full() {
599-
check_crate("std::foo::bar::Baz", r"use std::foo::bar::Qux;", r"use std::foo::bar::{Baz, Qux};")
651+
check_crate(
652+
"std::foo::bar::Baz",
653+
r"use std::foo::bar::Qux;",
654+
r"use std::foo::bar::{Baz, Qux};",
655+
);
656+
check_crate(
657+
"std::foo::bar::r#Baz",
658+
r"use std::foo::bar::Qux;",
659+
r"use std::foo::bar::{r#Baz, Qux};",
660+
);
600661
}
601662

602663
#[test]
@@ -614,7 +675,12 @@ fn merge_groups_long_full_list() {
614675
"std::foo::bar::Baz",
615676
r"use std::foo::bar::{Qux, Quux};",
616677
r"use std::foo::bar::{Baz, Quux, Qux};",
617-
)
678+
);
679+
check_crate(
680+
"std::foo::bar::r#Baz",
681+
r"use std::foo::bar::{Qux, Quux};",
682+
r"use std::foo::bar::{r#Baz, Quux, Qux};",
683+
);
618684
}
619685

620686
#[test]
@@ -632,7 +698,12 @@ fn merge_groups_long_full_nested() {
632698
"std::foo::bar::Baz",
633699
r"use std::foo::bar::{Qux, quux::{Fez, Fizz}};",
634700
r"use std::foo::bar::{quux::{Fez, Fizz}, Baz, Qux};",
635-
)
701+
);
702+
check_crate(
703+
"std::foo::bar::r#Baz",
704+
r"use std::foo::bar::{Qux, quux::{Fez, Fizz}};",
705+
r"use std::foo::bar::{quux::{Fez, Fizz}, r#Baz, Qux};",
706+
);
636707
}
637708

638709
#[test]

crates/ide-db/src/imports/merge_imports.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use syntax::{
99
algo,
1010
ast::{self, make, AstNode, HasAttrs, HasName, HasVisibility, PathSegmentKind},
1111
ted::{self, Position},
12-
Direction, TokenText,
12+
Direction,
1313
};
1414

1515
use crate::syntax_helpers::node_ext::vis_eq;
@@ -339,8 +339,8 @@ fn path_segment_cmp(a: &ast::PathSegment, b: &ast::PathSegment) -> Ordering {
339339
(None, Some(_)) => Ordering::Less,
340340
(Some(a_name), Some(b_name)) => {
341341
// snake_case < CamelCase < UPPER_SNAKE_CASE
342-
let a_text = a_name.as_str();
343-
let b_text = b_name.as_str();
342+
let a_text = a_name.as_str().trim_start_matches("r#");
343+
let b_text = b_name.as_str().trim_start_matches("r#");
344344
if a_text.starts_with(char::is_lowercase)
345345
&& b_text.starts_with(char::is_uppercase)
346346
{
@@ -388,14 +388,14 @@ fn use_tree_cmp_by_tree_list_glob_or_alias(
388388
.as_ref()
389389
.map(ast::Name::text)
390390
.as_ref()
391-
.map_or("_", TokenText::as_str)
391+
.map_or("_", |a_name| a_name.as_str().trim_start_matches("r#"))
392392
.cmp(
393393
b_rename
394394
.name()
395395
.as_ref()
396396
.map(ast::Name::text)
397397
.as_ref()
398-
.map_or("_", TokenText::as_str),
398+
.map_or("_", |b_name| b_name.as_str().trim_start_matches("r#")),
399399
),
400400
},
401401
};

0 commit comments

Comments
 (0)