From 6b1f30ade93b3bd73625cc354652738254175dba Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 27 Nov 2018 00:12:43 +0300 Subject: hack around nested libraries --- crates/ra_lsp_server/src/main_loop/mod.rs | 32 ++++++++++++++++++++++++++++--- crates/ra_lsp_server/src/path_map.rs | 4 ++++ 2 files changed, 33 insertions(+), 3 deletions(-) (limited to 'crates/ra_lsp_server/src') diff --git a/crates/ra_lsp_server/src/main_loop/mod.rs b/crates/ra_lsp_server/src/main_loop/mod.rs index 78d93741a..36f08be2f 100644 --- a/crates/ra_lsp_server/src/main_loop/mod.rs +++ b/crates/ra_lsp_server/src/main_loop/mod.rs @@ -168,9 +168,35 @@ fn main_loop_inner( let workspaces = vec![ws]; feedback(internal_mode, "workspace loaded", msg_sender); for ws in workspaces.iter() { - for pkg in ws.packages().filter(|pkg| !pkg.is_member(ws)) { - debug!("sending root, {}", pkg.root(ws).to_path_buf().display()); - fs_worker.send(pkg.root(ws).to_path_buf()); + // Add each library as constant input. If library is + // within the workspace, don't treat it as a library. + // + // HACK: If source roots are nested, pick the outer one. + + let mut roots = ws + .packages() + .filter(|pkg| !pkg.is_member(ws)) + .filter_map(|pkg| { + let root = pkg.root(ws).to_path_buf(); + if root.starts_with(&ws_root) { + None + } else { + Some(root) + } + }) + .collect::>(); + roots.sort_by_key(|it| it.as_os_str().len()); + let unique = roots + .iter() + .enumerate() + .filter(|&(idx, long)| { + !roots[..idx].iter().any(|short| long.starts_with(short)) + }) + .map(|(_idx, root)| root); + + for root in unique { + debug!("sending root, {}", root.display()); + fs_worker.send(root.to_owned()); } } state.set_workspaces(workspaces); diff --git a/crates/ra_lsp_server/src/path_map.rs b/crates/ra_lsp_server/src/path_map.rs index 87eabf9be..a624043d8 100644 --- a/crates/ra_lsp_server/src/path_map.rs +++ b/crates/ra_lsp_server/src/path_map.rs @@ -79,6 +79,10 @@ impl FileResolver for PathMap { let path = normalize(&path); self.get_id(&path) } + + fn debug_path(&self, file_id: FileId) -> Option { + Some(self.get_path(file_id).to_owned()) + } } fn normalize(path: &Path) -> PathBuf { -- cgit v1.2.3