From e44c7ce2004913d3e928bc03df64647c6059ae0e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 9 Oct 2019 14:27:37 +0300 Subject: remove last traces of source roots from hir --- crates/ra_db/src/lib.rs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'crates/ra_db/src/lib.rs') 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}; use ra_prof::profile; use ra_syntax::{ast, Parse, SourceFile, TextRange, TextUnit}; -use relative_path::RelativePathBuf; +use relative_path::{RelativePath, RelativePathBuf}; pub use crate::{ cancellation::Canceled, @@ -71,6 +71,11 @@ pub trait SourceDatabase: CheckCanceled + std::fmt::Debug { /// Text of the file. #[salsa::input] fn file_text(&self, file_id: FileId) -> Arc; + + #[salsa::transparent] + fn resolve_relative_path(&self, anchor: FileId, relative_path: &RelativePath) + -> Option; + // Parses the file into the syntax tree. #[salsa::invoke(parse_query)] fn parse(&self, file_id: FileId) -> Parse; @@ -89,6 +94,25 @@ pub trait SourceDatabase: CheckCanceled + std::fmt::Debug { fn crate_graph(&self) -> Arc; } +fn resolve_relative_path( + db: &impl SourceDatabase, + anchor: FileId, + relative_path: &RelativePath, +) -> Option { + let path = { + let mut path = db.file_relative_path(anchor); + // Workaround for relative path API: turn `lib.rs` into ``. + if !path.pop() { + path = RelativePathBuf::default(); + } + path.push(relative_path); + path.normalize() + }; + let source_root = db.file_source_root(anchor); + let source_root = db.source_root(source_root); + source_root.file_by_relative_path(&path) +} + fn source_root_crates(db: &impl SourceDatabase, id: SourceRootId) -> Arc> { let root = db.source_root(id); let graph = db.crate_graph(); -- cgit v1.2.3