diff options
Diffstat (limited to 'crates/ra_lsp_server')
-rw-r--r-- | crates/ra_lsp_server/src/main_loop.rs | 4 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/server_world.rs | 33 | ||||
-rw-r--r-- | crates/ra_lsp_server/tests/heavy_tests/main.rs | 3 |
3 files changed, 31 insertions, 9 deletions
diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index 7904545d3..d2f16ea97 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs | |||
@@ -143,6 +143,7 @@ fn main_loop_inner( | |||
143 | } | 143 | } |
144 | recv(libdata_receiver, data) => Event::Lib(data.unwrap()) | 144 | recv(libdata_receiver, data) => Event::Lib(data.unwrap()) |
145 | }; | 145 | }; |
146 | log::info!("{:?}", event); | ||
146 | let mut state_changed = false; | 147 | let mut state_changed = false; |
147 | match event { | 148 | match event { |
148 | Event::Task(task) => on_task(task, msg_sender, pending_requests), | 149 | Event::Task(task) => on_task(task, msg_sender, pending_requests), |
@@ -192,6 +193,9 @@ fn main_loop_inner( | |||
192 | sender.send(data); | 193 | sender.send(data); |
193 | }); | 194 | }); |
194 | } | 195 | } |
196 | if state.roots_to_scan == 0 { | ||
197 | feedback(internal_mode, "workspace loaded", msg_sender); | ||
198 | } | ||
195 | 199 | ||
196 | if state_changed { | 200 | if state_changed { |
197 | update_file_notifications_on_threadpool( | 201 | update_file_notifications_on_threadpool( |
diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs index f2fd09e85..bdb4c513f 100644 --- a/crates/ra_lsp_server/src/server_world.rs +++ b/crates/ra_lsp_server/src/server_world.rs | |||
@@ -21,6 +21,8 @@ use crate::{ | |||
21 | 21 | ||
22 | #[derive(Debug)] | 22 | #[derive(Debug)] |
23 | pub struct ServerWorldState { | 23 | pub struct ServerWorldState { |
24 | pub roots_to_scan: usize, | ||
25 | pub root: PathBuf, | ||
24 | pub workspaces: Arc<Vec<CargoWorkspace>>, | 26 | pub workspaces: Arc<Vec<CargoWorkspace>>, |
25 | pub analysis_host: AnalysisHost, | 27 | pub analysis_host: AnalysisHost, |
26 | pub vfs: Arc<RwLock<Vfs>>, | 28 | pub vfs: Arc<RwLock<Vfs>>, |
@@ -37,12 +39,13 @@ impl ServerWorldState { | |||
37 | let mut change = AnalysisChange::new(); | 39 | let mut change = AnalysisChange::new(); |
38 | 40 | ||
39 | let mut roots = Vec::new(); | 41 | let mut roots = Vec::new(); |
40 | roots.push(root); | 42 | roots.push(root.clone()); |
41 | for ws in workspaces.iter() { | 43 | for ws in workspaces.iter() { |
42 | for pkg in ws.packages() { | 44 | for pkg in ws.packages() { |
43 | roots.push(pkg.root(&ws).to_path_buf()); | 45 | roots.push(pkg.root(&ws).to_path_buf()); |
44 | } | 46 | } |
45 | } | 47 | } |
48 | let roots_to_scan = roots.len(); | ||
46 | let (mut vfs, roots) = Vfs::new(roots); | 49 | let (mut vfs, roots) = Vfs::new(roots); |
47 | for r in roots { | 50 | for r in roots { |
48 | change.add_root(SourceRootId(r.0)); | 51 | change.add_root(SourceRootId(r.0)); |
@@ -83,6 +86,8 @@ impl ServerWorldState { | |||
83 | let mut analysis_host = AnalysisHost::default(); | 86 | let mut analysis_host = AnalysisHost::default(); |
84 | analysis_host.apply_change(change); | 87 | analysis_host.apply_change(change); |
85 | ServerWorldState { | 88 | ServerWorldState { |
89 | roots_to_scan, | ||
90 | root, | ||
86 | workspaces: Arc::new(workspaces), | 91 | workspaces: Arc::new(workspaces), |
87 | analysis_host, | 92 | analysis_host, |
88 | vfs: Arc::new(RwLock::new(vfs)), | 93 | vfs: Arc::new(RwLock::new(vfs)), |
@@ -94,16 +99,29 @@ impl ServerWorldState { | |||
94 | pub fn process_changes( | 99 | pub fn process_changes( |
95 | &mut self, | 100 | &mut self, |
96 | ) -> Vec<(SourceRootId, Vec<(FileId, RelativePathBuf, Arc<String>)>)> { | 101 | ) -> Vec<(SourceRootId, Vec<(FileId, RelativePathBuf, Arc<String>)>)> { |
102 | let changes = self.vfs.write().commit_changes(); | ||
103 | if changes.is_empty() { | ||
104 | return Vec::new(); | ||
105 | } | ||
97 | let mut libs = Vec::new(); | 106 | let mut libs = Vec::new(); |
98 | let mut change = AnalysisChange::new(); | 107 | let mut change = AnalysisChange::new(); |
99 | for c in self.vfs.write().commit_changes() { | 108 | for c in changes { |
109 | log::info!("vfs change {:?}", c); | ||
100 | match c { | 110 | match c { |
101 | VfsChange::AddRoot { root, files } => { | 111 | VfsChange::AddRoot { root, files } => { |
102 | let files = files | 112 | let root_path = self.vfs.read().root2path(root); |
103 | .into_iter() | 113 | if root_path.starts_with(&self.root) { |
104 | .map(|(vfsfile, path, text)| (FileId(vfsfile.0), path, text)) | 114 | self.roots_to_scan -= 1; |
105 | .collect(); | 115 | for (file, path, text) in files { |
106 | libs.push((SourceRootId(root.0), files)); | 116 | change.add_file(SourceRootId(root.0), FileId(file.0), path, text); |
117 | } | ||
118 | } else { | ||
119 | let files = files | ||
120 | .into_iter() | ||
121 | .map(|(vfsfile, path, text)| (FileId(vfsfile.0), path, text)) | ||
122 | .collect(); | ||
123 | libs.push((SourceRootId(root.0), files)); | ||
124 | } | ||
107 | } | 125 | } |
108 | VfsChange::AddFile { | 126 | VfsChange::AddFile { |
109 | root, | 127 | root, |
@@ -126,6 +144,7 @@ impl ServerWorldState { | |||
126 | } | 144 | } |
127 | 145 | ||
128 | pub fn add_lib(&mut self, data: LibraryData) { | 146 | pub fn add_lib(&mut self, data: LibraryData) { |
147 | self.roots_to_scan -= 1; | ||
129 | let mut change = AnalysisChange::new(); | 148 | let mut change = AnalysisChange::new(); |
130 | change.add_library(data); | 149 | change.add_library(data); |
131 | self.analysis_host.apply_change(change); | 150 | self.analysis_host.apply_change(change); |
diff --git a/crates/ra_lsp_server/tests/heavy_tests/main.rs b/crates/ra_lsp_server/tests/heavy_tests/main.rs index 26f5e3f20..029a55d40 100644 --- a/crates/ra_lsp_server/tests/heavy_tests/main.rs +++ b/crates/ra_lsp_server/tests/heavy_tests/main.rs | |||
@@ -1,9 +1,7 @@ | |||
1 | mod support; | 1 | mod support; |
2 | 2 | ||
3 | use serde_json::json; | 3 | use serde_json::json; |
4 | |||
5 | use ra_lsp_server::req::{Runnables, RunnablesParams, CodeActionRequest, CodeActionParams}; | 4 | use ra_lsp_server::req::{Runnables, RunnablesParams, CodeActionRequest, CodeActionParams}; |
6 | |||
7 | use languageserver_types::{Position, Range, CodeActionContext}; | 5 | use languageserver_types::{Position, Range, CodeActionContext}; |
8 | 6 | ||
9 | use crate::support::project; | 7 | use crate::support::project; |
@@ -20,6 +18,7 @@ fn foo() { | |||
20 | } | 18 | } |
21 | ", | 19 | ", |
22 | ); | 20 | ); |
21 | server.wait_for_feedback("workspace loaded"); | ||
23 | server.request::<Runnables>( | 22 | server.request::<Runnables>( |
24 | RunnablesParams { | 23 | RunnablesParams { |
25 | text_document: server.doc_id("lib.rs"), | 24 | text_document: server.doc_id("lib.rs"), |