diff options
Diffstat (limited to 'crates/server/src/server_world.rs')
-rw-r--r-- | crates/server/src/server_world.rs | 31 |
1 files changed, 18 insertions, 13 deletions
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 | } |