mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 12:33:33 +00:00
kill file resolver
This commit is contained in:
parent
85290bc134
commit
18aac1df45
3 changed files with 1 additions and 94 deletions
|
@ -1,76 +0,0 @@
|
||||||
use std::{
|
|
||||||
sync::Arc,
|
|
||||||
hash::{Hash, Hasher},
|
|
||||||
fmt,
|
|
||||||
};
|
|
||||||
|
|
||||||
use relative_path::RelativePath;
|
|
||||||
|
|
||||||
use crate::input::FileId;
|
|
||||||
|
|
||||||
pub trait FileResolver: fmt::Debug + Send + Sync + 'static {
|
|
||||||
fn file_stem(&self, file_id: FileId) -> String;
|
|
||||||
fn resolve(&self, file_id: FileId, path: &RelativePath) -> Option<FileId>;
|
|
||||||
fn debug_path(&self, _1file_id: FileId) -> Option<std::path::PathBuf> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct FileResolverImp {
|
|
||||||
inner: Arc<FileResolver>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PartialEq for FileResolverImp {
|
|
||||||
fn eq(&self, other: &FileResolverImp) -> bool {
|
|
||||||
self.inner() == other.inner()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Eq for FileResolverImp {}
|
|
||||||
|
|
||||||
impl Hash for FileResolverImp {
|
|
||||||
fn hash<H: Hasher>(&self, hasher: &mut H) {
|
|
||||||
self.inner().hash(hasher);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FileResolverImp {
|
|
||||||
pub fn new(inner: Arc<FileResolver>) -> FileResolverImp {
|
|
||||||
FileResolverImp { inner }
|
|
||||||
}
|
|
||||||
pub fn file_stem(&self, file_id: FileId) -> String {
|
|
||||||
self.inner.file_stem(file_id)
|
|
||||||
}
|
|
||||||
pub fn resolve(&self, file_id: FileId, path: &RelativePath) -> Option<FileId> {
|
|
||||||
self.inner.resolve(file_id, path)
|
|
||||||
}
|
|
||||||
pub fn debug_path(&self, file_id: FileId) -> Option<std::path::PathBuf> {
|
|
||||||
self.inner.debug_path(file_id)
|
|
||||||
}
|
|
||||||
fn inner(&self) -> *const FileResolver {
|
|
||||||
&*self.inner
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for FileResolverImp {
|
|
||||||
fn default() -> FileResolverImp {
|
|
||||||
#[derive(Debug)]
|
|
||||||
struct DummyResolver;
|
|
||||||
impl FileResolver for DummyResolver {
|
|
||||||
fn file_stem(&self, _file_: FileId) -> String {
|
|
||||||
panic!("file resolver not set")
|
|
||||||
}
|
|
||||||
fn resolve(
|
|
||||||
&self,
|
|
||||||
_file_id: FileId,
|
|
||||||
_path: &::relative_path::RelativePath,
|
|
||||||
) -> Option<FileId> {
|
|
||||||
panic!("file resolver not set")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
FileResolverImp {
|
|
||||||
inner: Arc::new(DummyResolver),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +1,5 @@
|
||||||
//! ra_db defines basic database traits. Concrete DB is defined by ra_analysis.
|
//! ra_db defines basic database traits. Concrete DB is defined by ra_analysis.
|
||||||
mod syntax_ptr;
|
mod syntax_ptr;
|
||||||
mod file_resolver;
|
|
||||||
mod input;
|
mod input;
|
||||||
mod loc2id;
|
mod loc2id;
|
||||||
pub mod mock;
|
pub mod mock;
|
||||||
|
@ -24,7 +23,6 @@ impl std::error::Error for Canceled {}
|
||||||
|
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
syntax_ptr::LocalSyntaxPtr,
|
syntax_ptr::LocalSyntaxPtr,
|
||||||
file_resolver::{FileResolver, FileResolverImp},
|
|
||||||
input::{
|
input::{
|
||||||
FilesDatabase, FileId, CrateId, SourceRoot, SourceRootId, CrateGraph, WORKSPACE,
|
FilesDatabase, FileId, CrateId, SourceRoot, SourceRootId, CrateGraph, WORKSPACE,
|
||||||
FileTextQuery, FileSourceRootQuery, SourceRootQuery, LibrariesQuery, CrateGraphQuery,
|
FileTextQuery, FileSourceRootQuery, SourceRootQuery, LibrariesQuery, CrateGraphQuery,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
use relative_path::{RelativePath, RelativePathBuf};
|
use relative_path::{RelativePath, RelativePathBuf};
|
||||||
|
|
||||||
use crate::{FileId, FileResolver};
|
use crate::{FileId};
|
||||||
|
|
||||||
#[derive(Default, Debug, Clone)]
|
#[derive(Default, Debug, Clone)]
|
||||||
pub struct FileMap(Vec<(FileId, RelativePathBuf)>);
|
pub struct FileMap(Vec<(FileId, RelativePathBuf)>);
|
||||||
|
@ -27,19 +27,4 @@ impl FileMap {
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(id, path)| (*id, path.as_relative_path()))
|
.map(|(id, path)| (*id, path.as_relative_path()))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn path(&self, id: FileId) -> &RelativePath {
|
|
||||||
self.iter().find(|&(it, _)| it == id).unwrap().1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FileResolver for FileMap {
|
|
||||||
fn file_stem(&self, id: FileId) -> String {
|
|
||||||
self.path(id).file_stem().unwrap().to_string()
|
|
||||||
}
|
|
||||||
fn resolve(&self, id: FileId, rel: &RelativePath) -> Option<FileId> {
|
|
||||||
let path = self.path(id).join(rel).normalize();
|
|
||||||
let id = self.iter().find(|&(_, p)| path == p)?.0;
|
|
||||||
Some(id)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue