Skip to content

Commit 6190cae

Browse files
committed
Migrate to privacy as per review commets
1 parent bef899a commit 6190cae

File tree

6 files changed

+25
-15
lines changed

6 files changed

+25
-15
lines changed

crates/ra_project_model/src/lib.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ pub enum ProjectWorkspace {
5858
#[derive(Clone)]
5959
pub struct PackageRoot {
6060
/// Path to the root folder
61-
pub path: PathBuf,
61+
path: PathBuf,
6262
/// Is a member of the current workspace
63-
pub is_member: bool,
63+
is_member: bool,
6464
}
6565
impl PackageRoot {
6666
pub fn new_member(path: PathBuf) -> PackageRoot {
@@ -69,6 +69,12 @@ impl PackageRoot {
6969
pub fn new_non_member(path: PathBuf) -> PackageRoot {
7070
Self { path, is_member: false }
7171
}
72+
pub fn path(&self) -> &Path {
73+
&self.path
74+
}
75+
pub fn is_member(&self) -> bool {
76+
self.is_member
77+
}
7278
}
7379

7480
impl ProjectWorkspace {

crates/rust-analyzer/src/cli/analysis_bench.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ pub fn analysis_bench(
6565
roots
6666
.iter()
6767
.find_map(|(source_root_id, project_root)| {
68-
if project_root.is_member {
68+
if project_root.is_member() {
6969
for file_id in db.source_root(*source_root_id).walk() {
7070
let rel_path = db.file_relative_path(file_id);
71-
let abs_path = rel_path.to_path(&project_root.path);
71+
let abs_path = rel_path.to_path(project_root.path());
7272
if abs_path == path {
7373
return Some(file_id);
7474
}

crates/rust-analyzer/src/cli/analysis_stats.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub fn analysis_stats(
3939
roots
4040
.into_iter()
4141
.filter_map(|(source_root_id, project_root)| {
42-
if with_deps || project_root.is_member {
42+
if with_deps || project_root.is_member() {
4343
Some(source_root_id)
4444
} else {
4545
None

crates/rust-analyzer/src/cli/load_cargo.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ pub(crate) fn load_cargo(
4545
.iter()
4646
.map(|pkg_root| {
4747
RootEntry::new(
48-
pkg_root.path.clone(),
48+
pkg_root.path().to_owned(),
4949
RustPackageFilterBuilder::default()
50-
.set_member(pkg_root.is_member)
50+
.set_member(pkg_root.is_member())
5151
.into_vfs_filter(),
5252
)
5353
})
@@ -60,8 +60,11 @@ pub(crate) fn load_cargo(
6060
.into_iter()
6161
.map(|vfs_root| {
6262
let source_root_id = vfs_root_to_id(vfs_root);
63-
let project_root =
64-
project_roots.iter().find(|it| it.path == vfs.root2path(vfs_root)).unwrap().clone();
63+
let project_root = project_roots
64+
.iter()
65+
.find(|it| it.path() == vfs.root2path(vfs_root))
66+
.unwrap()
67+
.clone();
6568
(source_root_id, project_root)
6669
})
6770
.collect::<FxHashMap<_, _>>();
@@ -93,7 +96,7 @@ pub(crate) fn load(
9396
match change {
9497
VfsChange::AddRoot { root, files } => {
9598
let source_root_id = vfs_root_to_id(root);
96-
let is_local = source_roots[&source_root_id].is_member;
99+
let is_local = source_roots[&source_root_id].is_member();
97100
log::debug!(
98101
"loaded source root {:?} with path {:?}",
99102
source_root_id,
@@ -102,7 +105,7 @@ pub(crate) fn load(
102105
analysis_change.add_root(source_root_id, is_local);
103106
analysis_change.set_debug_root_path(
104107
source_root_id,
105-
source_roots[&source_root_id].path.display().to_string(),
108+
source_roots[&source_root_id].path().display().to_string(),
106109
);
107110

108111
let vfs_root_path = vfs.root2path(root);

crates/rust-analyzer/src/main_loop.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use lsp_types::{
2323
use ra_flycheck::{url_from_path_with_drive_lowercasing, CheckTask};
2424
use ra_ide::{Canceled, FileId, LibraryData, SourceRootId};
2525
use ra_prof::profile;
26+
use ra_project_model::{PackageRoot, ProjectWorkspace};
2627
use ra_vfs::{VfsFile, VfsTask, Watch};
2728
use relative_path::RelativePathBuf;
2829
use rustc_hash::FxHashSet;
@@ -131,9 +132,9 @@ pub fn main_loop(ws_roots: Vec<PathBuf>, config: Config, connection: Connection)
131132
let registration_options = req::DidChangeWatchedFilesRegistrationOptions {
132133
watchers: workspaces
133134
.iter()
134-
.flat_map(|ws| ws.to_roots())
135-
.filter(|root| root.is_member)
136-
.map(|root| format!("{}/**/*.rs", root.path.display()))
135+
.flat_map(ProjectWorkspace::to_roots)
136+
.filter(PackageRoot::is_member)
137+
.map(|root| format!("{}/**/*.rs", root.path().display()))
137138
.map(|glob_pattern| req::FileSystemWatcher { glob_pattern, kind: None })
138139
.collect(),
139140
};

crates/rust-analyzer/src/world.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl WorldState {
101101
.iter()
102102
.map(|path| RootEntry::new(path.clone(), create_filter(true)))
103103
.chain(workspaces.iter().flat_map(ProjectWorkspace::to_roots).map(|pkg_root| {
104-
RootEntry::new(pkg_root.path, create_filter(pkg_root.is_member))
104+
RootEntry::new(pkg_root.path().to_owned(), create_filter(pkg_root.is_member()))
105105
}))
106106
.chain(
107107
extern_dirs

0 commit comments

Comments
 (0)