aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-11-26 21:12:43 +0000
committerAleksey Kladov <[email protected]>2018-11-26 21:12:43 +0000
commit6b1f30ade93b3bd73625cc354652738254175dba (patch)
tree16cdd20641d34b441bdb571ac04b9c7f1aee30f7 /crates
parent8a572043e7effe1d0b36a0d247960111312edc2a (diff)
hack around nested libraries
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_analysis/src/imp.rs8
-rw-r--r--crates/ra_analysis/src/input.rs3
-rw-r--r--crates/ra_lsp_server/src/main_loop/mod.rs32
-rw-r--r--crates/ra_lsp_server/src/path_map.rs4
4 files changed, 44 insertions, 3 deletions
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index e1493bdaa..ad6b52371 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -59,6 +59,9 @@ impl FileResolverImp {
59 pub(crate) fn resolve(&self, file_id: FileId, path: &RelativePath) -> Option<FileId> { 59 pub(crate) fn resolve(&self, file_id: FileId, path: &RelativePath) -> Option<FileId> {
60 self.inner.resolve(file_id, path) 60 self.inner.resolve(file_id, path)
61 } 61 }
62 pub(crate) fn debug_path(&self, file_id: FileId) -> Option<std::path::PathBuf> {
63 self.inner.debug_path(file_id)
64 }
62 fn inner(&self) -> *const FileResolver { 65 fn inner(&self) -> *const FileResolver {
63 &*self.inner 66 &*self.inner
64 } 67 }
@@ -138,6 +141,11 @@ impl AnalysisHostImpl {
138 let mut files = FxHashSet::default(); 141 let mut files = FxHashSet::default();
139 for (file_id, text) in library.files { 142 for (file_id, text) in library.files {
140 files.insert(file_id); 143 files.insert(file_id);
144 log::debug!(
145 "library file: {:?} {:?}",
146 file_id,
147 library.file_resolver.debug_path(file_id)
148 );
141 self.db 149 self.db
142 .query_mut(crate::input::FileSourceRootQuery) 150 .query_mut(crate::input::FileSourceRootQuery)
143 .set_constant(file_id, source_root_id); 151 .set_constant(file_id, source_root_id);
diff --git a/crates/ra_analysis/src/input.rs b/crates/ra_analysis/src/input.rs
index ba8a17fd5..a78b6e397 100644
--- a/crates/ra_analysis/src/input.rs
+++ b/crates/ra_analysis/src/input.rs
@@ -33,6 +33,9 @@ impl CrateGraph {
33pub trait FileResolver: fmt::Debug + Send + Sync + 'static { 33pub trait FileResolver: fmt::Debug + Send + Sync + 'static {
34 fn file_stem(&self, file_id: FileId) -> String; 34 fn file_stem(&self, file_id: FileId) -> String;
35 fn resolve(&self, file_id: FileId, path: &RelativePath) -> Option<FileId>; 35 fn resolve(&self, file_id: FileId, path: &RelativePath) -> Option<FileId>;
36 fn debug_path(&self, _file_id: FileId) -> Option<std::path::PathBuf> {
37 None
38 }
36} 39}
37 40
38salsa::query_group! { 41salsa::query_group! {
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(
168 let workspaces = vec![ws]; 168 let workspaces = vec![ws];
169 feedback(internal_mode, "workspace loaded", msg_sender); 169 feedback(internal_mode, "workspace loaded", msg_sender);
170 for ws in workspaces.iter() { 170 for ws in workspaces.iter() {
171 for pkg in ws.packages().filter(|pkg| !pkg.is_member(ws)) { 171 // Add each library as constant input. If library is
172 debug!("sending root, {}", pkg.root(ws).to_path_buf().display()); 172 // within the workspace, don't treat it as a library.
173 fs_worker.send(pkg.root(ws).to_path_buf()); 173 //
174 // HACK: If source roots are nested, pick the outer one.
175
176 let mut roots = ws
177 .packages()
178 .filter(|pkg| !pkg.is_member(ws))
179 .filter_map(|pkg| {
180 let root = pkg.root(ws).to_path_buf();
181 if root.starts_with(&ws_root) {
182 None
183 } else {
184 Some(root)
185 }
186 })
187 .collect::<Vec<_>>();
188 roots.sort_by_key(|it| it.as_os_str().len());
189 let unique = roots
190 .iter()
191 .enumerate()
192 .filter(|&(idx, long)| {
193 !roots[..idx].iter().any(|short| long.starts_with(short))
194 })
195 .map(|(_idx, root)| root);
196
197 for root in unique {
198 debug!("sending root, {}", root.display());
199 fs_worker.send(root.to_owned());
174 } 200 }
175 } 201 }
176 state.set_workspaces(workspaces); 202 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 {
79 let path = normalize(&path); 79 let path = normalize(&path);
80 self.get_id(&path) 80 self.get_id(&path)
81 } 81 }
82
83 fn debug_path(&self, file_id: FileId) -> Option<PathBuf> {
84 Some(self.get_path(file_id).to_owned())
85 }
82} 86}
83 87
84fn normalize(path: &Path) -> PathBuf { 88fn normalize(path: &Path) -> PathBuf {