Skip to content

Commit d4b2147

Browse files
committed
Derive local roots from Workspaces
1 parent ca80544 commit d4b2147

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

crates/rust-analyzer/src/main_loop.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ pub fn main_loop(ws_roots: Vec<PathBuf>, config: Config, connection: Connection)
164164
}
165165

166166
WorldState::new(
167-
ws_roots,
168167
workspaces,
169168
config.lru_capacity,
170169
&globs,

crates/rust-analyzer/src/world.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ fn create_flycheck(workspaces: &[ProjectWorkspace], config: &FlycheckConfig) ->
5858
#[derive(Debug)]
5959
pub struct WorldState {
6060
pub config: Config,
61-
pub roots: Vec<PathBuf>,
61+
pub local_roots: Vec<PathBuf>,
6262
pub workspaces: Arc<Vec<ProjectWorkspace>>,
6363
pub analysis_host: AnalysisHost,
6464
pub vfs: Arc<RwLock<Vfs>>,
@@ -81,7 +81,6 @@ pub struct WorldSnapshot {
8181

8282
impl WorldState {
8383
pub fn new(
84-
folder_roots: Vec<PathBuf>,
8584
workspaces: Vec<ProjectWorkspace>,
8685
lru_capacity: Option<usize>,
8786
exclude_globs: &[Glob],
@@ -93,19 +92,24 @@ impl WorldState {
9392
let extern_dirs: FxHashSet<_> =
9493
workspaces.iter().flat_map(ProjectWorkspace::out_dirs).collect();
9594

95+
let mut local_roots = Vec::new();
9696
let roots: Vec<_> = {
9797
let create_filter = |is_member| {
9898
RustPackageFilterBuilder::default()
9999
.set_member(is_member)
100100
.exclude(exclude_globs.iter().cloned())
101101
.into_vfs_filter()
102102
};
103-
folder_roots
103+
workspaces
104104
.iter()
105-
.map(|path| RootEntry::new(path.clone(), create_filter(true)))
106-
.chain(workspaces.iter().flat_map(ProjectWorkspace::to_roots).map(|pkg_root| {
107-
RootEntry::new(pkg_root.path().to_owned(), create_filter(pkg_root.is_member()))
108-
}))
105+
.flat_map(ProjectWorkspace::to_roots)
106+
.map(|pkg_root| {
107+
let path = pkg_root.path().to_owned();
108+
if pkg_root.is_member() {
109+
local_roots.push(path.clone());
110+
}
111+
RootEntry::new(path, create_filter(pkg_root.is_member()))
112+
})
109113
.chain(
110114
extern_dirs
111115
.iter()
@@ -121,7 +125,7 @@ impl WorldState {
121125
let mut extern_source_roots = FxHashMap::default();
122126
for r in vfs_roots {
123127
let vfs_root_path = vfs.root2path(r);
124-
let is_local = folder_roots.iter().any(|it| vfs_root_path.starts_with(it));
128+
let is_local = local_roots.iter().any(|it| vfs_root_path.starts_with(it));
125129
change.add_root(SourceRootId(r.0), is_local);
126130
change.set_debug_root_path(SourceRootId(r.0), vfs_root_path.display().to_string());
127131

@@ -178,7 +182,7 @@ impl WorldState {
178182
analysis_host.apply_change(change);
179183
WorldState {
180184
config,
181-
roots: folder_roots,
185+
local_roots,
182186
workspaces: Arc::new(workspaces),
183187
analysis_host,
184188
vfs: Arc::new(RwLock::new(vfs)),
@@ -216,7 +220,7 @@ impl WorldState {
216220
match c {
217221
VfsChange::AddRoot { root, files } => {
218222
let root_path = self.vfs.read().root2path(root);
219-
let is_local = self.roots.iter().any(|r| root_path.starts_with(r));
223+
let is_local = self.local_roots.iter().any(|r| root_path.starts_with(r));
220224
if is_local {
221225
*roots_scanned += 1;
222226
for (file, path, text) in files {

0 commit comments

Comments
 (0)