aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-12-19 12:40:42 +0000
committerAleksey Kladov <[email protected]>2018-12-20 09:15:38 +0000
commit7b6bafa631e6272946da568e9da7c3adc01ba625 (patch)
treef71e26828c40a79e50a21ab284c4123b741735f9 /crates
parenta5ef8ad05b7c1f7148c59814b55d641fd75aff75 (diff)
fix syc
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_analysis/src/lib.rs1
-rw-r--r--crates/ra_lsp_server/src/main_loop.rs4
-rw-r--r--crates/ra_lsp_server/src/server_world.rs33
-rw-r--r--crates/ra_lsp_server/tests/heavy_tests/main.rs3
-rw-r--r--crates/ra_vfs/src/lib.rs27
5 files changed, 55 insertions, 13 deletions
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs
index 8882feca3..300dfc5dd 100644
--- a/crates/ra_analysis/src/lib.rs
+++ b/crates/ra_analysis/src/lib.rs
@@ -73,6 +73,7 @@ struct RemoveFile {
73impl fmt::Debug for AnalysisChange { 73impl fmt::Debug for AnalysisChange {
74 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { 74 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
75 fmt.debug_struct("AnalysisChange") 75 fmt.debug_struct("AnalysisChange")
76 .field("new_roots", &self.new_roots)
76 .field("roots_changed", &self.roots_changed) 77 .field("roots_changed", &self.roots_changed)
77 .field("files_changed", &self.files_changed.len()) 78 .field("files_changed", &self.files_changed.len())
78 .field("libraries_added", &self.libraries_added.len()) 79 .field("libraries_added", &self.libraries_added.len())
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)]
23pub struct ServerWorldState { 23pub 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 @@
1mod support; 1mod support;
2 2
3use serde_json::json; 3use serde_json::json;
4
5use ra_lsp_server::req::{Runnables, RunnablesParams, CodeActionRequest, CodeActionParams}; 4use ra_lsp_server::req::{Runnables, RunnablesParams, CodeActionRequest, CodeActionParams};
6
7use languageserver_types::{Position, Range, CodeActionContext}; 5use languageserver_types::{Position, Range, CodeActionContext};
8 6
9use crate::support::project; 7use 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"),
diff --git a/crates/ra_vfs/src/lib.rs b/crates/ra_vfs/src/lib.rs
index dc980c3d2..3a68039f0 100644
--- a/crates/ra_vfs/src/lib.rs
+++ b/crates/ra_vfs/src/lib.rs
@@ -132,6 +132,7 @@ impl Vfs {
132 roots.sort_by_key(|it| Reverse(it.as_os_str().len())); 132 roots.sort_by_key(|it| Reverse(it.as_os_str().len()));
133 for (i, path) in roots.iter().enumerate() { 133 for (i, path) in roots.iter().enumerate() {
134 let root = res.roots.alloc(RootFilter::new(path.clone())); 134 let root = res.roots.alloc(RootFilter::new(path.clone()));
135 res.root2files.insert(root, Default::default());
135 let nested = roots[..i] 136 let nested = roots[..i]
136 .iter() 137 .iter()
137 .filter(|it| it.starts_with(path)) 138 .filter(|it| it.starts_with(path))
@@ -155,6 +156,10 @@ impl Vfs {
155 (res, roots) 156 (res, roots)
156 } 157 }
157 158
159 pub fn root2path(&self, root: VfsRoot) -> PathBuf {
160 self.roots[root].root.clone()
161 }
162
158 pub fn path2file(&self, path: &Path) -> Option<VfsFile> { 163 pub fn path2file(&self, path: &Path) -> Option<VfsFile> {
159 if let Some((_root, _path, Some(file))) = self.find_root(path) { 164 if let Some((_root, _path, Some(file))) = self.find_root(path) {
160 return Some(file); 165 return Some(file);
@@ -176,6 +181,23 @@ impl Vfs {
176 } 181 }
177 182
178 pub fn load(&mut self, path: &Path) -> Option<VfsFile> { 183 pub fn load(&mut self, path: &Path) -> Option<VfsFile> {
184 if let Some((root, rel_path, file)) = self.find_root(path) {
185 return if let Some(file) = file {
186 Some(file)
187 } else {
188 let text = fs::read_to_string(path).unwrap_or_default();
189 let text = Arc::new(text);
190 let file = self.add_file(root, rel_path.clone(), Arc::clone(&text));
191 let change = VfsChange::AddFile {
192 file,
193 text,
194 root,
195 path: rel_path,
196 };
197 self.pending_changes.push(change);
198 Some(file)
199 };
200 }
179 None 201 None
180 } 202 }
181 203
@@ -262,10 +284,7 @@ impl Vfs {
262 fn add_file(&mut self, root: VfsRoot, path: RelativePathBuf, text: Arc<String>) -> VfsFile { 284 fn add_file(&mut self, root: VfsRoot, path: RelativePathBuf, text: Arc<String>) -> VfsFile {
263 let data = VfsFileData { root, path, text }; 285 let data = VfsFileData { root, path, text };
264 let file = self.files.alloc(data); 286 let file = self.files.alloc(data);
265 self.root2files 287 self.root2files.get_mut(&root).unwrap().insert(file);
266 .entry(root)
267 .or_insert_with(FxHashSet::default)
268 .insert(file);
269 file 288 file
270 } 289 }
271 290