diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-06-05 14:15:31 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-06-05 14:15:31 +0100 |
commit | d06df2c3e7e2b6eacda29cb1c715f1a1f2ada032 (patch) | |
tree | a1a1439aa2cd1b4cba3c559f41bfbde24a08aa36 /crates | |
parent | f98d057218ca30d052da2a119fa0b3108ba3a091 (diff) | |
parent | cb9d9040f7e5cb5971deabe3b66045010576a689 (diff) |
Merge #4756
4756: Cleanup resolution of file paths r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_db/src/lib.rs | 26 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/mod_resolution.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/test_db.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/builtin_macro.rs | 4 | ||||
-rw-r--r-- | crates/ra_hir_expand/src/test_db.rs | 8 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/test_db.rs | 8 | ||||
-rw-r--r-- | crates/ra_ide_db/src/lib.rs | 8 | ||||
-rw-r--r-- | crates/rust-analyzer/tests/heavy_tests/main.rs | 62 |
8 files changed, 36 insertions, 90 deletions
diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs index fd4280de2..2e63cb46e 100644 --- a/crates/ra_db/src/lib.rs +++ b/crates/ra_db/src/lib.rs | |||
@@ -89,8 +89,7 @@ pub const DEFAULT_LRU_CAP: usize = 128; | |||
89 | pub trait FileLoader { | 89 | pub trait FileLoader { |
90 | /// Text of the file. | 90 | /// Text of the file. |
91 | fn file_text(&self, file_id: FileId) -> Arc<String>; | 91 | fn file_text(&self, file_id: FileId) -> Arc<String>; |
92 | fn resolve_relative_path(&self, anchor: FileId, relative_path: &RelativePath) | 92 | fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId>; |
93 | -> Option<FileId>; | ||
94 | fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>>; | 93 | fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>>; |
95 | 94 | ||
96 | fn resolve_extern_path( | 95 | fn resolve_extern_path( |
@@ -155,20 +154,21 @@ impl<T: SourceDatabaseExt> FileLoader for FileLoaderDelegate<&'_ T> { | |||
155 | fn file_text(&self, file_id: FileId) -> Arc<String> { | 154 | fn file_text(&self, file_id: FileId) -> Arc<String> { |
156 | SourceDatabaseExt::file_text(self.0, file_id) | 155 | SourceDatabaseExt::file_text(self.0, file_id) |
157 | } | 156 | } |
158 | fn resolve_relative_path( | 157 | /// Note that we intentionally accept a `&str` and not a `&Path` here. This |
159 | &self, | 158 | /// method exists to handle `#[path = "/some/path.rs"] mod foo;` and such, |
160 | anchor: FileId, | 159 | /// so the input is guaranteed to be utf-8 string. We might introduce |
161 | relative_path: &RelativePath, | 160 | /// `struct StrPath(str)` for clarity some day, but it's a bit messy, so we |
162 | ) -> Option<FileId> { | 161 | /// get by with a `&str` for the time being. |
163 | let path = { | 162 | fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> { |
164 | let mut path = self.0.file_relative_path(anchor); | 163 | let rel_path = { |
165 | assert!(path.pop()); | 164 | let mut rel_path = self.0.file_relative_path(anchor); |
166 | path.push(relative_path); | 165 | assert!(rel_path.pop()); |
167 | path.normalize() | 166 | rel_path.push(path); |
167 | rel_path.normalize() | ||
168 | }; | 168 | }; |
169 | let source_root = self.0.file_source_root(anchor); | 169 | let source_root = self.0.file_source_root(anchor); |
170 | let source_root = self.0.source_root(source_root); | 170 | let source_root = self.0.source_root(source_root); |
171 | source_root.file_by_relative_path(&path) | 171 | source_root.file_by_relative_path(&rel_path) |
172 | } | 172 | } |
173 | 173 | ||
174 | fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> { | 174 | fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> { |
diff --git a/crates/ra_hir_def/src/nameres/mod_resolution.rs b/crates/ra_hir_def/src/nameres/mod_resolution.rs index 386c5cade..cede4a6fc 100644 --- a/crates/ra_hir_def/src/nameres/mod_resolution.rs +++ b/crates/ra_hir_def/src/nameres/mod_resolution.rs | |||
@@ -61,7 +61,7 @@ impl ModDir { | |||
61 | }; | 61 | }; |
62 | 62 | ||
63 | for candidate in candidate_files.iter() { | 63 | for candidate in candidate_files.iter() { |
64 | if let Some(file_id) = db.resolve_relative_path(file_id, candidate) { | 64 | if let Some(file_id) = db.resolve_path(file_id, candidate.as_str()) { |
65 | let mut root_non_dir_owner = false; | 65 | let mut root_non_dir_owner = false; |
66 | let mut mod_path = RelativePathBuf::new(); | 66 | let mut mod_path = RelativePathBuf::new(); |
67 | if !(candidate.ends_with("mod.rs") || attr_path.is_some()) { | 67 | if !(candidate.ends_with("mod.rs") || attr_path.is_some()) { |
diff --git a/crates/ra_hir_def/src/test_db.rs b/crates/ra_hir_def/src/test_db.rs index eb83dee79..e7a5182f0 100644 --- a/crates/ra_hir_def/src/test_db.rs +++ b/crates/ra_hir_def/src/test_db.rs | |||
@@ -58,12 +58,8 @@ impl FileLoader for TestDB { | |||
58 | fn file_text(&self, file_id: FileId) -> Arc<String> { | 58 | fn file_text(&self, file_id: FileId) -> Arc<String> { |
59 | FileLoaderDelegate(self).file_text(file_id) | 59 | FileLoaderDelegate(self).file_text(file_id) |
60 | } | 60 | } |
61 | fn resolve_relative_path( | 61 | fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> { |
62 | &self, | 62 | FileLoaderDelegate(self).resolve_path(anchor, path) |
63 | anchor: FileId, | ||
64 | relative_path: &RelativePath, | ||
65 | ) -> Option<FileId> { | ||
66 | FileLoaderDelegate(self).resolve_relative_path(anchor, relative_path) | ||
67 | } | 63 | } |
68 | fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> { | 64 | fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> { |
69 | FileLoaderDelegate(self).relevant_crates(file_id) | 65 | FileLoaderDelegate(self).relevant_crates(file_id) |
diff --git a/crates/ra_hir_expand/src/builtin_macro.rs b/crates/ra_hir_expand/src/builtin_macro.rs index 3bce8f673..eec5fb8eb 100644 --- a/crates/ra_hir_expand/src/builtin_macro.rs +++ b/crates/ra_hir_expand/src/builtin_macro.rs | |||
@@ -8,7 +8,7 @@ use crate::{ | |||
8 | use crate::{quote, EagerMacroId, LazyMacroId, MacroCallId}; | 8 | use crate::{quote, EagerMacroId, LazyMacroId, MacroCallId}; |
9 | use either::Either; | 9 | use either::Either; |
10 | use mbe::parse_to_token_tree; | 10 | use mbe::parse_to_token_tree; |
11 | use ra_db::{FileId, RelativePath}; | 11 | use ra_db::FileId; |
12 | use ra_parser::FragmentKind; | 12 | use ra_parser::FragmentKind; |
13 | 13 | ||
14 | macro_rules! register_builtin { | 14 | macro_rules! register_builtin { |
@@ -297,7 +297,7 @@ fn relative_file(db: &dyn AstDatabase, call_id: MacroCallId, path: &str) -> Opti | |||
297 | let call_site = call_id.as_file().original_file(db); | 297 | let call_site = call_id.as_file().original_file(db); |
298 | 298 | ||
299 | // Handle trivial case | 299 | // Handle trivial case |
300 | if let Some(res) = db.resolve_relative_path(call_site, &RelativePath::new(&path)) { | 300 | if let Some(res) = db.resolve_path(call_site, path) { |
301 | // Prevent include itself | 301 | // Prevent include itself |
302 | return if res == call_site { None } else { Some(res) }; | 302 | return if res == call_site { None } else { Some(res) }; |
303 | } | 303 | } |
diff --git a/crates/ra_hir_expand/src/test_db.rs b/crates/ra_hir_expand/src/test_db.rs index c1fb762de..765a2f6d1 100644 --- a/crates/ra_hir_expand/src/test_db.rs +++ b/crates/ra_hir_expand/src/test_db.rs | |||
@@ -41,12 +41,8 @@ impl FileLoader for TestDB { | |||
41 | fn file_text(&self, file_id: FileId) -> Arc<String> { | 41 | fn file_text(&self, file_id: FileId) -> Arc<String> { |
42 | FileLoaderDelegate(self).file_text(file_id) | 42 | FileLoaderDelegate(self).file_text(file_id) |
43 | } | 43 | } |
44 | fn resolve_relative_path( | 44 | fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> { |
45 | &self, | 45 | FileLoaderDelegate(self).resolve_path(anchor, path) |
46 | anchor: FileId, | ||
47 | relative_path: &RelativePath, | ||
48 | ) -> Option<FileId> { | ||
49 | FileLoaderDelegate(self).resolve_relative_path(anchor, relative_path) | ||
50 | } | 46 | } |
51 | fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> { | 47 | fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> { |
52 | FileLoaderDelegate(self).relevant_crates(file_id) | 48 | FileLoaderDelegate(self).relevant_crates(file_id) |
diff --git a/crates/ra_hir_ty/src/test_db.rs b/crates/ra_hir_ty/src/test_db.rs index 8498d3d96..21a3bdfd1 100644 --- a/crates/ra_hir_ty/src/test_db.rs +++ b/crates/ra_hir_ty/src/test_db.rs | |||
@@ -72,12 +72,8 @@ impl FileLoader for TestDB { | |||
72 | fn file_text(&self, file_id: FileId) -> Arc<String> { | 72 | fn file_text(&self, file_id: FileId) -> Arc<String> { |
73 | FileLoaderDelegate(self).file_text(file_id) | 73 | FileLoaderDelegate(self).file_text(file_id) |
74 | } | 74 | } |
75 | fn resolve_relative_path( | 75 | fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> { |
76 | &self, | 76 | FileLoaderDelegate(self).resolve_path(anchor, path) |
77 | anchor: FileId, | ||
78 | relative_path: &RelativePath, | ||
79 | ) -> Option<FileId> { | ||
80 | FileLoaderDelegate(self).resolve_relative_path(anchor, relative_path) | ||
81 | } | 77 | } |
82 | fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> { | 78 | fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> { |
83 | FileLoaderDelegate(self).relevant_crates(file_id) | 79 | FileLoaderDelegate(self).relevant_crates(file_id) |
diff --git a/crates/ra_ide_db/src/lib.rs b/crates/ra_ide_db/src/lib.rs index 1b74e6558..93d5891a0 100644 --- a/crates/ra_ide_db/src/lib.rs +++ b/crates/ra_ide_db/src/lib.rs | |||
@@ -57,12 +57,8 @@ impl FileLoader for RootDatabase { | |||
57 | fn file_text(&self, file_id: FileId) -> Arc<String> { | 57 | fn file_text(&self, file_id: FileId) -> Arc<String> { |
58 | FileLoaderDelegate(self).file_text(file_id) | 58 | FileLoaderDelegate(self).file_text(file_id) |
59 | } | 59 | } |
60 | fn resolve_relative_path( | 60 | fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> { |
61 | &self, | 61 | FileLoaderDelegate(self).resolve_path(anchor, path) |
62 | anchor: FileId, | ||
63 | relative_path: &RelativePath, | ||
64 | ) -> Option<FileId> { | ||
65 | FileLoaderDelegate(self).resolve_relative_path(anchor, relative_path) | ||
66 | } | 62 | } |
67 | fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> { | 63 | fn relevant_crates(&self, file_id: FileId) -> Arc<Vec<CrateId>> { |
68 | FileLoaderDelegate(self).relevant_crates(file_id) | 64 | FileLoaderDelegate(self).relevant_crates(file_id) |
diff --git a/crates/rust-analyzer/tests/heavy_tests/main.rs b/crates/rust-analyzer/tests/heavy_tests/main.rs index ad3476310..237aaa2a1 100644 --- a/crates/rust-analyzer/tests/heavy_tests/main.rs +++ b/crates/rust-analyzer/tests/heavy_tests/main.rs | |||
@@ -523,8 +523,6 @@ fn main() { | |||
523 | let vb = B; | 523 | let vb = B; |
524 | message(); | 524 | message(); |
525 | } | 525 | } |
526 | |||
527 | fn main() { message(); } | ||
528 | "###, | 526 | "###, |
529 | ) | 527 | ) |
530 | .with_config(|config| { | 528 | .with_config(|config| { |
@@ -552,34 +550,16 @@ fn main() { message(); } | |||
552 | }, | 550 | }, |
553 | json!([{ | 551 | json!([{ |
554 | "originSelectionRange": { | 552 | "originSelectionRange": { |
555 | "end": { | 553 | "end": { "character": 10, "line": 12 }, |
556 | "character": 10, | 554 | "start": { "character": 8, "line": 12 } |
557 | "line": 12 | ||
558 | }, | ||
559 | "start": { | ||
560 | "character": 8, | ||
561 | "line": 12 | ||
562 | } | ||
563 | }, | 555 | }, |
564 | "targetRange": { | 556 | "targetRange": { |
565 | "end": { | 557 | "end": { "character": 9, "line": 3 }, |
566 | "character": 9, | 558 | "start": { "character": 0, "line": 2 } |
567 | "line": 3 | ||
568 | }, | ||
569 | "start": { | ||
570 | "character": 0, | ||
571 | "line": 2 | ||
572 | } | ||
573 | }, | 559 | }, |
574 | "targetSelectionRange": { | 560 | "targetSelectionRange": { |
575 | "end": { | 561 | "end": { "character": 8, "line": 3 }, |
576 | "character": 8, | 562 | "start": { "character": 7, "line": 3 } |
577 | "line": 3 | ||
578 | }, | ||
579 | "start": { | ||
580 | "character": 7, | ||
581 | "line": 3 | ||
582 | } | ||
583 | }, | 563 | }, |
584 | "targetUri": "file:///[..]src/main.rs" | 564 | "targetUri": "file:///[..]src/main.rs" |
585 | }]), | 565 | }]), |
@@ -595,34 +575,16 @@ fn main() { message(); } | |||
595 | }, | 575 | }, |
596 | json!([{ | 576 | json!([{ |
597 | "originSelectionRange": { | 577 | "originSelectionRange": { |
598 | "end": { | 578 | "end": { "character": 10, "line": 13 }, |
599 | "character": 10, | 579 | "start": { "character": 8, "line":13 } |
600 | "line": 13 | ||
601 | }, | ||
602 | "start": { | ||
603 | "character": 8, | ||
604 | "line":13 | ||
605 | } | ||
606 | }, | 580 | }, |
607 | "targetRange": { | 581 | "targetRange": { |
608 | "end": { | 582 | "end": { "character": 9, "line": 7 }, |
609 | "character": 9, | 583 | "start": { "character": 0, "line":6 } |
610 | "line": 7 | ||
611 | }, | ||
612 | "start": { | ||
613 | "character": 0, | ||
614 | "line":6 | ||
615 | } | ||
616 | }, | 584 | }, |
617 | "targetSelectionRange": { | 585 | "targetSelectionRange": { |
618 | "end": { | 586 | "end": { "character": 8, "line": 7 }, |
619 | "character": 8, | 587 | "start": { "character": 7, "line": 7 } |
620 | "line": 7 | ||
621 | }, | ||
622 | "start": { | ||
623 | "character": 7, | ||
624 | "line": 7 | ||
625 | } | ||
626 | }, | 588 | }, |
627 | "targetUri": "file:///[..]src/main.rs" | 589 | "targetUri": "file:///[..]src/main.rs" |
628 | }]), | 590 | }]), |