@@ -183,6 +183,8 @@ fn find_path_for_module(
183
183
let kind = if name_already_occupied_in_type_ns {
184
184
cov_mark:: hit!( ambiguous_crate_start) ;
185
185
PathKind :: Abs
186
+ } else if ctx. cfg . prefer_absolute {
187
+ PathKind :: Abs
186
188
} else {
187
189
PathKind :: Plain
188
190
} ;
@@ -564,7 +566,13 @@ mod tests {
564
566
/// item the `path` refers to returns that same path when called from the
565
567
/// module the cursor is in.
566
568
#[ track_caller]
567
- fn check_found_path_ ( ra_fixture : & str , path : & str , prefer_prelude : bool , expect : Expect ) {
569
+ fn check_found_path_ (
570
+ ra_fixture : & str ,
571
+ path : & str ,
572
+ prefer_prelude : bool ,
573
+ prefer_absolute : bool ,
574
+ expect : Expect ,
575
+ ) {
568
576
let ( db, pos) = TestDB :: with_position ( ra_fixture) ;
569
577
let module = db. module_at_position ( pos) ;
570
578
let parsed_path_file =
@@ -604,7 +612,7 @@ mod tests {
604
612
module,
605
613
prefix,
606
614
ignore_local_imports,
607
- ImportPathConfig { prefer_no_std : false , prefer_prelude } ,
615
+ ImportPathConfig { prefer_no_std : false , prefer_prelude, prefer_absolute } ,
608
616
) ;
609
617
format_to ! (
610
618
res,
@@ -619,11 +627,15 @@ mod tests {
619
627
}
620
628
621
629
fn check_found_path ( ra_fixture : & str , path : & str , expect : Expect ) {
622
- check_found_path_ ( ra_fixture, path, false , expect) ;
630
+ check_found_path_ ( ra_fixture, path, false , false , expect) ;
623
631
}
624
632
625
633
fn check_found_path_prelude ( ra_fixture : & str , path : & str , expect : Expect ) {
626
- check_found_path_ ( ra_fixture, path, true , expect) ;
634
+ check_found_path_ ( ra_fixture, path, true , false , expect) ;
635
+ }
636
+
637
+ fn check_found_path_absolute ( ra_fixture : & str , path : & str , expect : Expect ) {
638
+ check_found_path_ ( ra_fixture, path, false , true , expect) ;
627
639
}
628
640
629
641
#[ test]
@@ -870,6 +882,39 @@ pub mod ast {
870
882
) ;
871
883
}
872
884
885
+ #[ test]
886
+ fn partially_imported_with_prefer_absolute ( ) {
887
+ cov_mark:: check!( partially_imported) ;
888
+ // Similar to partially_imported test case above, but with prefer_absolute enabled.
889
+ // Even if the actual imported item is in external crate, if the path to that item
890
+ // is starting from the imported name, then the path should not start from "::".
891
+ // i.e. The first line in the expected output should not start from "::".
892
+ check_found_path_absolute (
893
+ r#"
894
+ //- /main.rs crate:main deps:syntax
895
+
896
+ use syntax::ast;
897
+ $0
898
+
899
+ //- /lib.rs crate:syntax
900
+ pub mod ast {
901
+ pub enum ModuleItem {
902
+ A, B, C,
903
+ }
904
+ }
905
+ "# ,
906
+ "syntax::ast::ModuleItem" ,
907
+ expect ! [ [ r#"
908
+ Plain (imports ✔): ast::ModuleItem
909
+ Plain (imports ✖): ::syntax::ast::ModuleItem
910
+ ByCrate(imports ✔): crate::ast::ModuleItem
911
+ ByCrate(imports ✖): ::syntax::ast::ModuleItem
912
+ BySelf (imports ✔): self::ast::ModuleItem
913
+ BySelf (imports ✖): ::syntax::ast::ModuleItem
914
+ "# ] ] ,
915
+ ) ;
916
+ }
917
+
873
918
#[ test]
874
919
fn same_crate_reexport ( ) {
875
920
check_found_path (
@@ -1769,6 +1814,43 @@ pub mod foo {
1769
1814
) ;
1770
1815
}
1771
1816
1817
+ #[ test]
1818
+ fn respects_absolute_setting ( ) {
1819
+ let ra_fixture = r#"
1820
+ //- /main.rs crate:main deps:krate
1821
+ $0
1822
+ //- /krate.rs crate:krate
1823
+ pub mod foo {
1824
+ pub struct Foo;
1825
+ }
1826
+ "# ;
1827
+ check_found_path (
1828
+ ra_fixture,
1829
+ "krate::foo::Foo" ,
1830
+ expect ! [ [ r#"
1831
+ Plain (imports ✔): krate::foo::Foo
1832
+ Plain (imports ✖): krate::foo::Foo
1833
+ ByCrate(imports ✔): krate::foo::Foo
1834
+ ByCrate(imports ✖): krate::foo::Foo
1835
+ BySelf (imports ✔): krate::foo::Foo
1836
+ BySelf (imports ✖): krate::foo::Foo
1837
+ "# ] ] ,
1838
+ ) ;
1839
+
1840
+ check_found_path_absolute (
1841
+ ra_fixture,
1842
+ "krate::foo::Foo" ,
1843
+ expect ! [ [ r#"
1844
+ Plain (imports ✔): ::krate::foo::Foo
1845
+ Plain (imports ✖): ::krate::foo::Foo
1846
+ ByCrate(imports ✔): ::krate::foo::Foo
1847
+ ByCrate(imports ✖): ::krate::foo::Foo
1848
+ BySelf (imports ✔): ::krate::foo::Foo
1849
+ BySelf (imports ✖): ::krate::foo::Foo
1850
+ "# ] ] ,
1851
+ ) ;
1852
+ }
1853
+
1772
1854
#[ test]
1773
1855
fn respect_segment_length ( ) {
1774
1856
check_found_path (
0 commit comments