diff options
Diffstat (limited to 'crates/server/src')
-rw-r--r-- | crates/server/src/main_loop/mod.rs | 4 | ||||
-rw-r--r-- | crates/server/src/server_world.rs | 31 |
2 files changed, 20 insertions, 15 deletions
diff --git a/crates/server/src/main_loop/mod.rs b/crates/server/src/main_loop/mod.rs index f1297ee48..f3b2744bf 100644 --- a/crates/server/src/main_loop/mod.rs +++ b/crates/server/src/main_loop/mod.rs | |||
@@ -135,12 +135,12 @@ fn main_loop_inner( | |||
135 | if root == ws_root { | 135 | if root == ws_root { |
136 | state.apply_fs_changes(events); | 136 | state.apply_fs_changes(events); |
137 | } else { | 137 | } else { |
138 | let files = state.events_to_files(events); | 138 | let (files, resolver) = state.events_to_files(events); |
139 | let sender = libdata_sender.clone(); | 139 | let sender = libdata_sender.clone(); |
140 | pool.spawn(move || { | 140 | pool.spawn(move || { |
141 | let start = ::std::time::Instant::now(); | 141 | let start = ::std::time::Instant::now(); |
142 | info!("indexing {} ... ", root.display()); | 142 | info!("indexing {} ... ", root.display()); |
143 | let data = LibraryData::prepare(files); | 143 | let data = LibraryData::prepare(files, resolver); |
144 | info!("indexed {:?} {}", start.elapsed(), root.display()); | 144 | info!("indexed {:?} {}", start.elapsed(), root.display()); |
145 | sender.send(data); | 145 | sender.send(data); |
146 | }); | 146 | }); |
diff --git a/crates/server/src/server_world.rs b/crates/server/src/server_world.rs index 8ceec594f..ffa0e74b8 100644 --- a/crates/server/src/server_world.rs +++ b/crates/server/src/server_world.rs | |||
@@ -6,7 +6,7 @@ use std::{ | |||
6 | }; | 6 | }; |
7 | 7 | ||
8 | use languageserver_types::Url; | 8 | use languageserver_types::Url; |
9 | use libanalysis::{FileId, AnalysisHost, Analysis, CrateGraph, CrateId, LibraryData}; | 9 | use libanalysis::{FileId, AnalysisHost, Analysis, CrateGraph, CrateId, LibraryData, FileResolver}; |
10 | 10 | ||
11 | use { | 11 | use { |
12 | Result, | 12 | Result, |
@@ -64,17 +64,21 @@ impl ServerWorldState { | |||
64 | 64 | ||
65 | self.analysis_host.change_files(changes); | 65 | self.analysis_host.change_files(changes); |
66 | } | 66 | } |
67 | pub fn events_to_files(&mut self, events: Vec<FileEvent>) -> Vec<(FileId, String)> { | 67 | pub fn events_to_files(&mut self, events: Vec<FileEvent>) -> (Vec<(FileId, String)>, Arc<FileResolver>) { |
68 | let pm = &mut self.path_map; | 68 | let files = { |
69 | events.into_iter() | 69 | let pm = &mut self.path_map; |
70 | .map(|event| { | 70 | events.into_iter() |
71 | let text = match event.kind { | 71 | .map(|event| { |
72 | FileEventKind::Add(text) => text, | 72 | let text = match event.kind { |
73 | }; | 73 | FileEventKind::Add(text) => text, |
74 | (event.path, text) | 74 | }; |
75 | }) | 75 | (event.path, text) |
76 | .map(|(path, text)| (pm.get_or_insert(path, Root::Lib), text)) | 76 | }) |
77 | .collect() | 77 | .map(|(path, text)| (pm.get_or_insert(path, Root::Lib), text)) |
78 | .collect() | ||
79 | }; | ||
80 | let resolver = Arc::new(self.path_map.clone()); | ||
81 | (files, resolver) | ||
78 | } | 82 | } |
79 | pub fn add_lib(&mut self, data: LibraryData) { | 83 | pub fn add_lib(&mut self, data: LibraryData) { |
80 | self.analysis_host.add_library(data); | 84 | self.analysis_host.add_library(data); |
@@ -82,6 +86,7 @@ impl ServerWorldState { | |||
82 | 86 | ||
83 | pub fn add_mem_file(&mut self, path: PathBuf, text: String) -> FileId { | 87 | pub fn add_mem_file(&mut self, path: PathBuf, text: String) -> FileId { |
84 | let file_id = self.path_map.get_or_insert(path, Root::Workspace); | 88 | let file_id = self.path_map.get_or_insert(path, Root::Workspace); |
89 | self.analysis_host.set_file_resolver(Arc::new(self.path_map.clone())); | ||
85 | self.mem_map.insert(file_id, None); | 90 | self.mem_map.insert(file_id, None); |
86 | if self.path_map.get_root(file_id) != Root::Lib { | 91 | if self.path_map.get_root(file_id) != Root::Lib { |
87 | self.analysis_host.change_file(file_id, Some(text)); | 92 | self.analysis_host.change_file(file_id, Some(text)); |
@@ -135,7 +140,7 @@ impl ServerWorldState { | |||
135 | pub fn snapshot(&self) -> ServerWorld { | 140 | pub fn snapshot(&self) -> ServerWorld { |
136 | ServerWorld { | 141 | ServerWorld { |
137 | workspaces: Arc::clone(&self.workspaces), | 142 | workspaces: Arc::clone(&self.workspaces), |
138 | analysis: self.analysis_host.analysis(self.path_map.clone()), | 143 | analysis: self.analysis_host.analysis(), |
139 | path_map: self.path_map.clone() | 144 | path_map: self.path_map.clone() |
140 | } | 145 | } |
141 | } | 146 | } |