Migrate to privacy as per review commets

This commit is contained in:
veetaha 2020-04-01 13:40:40 +03:00
parent bef899aa78
commit 6190caeeae
6 changed files with 25 additions and 15 deletions

View file

@ -58,9 +58,9 @@ pub enum ProjectWorkspace {
#[derive(Clone)] #[derive(Clone)]
pub struct PackageRoot { pub struct PackageRoot {
/// Path to the root folder /// Path to the root folder
pub path: PathBuf, path: PathBuf,
/// Is a member of the current workspace /// Is a member of the current workspace
pub is_member: bool, is_member: bool,
} }
impl PackageRoot { impl PackageRoot {
pub fn new_member(path: PathBuf) -> PackageRoot { pub fn new_member(path: PathBuf) -> PackageRoot {
@ -69,6 +69,12 @@ impl PackageRoot {
pub fn new_non_member(path: PathBuf) -> PackageRoot { pub fn new_non_member(path: PathBuf) -> PackageRoot {
Self { path, is_member: false } Self { path, is_member: false }
} }
pub fn path(&self) -> &Path {
&self.path
}
pub fn is_member(&self) -> bool {
self.is_member
}
} }
impl ProjectWorkspace { impl ProjectWorkspace {

View file

@ -65,10 +65,10 @@ pub fn analysis_bench(
roots roots
.iter() .iter()
.find_map(|(source_root_id, project_root)| { .find_map(|(source_root_id, project_root)| {
if project_root.is_member { if project_root.is_member() {
for file_id in db.source_root(*source_root_id).walk() { for file_id in db.source_root(*source_root_id).walk() {
let rel_path = db.file_relative_path(file_id); let rel_path = db.file_relative_path(file_id);
let abs_path = rel_path.to_path(&project_root.path); let abs_path = rel_path.to_path(project_root.path());
if abs_path == path { if abs_path == path {
return Some(file_id); return Some(file_id);
} }

View file

@ -39,7 +39,7 @@ pub fn analysis_stats(
roots roots
.into_iter() .into_iter()
.filter_map(|(source_root_id, project_root)| { .filter_map(|(source_root_id, project_root)| {
if with_deps || project_root.is_member { if with_deps || project_root.is_member() {
Some(source_root_id) Some(source_root_id)
} else { } else {
None None

View file

@ -45,9 +45,9 @@ pub(crate) fn load_cargo(
.iter() .iter()
.map(|pkg_root| { .map(|pkg_root| {
RootEntry::new( RootEntry::new(
pkg_root.path.clone(), pkg_root.path().to_owned(),
RustPackageFilterBuilder::default() RustPackageFilterBuilder::default()
.set_member(pkg_root.is_member) .set_member(pkg_root.is_member())
.into_vfs_filter(), .into_vfs_filter(),
) )
}) })
@ -60,8 +60,11 @@ pub(crate) fn load_cargo(
.into_iter() .into_iter()
.map(|vfs_root| { .map(|vfs_root| {
let source_root_id = vfs_root_to_id(vfs_root); let source_root_id = vfs_root_to_id(vfs_root);
let project_root = let project_root = project_roots
project_roots.iter().find(|it| it.path == vfs.root2path(vfs_root)).unwrap().clone(); .iter()
.find(|it| it.path() == vfs.root2path(vfs_root))
.unwrap()
.clone();
(source_root_id, project_root) (source_root_id, project_root)
}) })
.collect::<FxHashMap<_, _>>(); .collect::<FxHashMap<_, _>>();
@ -93,7 +96,7 @@ pub(crate) fn load(
match change { match change {
VfsChange::AddRoot { root, files } => { VfsChange::AddRoot { root, files } => {
let source_root_id = vfs_root_to_id(root); let source_root_id = vfs_root_to_id(root);
let is_local = source_roots[&source_root_id].is_member; let is_local = source_roots[&source_root_id].is_member();
log::debug!( log::debug!(
"loaded source root {:?} with path {:?}", "loaded source root {:?} with path {:?}",
source_root_id, source_root_id,
@ -102,7 +105,7 @@ pub(crate) fn load(
analysis_change.add_root(source_root_id, is_local); analysis_change.add_root(source_root_id, is_local);
analysis_change.set_debug_root_path( analysis_change.set_debug_root_path(
source_root_id, source_root_id,
source_roots[&source_root_id].path.display().to_string(), source_roots[&source_root_id].path().display().to_string(),
); );
let vfs_root_path = vfs.root2path(root); let vfs_root_path = vfs.root2path(root);

View file

@ -23,6 +23,7 @@ use lsp_types::{
use ra_flycheck::{url_from_path_with_drive_lowercasing, CheckTask}; use ra_flycheck::{url_from_path_with_drive_lowercasing, CheckTask};
use ra_ide::{Canceled, FileId, LibraryData, SourceRootId}; use ra_ide::{Canceled, FileId, LibraryData, SourceRootId};
use ra_prof::profile; use ra_prof::profile;
use ra_project_model::{PackageRoot, ProjectWorkspace};
use ra_vfs::{VfsFile, VfsTask, Watch}; use ra_vfs::{VfsFile, VfsTask, Watch};
use relative_path::RelativePathBuf; use relative_path::RelativePathBuf;
use rustc_hash::FxHashSet; use rustc_hash::FxHashSet;
@ -131,9 +132,9 @@ pub fn main_loop(ws_roots: Vec<PathBuf>, config: Config, connection: Connection)
let registration_options = req::DidChangeWatchedFilesRegistrationOptions { let registration_options = req::DidChangeWatchedFilesRegistrationOptions {
watchers: workspaces watchers: workspaces
.iter() .iter()
.flat_map(|ws| ws.to_roots()) .flat_map(ProjectWorkspace::to_roots)
.filter(|root| root.is_member) .filter(PackageRoot::is_member)
.map(|root| format!("{}/**/*.rs", root.path.display())) .map(|root| format!("{}/**/*.rs", root.path().display()))
.map(|glob_pattern| req::FileSystemWatcher { glob_pattern, kind: None }) .map(|glob_pattern| req::FileSystemWatcher { glob_pattern, kind: None })
.collect(), .collect(),
}; };

View file

@ -101,7 +101,7 @@ impl WorldState {
.iter() .iter()
.map(|path| RootEntry::new(path.clone(), create_filter(true))) .map(|path| RootEntry::new(path.clone(), create_filter(true)))
.chain(workspaces.iter().flat_map(ProjectWorkspace::to_roots).map(|pkg_root| { .chain(workspaces.iter().flat_map(ProjectWorkspace::to_roots).map(|pkg_root| {
RootEntry::new(pkg_root.path, create_filter(pkg_root.is_member)) RootEntry::new(pkg_root.path().to_owned(), create_filter(pkg_root.is_member()))
})) }))
.chain( .chain(
extern_dirs extern_dirs