From 6190caeeaedd026e02640fb30691d835d72a8899 Mon Sep 17 00:00:00 2001 From: veetaha Date: Wed, 1 Apr 2020 13:40:40 +0300 Subject: Migrate to privacy as per review commets --- crates/ra_project_model/src/lib.rs | 10 ++++++++-- crates/rust-analyzer/src/cli/analysis_bench.rs | 4 ++-- crates/rust-analyzer/src/cli/analysis_stats.rs | 2 +- crates/rust-analyzer/src/cli/load_cargo.rs | 15 +++++++++------ crates/rust-analyzer/src/main_loop.rs | 7 ++++--- crates/rust-analyzer/src/world.rs | 2 +- 6 files changed, 25 insertions(+), 15 deletions(-) diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index ec8574952..0ab64a1e0 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs @@ -58,9 +58,9 @@ pub enum ProjectWorkspace { #[derive(Clone)] pub struct PackageRoot { /// Path to the root folder - pub path: PathBuf, + path: PathBuf, /// Is a member of the current workspace - pub is_member: bool, + is_member: bool, } impl PackageRoot { pub fn new_member(path: PathBuf) -> PackageRoot { @@ -69,6 +69,12 @@ impl PackageRoot { pub fn new_non_member(path: PathBuf) -> PackageRoot { Self { path, is_member: false } } + pub fn path(&self) -> &Path { + &self.path + } + pub fn is_member(&self) -> bool { + self.is_member + } } impl ProjectWorkspace { diff --git a/crates/rust-analyzer/src/cli/analysis_bench.rs b/crates/rust-analyzer/src/cli/analysis_bench.rs index 0b138edd7..7667873d5 100644 --- a/crates/rust-analyzer/src/cli/analysis_bench.rs +++ b/crates/rust-analyzer/src/cli/analysis_bench.rs @@ -65,10 +65,10 @@ pub fn analysis_bench( roots .iter() .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() { 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 { return Some(file_id); } diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs index edd90df77..75cf2dae5 100644 --- a/crates/rust-analyzer/src/cli/analysis_stats.rs +++ b/crates/rust-analyzer/src/cli/analysis_stats.rs @@ -39,7 +39,7 @@ pub fn analysis_stats( roots .into_iter() .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) } else { None diff --git a/crates/rust-analyzer/src/cli/load_cargo.rs b/crates/rust-analyzer/src/cli/load_cargo.rs index 109b1d74b..69133e4e4 100644 --- a/crates/rust-analyzer/src/cli/load_cargo.rs +++ b/crates/rust-analyzer/src/cli/load_cargo.rs @@ -45,9 +45,9 @@ pub(crate) fn load_cargo( .iter() .map(|pkg_root| { RootEntry::new( - pkg_root.path.clone(), + pkg_root.path().to_owned(), RustPackageFilterBuilder::default() - .set_member(pkg_root.is_member) + .set_member(pkg_root.is_member()) .into_vfs_filter(), ) }) @@ -60,8 +60,11 @@ pub(crate) fn load_cargo( .into_iter() .map(|vfs_root| { let source_root_id = vfs_root_to_id(vfs_root); - let project_root = - project_roots.iter().find(|it| it.path == vfs.root2path(vfs_root)).unwrap().clone(); + let project_root = project_roots + .iter() + .find(|it| it.path() == vfs.root2path(vfs_root)) + .unwrap() + .clone(); (source_root_id, project_root) }) .collect::>(); @@ -93,7 +96,7 @@ pub(crate) fn load( match change { VfsChange::AddRoot { root, files } => { 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!( "loaded source root {:?} with path {:?}", source_root_id, @@ -102,7 +105,7 @@ pub(crate) fn load( analysis_change.add_root(source_root_id, is_local); analysis_change.set_debug_root_path( 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); diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index e61a56935..8d1429196 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs @@ -23,6 +23,7 @@ use lsp_types::{ use ra_flycheck::{url_from_path_with_drive_lowercasing, CheckTask}; use ra_ide::{Canceled, FileId, LibraryData, SourceRootId}; use ra_prof::profile; +use ra_project_model::{PackageRoot, ProjectWorkspace}; use ra_vfs::{VfsFile, VfsTask, Watch}; use relative_path::RelativePathBuf; use rustc_hash::FxHashSet; @@ -131,9 +132,9 @@ pub fn main_loop(ws_roots: Vec, config: Config, connection: Connection) let registration_options = req::DidChangeWatchedFilesRegistrationOptions { watchers: workspaces .iter() - .flat_map(|ws| ws.to_roots()) - .filter(|root| root.is_member) - .map(|root| format!("{}/**/*.rs", root.path.display())) + .flat_map(ProjectWorkspace::to_roots) + .filter(PackageRoot::is_member) + .map(|root| format!("{}/**/*.rs", root.path().display())) .map(|glob_pattern| req::FileSystemWatcher { glob_pattern, kind: None }) .collect(), }; diff --git a/crates/rust-analyzer/src/world.rs b/crates/rust-analyzer/src/world.rs index a6549a8f4..3be4455e3 100644 --- a/crates/rust-analyzer/src/world.rs +++ b/crates/rust-analyzer/src/world.rs @@ -101,7 +101,7 @@ impl WorldState { .iter() .map(|path| RootEntry::new(path.clone(), create_filter(true))) .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( extern_dirs -- cgit v1.2.3