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)]
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 {

View File

@ -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);
}

View File

@ -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

View File

@ -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::<FxHashMap<_, _>>();
@ -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);

View File

@ -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<PathBuf>, 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(),
};

View File

@ -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