aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_db
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_db')
-rw-r--r--crates/ra_db/src/lib.rs26
1 files changed, 25 insertions, 1 deletions
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
7use ra_prof::profile; 7use ra_prof::profile;
8use ra_syntax::{ast, Parse, SourceFile, TextRange, TextUnit}; 8use ra_syntax::{ast, Parse, SourceFile, TextRange, TextUnit};
9use relative_path::RelativePathBuf; 9use relative_path::{RelativePath, RelativePathBuf};
10 10
11pub use crate::{ 11pub 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
97fn 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
92fn source_root_crates(db: &impl SourceDatabase, id: SourceRootId) -> Arc<Vec<CrateId>> { 116fn 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();