diff options
Diffstat (limited to 'crates/ra_db')
-rw-r--r-- | crates/ra_db/src/input.rs | 6 | ||||
-rw-r--r-- | crates/ra_db/src/lib.rs | 26 |
2 files changed, 28 insertions, 4 deletions
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index 23148096c..cae51b02c 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs | |||
@@ -48,9 +48,6 @@ impl SourceRoot { | |||
48 | pub fn new_library() -> SourceRoot { | 48 | pub fn new_library() -> SourceRoot { |
49 | SourceRoot { is_library: true, ..SourceRoot::new() } | 49 | SourceRoot { is_library: true, ..SourceRoot::new() } |
50 | } | 50 | } |
51 | pub fn file_by_relative_path(&self, path: &RelativePath) -> Option<FileId> { | ||
52 | self.files.get(path).copied() | ||
53 | } | ||
54 | pub fn insert_file(&mut self, path: RelativePathBuf, file_id: FileId) { | 51 | pub fn insert_file(&mut self, path: RelativePathBuf, file_id: FileId) { |
55 | self.files.insert(path, file_id); | 52 | self.files.insert(path, file_id); |
56 | } | 53 | } |
@@ -60,6 +57,9 @@ impl SourceRoot { | |||
60 | pub fn walk(&self) -> impl Iterator<Item = FileId> + '_ { | 57 | pub fn walk(&self) -> impl Iterator<Item = FileId> + '_ { |
61 | self.files.values().copied() | 58 | self.files.values().copied() |
62 | } | 59 | } |
60 | pub(crate) fn file_by_relative_path(&self, path: &RelativePath) -> Option<FileId> { | ||
61 | self.files.get(path).copied() | ||
62 | } | ||
63 | } | 63 | } |
64 | 64 | ||
65 | /// `CrateGraph` is a bit of information which turns a set of text files into a | 65 | /// `CrateGraph` is a bit of information which turns a set of text files into a |
diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs index 603daed37..4d3a9c036 100644 --- a/crates/ra_db/src/lib.rs +++ b/crates/ra_db/src/lib.rs | |||
@@ -6,7 +6,7 @@ use std::{panic, sync::Arc}; | |||
6 | 6 | ||
7 | use ra_prof::profile; | 7 | use ra_prof::profile; |
8 | use ra_syntax::{ast, Parse, SourceFile, TextRange, TextUnit}; | 8 | use ra_syntax::{ast, Parse, SourceFile, TextRange, TextUnit}; |
9 | use relative_path::RelativePathBuf; | 9 | use relative_path::{RelativePath, RelativePathBuf}; |
10 | 10 | ||
11 | pub use crate::{ | 11 | pub use crate::{ |
12 | cancellation::Canceled, | 12 | cancellation::Canceled, |
@@ -71,6 +71,11 @@ pub trait SourceDatabase: CheckCanceled + std::fmt::Debug { | |||
71 | /// Text of the file. | 71 | /// Text of the file. |
72 | #[salsa::input] | 72 | #[salsa::input] |
73 | fn file_text(&self, file_id: FileId) -> Arc<String>; | 73 | fn file_text(&self, file_id: FileId) -> Arc<String>; |
74 | |||
75 | #[salsa::transparent] | ||
76 | fn resolve_relative_path(&self, anchor: FileId, relative_path: &RelativePath) | ||
77 | -> Option<FileId>; | ||
78 | |||
74 | // Parses the file into the syntax tree. | 79 | // Parses the file into the syntax tree. |
75 | #[salsa::invoke(parse_query)] | 80 | #[salsa::invoke(parse_query)] |
76 | fn parse(&self, file_id: FileId) -> Parse<ast::SourceFile>; | 81 | fn parse(&self, file_id: FileId) -> Parse<ast::SourceFile>; |
@@ -89,6 +94,25 @@ pub trait SourceDatabase: CheckCanceled + std::fmt::Debug { | |||
89 | fn crate_graph(&self) -> Arc<CrateGraph>; | 94 | fn crate_graph(&self) -> Arc<CrateGraph>; |
90 | } | 95 | } |
91 | 96 | ||
97 | fn resolve_relative_path( | ||
98 | db: &impl SourceDatabase, | ||
99 | anchor: FileId, | ||
100 | relative_path: &RelativePath, | ||
101 | ) -> Option<FileId> { | ||
102 | let path = { | ||
103 | let mut path = db.file_relative_path(anchor); | ||
104 | // Workaround for relative path API: turn `lib.rs` into ``. | ||
105 | if !path.pop() { | ||
106 | path = RelativePathBuf::default(); | ||
107 | } | ||
108 | path.push(relative_path); | ||
109 | path.normalize() | ||
110 | }; | ||
111 | let source_root = db.file_source_root(anchor); | ||
112 | let source_root = db.source_root(source_root); | ||
113 | source_root.file_by_relative_path(&path) | ||
114 | } | ||
115 | |||
92 | fn source_root_crates(db: &impl SourceDatabase, id: SourceRootId) -> Arc<Vec<CrateId>> { | 116 | fn source_root_crates(db: &impl SourceDatabase, id: SourceRootId) -> Arc<Vec<CrateId>> { |
93 | let root = db.source_root(id); | 117 | let root = db.source_root(id); |
94 | let graph = db.crate_graph(); | 118 | let graph = db.crate_graph(); |