diff options
author | Aleksey Kladov <[email protected]> | 2020-12-09 16:01:15 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-12-09 16:07:05 +0000 |
commit | 6e24321e4579d25686982002ed18f321db23cb9f (patch) | |
tree | 08f0fd7d99ad22a3d1db782482b66548e99ba8b2 /crates/ide | |
parent | 5e3891c2559de5a6540d69bc14ded281484479f9 (diff) |
Introduce anchored_path
They allow to represent paths like `#[path = "C:\path.rs"] mod foo;`
in a lossless cross-platform & network-transparent way.
Diffstat (limited to 'crates/ide')
-rw-r--r-- | crates/ide/src/diagnostics.rs | 10 | ||||
-rw-r--r-- | crates/ide/src/diagnostics/fixes.rs | 8 | ||||
-rw-r--r-- | crates/ide/src/references/rename.rs | 57 |
3 files changed, 45 insertions, 30 deletions
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs index c8453edb3..d09f3a0a1 100644 --- a/crates/ide/src/diagnostics.rs +++ b/crates/ide/src/diagnostics.rs | |||
@@ -610,10 +610,12 @@ fn test_fn() { | |||
610 | source_file_edits: [], | 610 | source_file_edits: [], |
611 | file_system_edits: [ | 611 | file_system_edits: [ |
612 | CreateFile { | 612 | CreateFile { |
613 | anchor: FileId( | 613 | dst: AnchoredPathBuf { |
614 | 0, | 614 | anchor: FileId( |
615 | ), | 615 | 0, |
616 | dst: "foo.rs", | 616 | ), |
617 | path: "foo.rs", | ||
618 | }, | ||
617 | }, | 619 | }, |
618 | ], | 620 | ], |
619 | is_snippet: false, | 621 | is_snippet: false, |
diff --git a/crates/ide/src/diagnostics/fixes.rs b/crates/ide/src/diagnostics/fixes.rs index 24d08651e..29c7a040b 100644 --- a/crates/ide/src/diagnostics/fixes.rs +++ b/crates/ide/src/diagnostics/fixes.rs | |||
@@ -8,7 +8,7 @@ use hir::{ | |||
8 | }, | 8 | }, |
9 | HasSource, HirDisplay, Semantics, VariantDef, | 9 | HasSource, HirDisplay, Semantics, VariantDef, |
10 | }; | 10 | }; |
11 | use ide_db::base_db::FileId; | 11 | use ide_db::base_db::{AnchoredPathBuf, FileId}; |
12 | use ide_db::{ | 12 | use ide_db::{ |
13 | source_change::{FileSystemEdit, SourceFileEdit}, | 13 | source_change::{FileSystemEdit, SourceFileEdit}, |
14 | RootDatabase, | 14 | RootDatabase, |
@@ -36,8 +36,10 @@ impl DiagnosticWithFix for UnresolvedModule { | |||
36 | Some(Fix::new( | 36 | Some(Fix::new( |
37 | "Create module", | 37 | "Create module", |
38 | FileSystemEdit::CreateFile { | 38 | FileSystemEdit::CreateFile { |
39 | anchor: self.file.original_file(sema.db), | 39 | dst: AnchoredPathBuf { |
40 | dst: self.candidate.clone(), | 40 | anchor: self.file.original_file(sema.db), |
41 | path: self.candidate.clone(), | ||
42 | }, | ||
41 | } | 43 | } |
42 | .into(), | 44 | .into(), |
43 | unresolved_module.syntax().text_range(), | 45 | unresolved_module.syntax().text_range(), |
diff --git a/crates/ide/src/references/rename.rs b/crates/ide/src/references/rename.rs index 64fe8bd65..44081f210 100644 --- a/crates/ide/src/references/rename.rs +++ b/crates/ide/src/references/rename.rs | |||
@@ -6,7 +6,7 @@ use std::{ | |||
6 | }; | 6 | }; |
7 | 7 | ||
8 | use hir::{Module, ModuleDef, ModuleSource, Semantics}; | 8 | use hir::{Module, ModuleDef, ModuleSource, Semantics}; |
9 | use ide_db::base_db::{FileRange, SourceDatabaseExt}; | 9 | use ide_db::base_db::{AnchoredPathBuf, FileRange, SourceDatabaseExt}; |
10 | use ide_db::{ | 10 | use ide_db::{ |
11 | defs::{Definition, NameClass, NameRefClass}, | 11 | defs::{Definition, NameClass, NameRefClass}, |
12 | RootDatabase, | 12 | RootDatabase, |
@@ -182,12 +182,13 @@ fn rename_mod( | |||
182 | match src.value { | 182 | match src.value { |
183 | ModuleSource::SourceFile(..) => { | 183 | ModuleSource::SourceFile(..) => { |
184 | // mod is defined in path/to/dir/mod.rs | 184 | // mod is defined in path/to/dir/mod.rs |
185 | let dst = if module.is_mod_rs(sema.db) { | 185 | let path = if module.is_mod_rs(sema.db) { |
186 | format!("../{}/mod.rs", new_name) | 186 | format!("../{}/mod.rs", new_name) |
187 | } else { | 187 | } else { |
188 | format!("{}.rs", new_name) | 188 | format!("{}.rs", new_name) |
189 | }; | 189 | }; |
190 | let move_file = FileSystemEdit::MoveFile { src: file_id, anchor: file_id, dst }; | 190 | let dst = AnchoredPathBuf { anchor: file_id, path }; |
191 | let move_file = FileSystemEdit::MoveFile { src: file_id, dst }; | ||
191 | file_system_edits.push(move_file); | 192 | file_system_edits.push(move_file); |
192 | } | 193 | } |
193 | ModuleSource::Module(..) => {} | 194 | ModuleSource::Module(..) => {} |
@@ -771,10 +772,12 @@ mod foo<|>; | |||
771 | src: FileId( | 772 | src: FileId( |
772 | 2, | 773 | 2, |
773 | ), | 774 | ), |
774 | anchor: FileId( | 775 | dst: AnchoredPathBuf { |
775 | 2, | 776 | anchor: FileId( |
776 | ), | 777 | 2, |
777 | dst: "foo2.rs", | 778 | ), |
779 | path: "foo2.rs", | ||
780 | }, | ||
778 | }, | 781 | }, |
779 | ], | 782 | ], |
780 | is_snippet: false, | 783 | is_snippet: false, |
@@ -837,10 +840,12 @@ use crate::foo<|>::FooContent; | |||
837 | src: FileId( | 840 | src: FileId( |
838 | 1, | 841 | 1, |
839 | ), | 842 | ), |
840 | anchor: FileId( | 843 | dst: AnchoredPathBuf { |
841 | 1, | 844 | anchor: FileId( |
842 | ), | 845 | 1, |
843 | dst: "quux.rs", | 846 | ), |
847 | path: "quux.rs", | ||
848 | }, | ||
844 | }, | 849 | }, |
845 | ], | 850 | ], |
846 | is_snippet: false, | 851 | is_snippet: false, |
@@ -884,10 +889,12 @@ mod fo<|>o; | |||
884 | src: FileId( | 889 | src: FileId( |
885 | 1, | 890 | 1, |
886 | ), | 891 | ), |
887 | anchor: FileId( | 892 | dst: AnchoredPathBuf { |
888 | 1, | 893 | anchor: FileId( |
889 | ), | 894 | 1, |
890 | dst: "../foo2/mod.rs", | 895 | ), |
896 | path: "../foo2/mod.rs", | ||
897 | }, | ||
891 | }, | 898 | }, |
892 | ], | 899 | ], |
893 | is_snippet: false, | 900 | is_snippet: false, |
@@ -932,10 +939,12 @@ mod outer { mod fo<|>o; } | |||
932 | src: FileId( | 939 | src: FileId( |
933 | 1, | 940 | 1, |
934 | ), | 941 | ), |
935 | anchor: FileId( | 942 | dst: AnchoredPathBuf { |
936 | 1, | 943 | anchor: FileId( |
937 | ), | 944 | 1, |
938 | dst: "bar.rs", | 945 | ), |
946 | path: "bar.rs", | ||
947 | }, | ||
939 | }, | 948 | }, |
940 | ], | 949 | ], |
941 | is_snippet: false, | 950 | is_snippet: false, |
@@ -1016,10 +1025,12 @@ pub mod foo<|>; | |||
1016 | src: FileId( | 1025 | src: FileId( |
1017 | 2, | 1026 | 2, |
1018 | ), | 1027 | ), |
1019 | anchor: FileId( | 1028 | dst: AnchoredPathBuf { |
1020 | 2, | 1029 | anchor: FileId( |
1021 | ), | 1030 | 2, |
1022 | dst: "foo2.rs", | 1031 | ), |
1032 | path: "foo2.rs", | ||
1033 | }, | ||
1023 | }, | 1034 | }, |
1024 | ], | 1035 | ], |
1025 | is_snippet: false, | 1036 | is_snippet: false, |