diff options
Diffstat (limited to 'crates/server/src/main_loop/handlers.rs')
-rw-r--r-- | crates/server/src/main_loop/handlers.rs | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/crates/server/src/main_loop/handlers.rs b/crates/server/src/main_loop/handlers.rs index 6b70399b0..ab8b6f799 100644 --- a/crates/server/src/main_loop/handlers.rs +++ b/crates/server/src/main_loop/handlers.rs | |||
@@ -7,7 +7,7 @@ use languageserver_types::{ | |||
7 | CompletionItem, InsertTextFormat, CompletionItemKind, | 7 | CompletionItem, InsertTextFormat, CompletionItemKind, |
8 | }; | 8 | }; |
9 | use serde_json::to_value; | 9 | use serde_json::to_value; |
10 | use libanalysis::{Query, FileId, RunnableKind}; | 10 | use libanalysis::{Query, FileId, RunnableKind, JobToken}; |
11 | use libsyntax2::{ | 11 | use libsyntax2::{ |
12 | text_utils::contains_offset_nonstrict, | 12 | text_utils::contains_offset_nonstrict, |
13 | }; | 13 | }; |
@@ -21,6 +21,7 @@ use ::{ | |||
21 | pub fn handle_syntax_tree( | 21 | pub fn handle_syntax_tree( |
22 | world: ServerWorld, | 22 | world: ServerWorld, |
23 | params: req::SyntaxTreeParams, | 23 | params: req::SyntaxTreeParams, |
24 | _token: JobToken, | ||
24 | ) -> Result<String> { | 25 | ) -> Result<String> { |
25 | let id = params.text_document.try_conv_with(&world)?; | 26 | let id = params.text_document.try_conv_with(&world)?; |
26 | let res = world.analysis().syntax_tree(id); | 27 | let res = world.analysis().syntax_tree(id); |
@@ -30,6 +31,7 @@ pub fn handle_syntax_tree( | |||
30 | pub fn handle_extend_selection( | 31 | pub fn handle_extend_selection( |
31 | world: ServerWorld, | 32 | world: ServerWorld, |
32 | params: req::ExtendSelectionParams, | 33 | params: req::ExtendSelectionParams, |
34 | _token: JobToken, | ||
33 | ) -> Result<req::ExtendSelectionResult> { | 35 | ) -> Result<req::ExtendSelectionResult> { |
34 | let file_id = params.text_document.try_conv_with(&world)?; | 36 | let file_id = params.text_document.try_conv_with(&world)?; |
35 | let file = world.analysis().file_syntax(file_id); | 37 | let file = world.analysis().file_syntax(file_id); |
@@ -45,6 +47,7 @@ pub fn handle_extend_selection( | |||
45 | pub fn handle_find_matching_brace( | 47 | pub fn handle_find_matching_brace( |
46 | world: ServerWorld, | 48 | world: ServerWorld, |
47 | params: req::FindMatchingBraceParams, | 49 | params: req::FindMatchingBraceParams, |
50 | _token: JobToken, | ||
48 | ) -> Result<Vec<Position>> { | 51 | ) -> Result<Vec<Position>> { |
49 | let file_id = params.text_document.try_conv_with(&world)?; | 52 | let file_id = params.text_document.try_conv_with(&world)?; |
50 | let file = world.analysis().file_syntax(file_id); | 53 | let file = world.analysis().file_syntax(file_id); |
@@ -63,6 +66,7 @@ pub fn handle_find_matching_brace( | |||
63 | pub fn handle_join_lines( | 66 | pub fn handle_join_lines( |
64 | world: ServerWorld, | 67 | world: ServerWorld, |
65 | params: req::JoinLinesParams, | 68 | params: req::JoinLinesParams, |
69 | _token: JobToken, | ||
66 | ) -> Result<req::SourceChange> { | 70 | ) -> Result<req::SourceChange> { |
67 | let file_id = params.text_document.try_conv_with(&world)?; | 71 | let file_id = params.text_document.try_conv_with(&world)?; |
68 | let line_index = world.analysis().file_line_index(file_id); | 72 | let line_index = world.analysis().file_line_index(file_id); |
@@ -74,6 +78,7 @@ pub fn handle_join_lines( | |||
74 | pub fn handle_on_type_formatting( | 78 | pub fn handle_on_type_formatting( |
75 | world: ServerWorld, | 79 | world: ServerWorld, |
76 | params: req::DocumentOnTypeFormattingParams, | 80 | params: req::DocumentOnTypeFormattingParams, |
81 | _token: JobToken, | ||
77 | ) -> Result<Option<Vec<TextEdit>>> { | 82 | ) -> Result<Option<Vec<TextEdit>>> { |
78 | if params.ch != "=" { | 83 | if params.ch != "=" { |
79 | return Ok(None); | 84 | return Ok(None); |
@@ -93,6 +98,7 @@ pub fn handle_on_type_formatting( | |||
93 | pub fn handle_document_symbol( | 98 | pub fn handle_document_symbol( |
94 | world: ServerWorld, | 99 | world: ServerWorld, |
95 | params: req::DocumentSymbolParams, | 100 | params: req::DocumentSymbolParams, |
101 | _token: JobToken, | ||
96 | ) -> Result<Option<req::DocumentSymbolResponse>> { | 102 | ) -> Result<Option<req::DocumentSymbolResponse>> { |
97 | let file_id = params.text_document.try_conv_with(&world)?; | 103 | let file_id = params.text_document.try_conv_with(&world)?; |
98 | let line_index = world.analysis().file_line_index(file_id); | 104 | let line_index = world.analysis().file_line_index(file_id); |
@@ -131,6 +137,7 @@ pub fn handle_document_symbol( | |||
131 | pub fn handle_workspace_symbol( | 137 | pub fn handle_workspace_symbol( |
132 | world: ServerWorld, | 138 | world: ServerWorld, |
133 | params: req::WorkspaceSymbolParams, | 139 | params: req::WorkspaceSymbolParams, |
140 | token: JobToken, | ||
134 | ) -> Result<Option<Vec<SymbolInformation>>> { | 141 | ) -> Result<Option<Vec<SymbolInformation>>> { |
135 | let all_symbols = params.query.contains("#"); | 142 | let all_symbols = params.query.contains("#"); |
136 | let query = { | 143 | let query = { |
@@ -144,18 +151,18 @@ pub fn handle_workspace_symbol( | |||
144 | q.limit(128); | 151 | q.limit(128); |
145 | q | 152 | q |
146 | }; | 153 | }; |
147 | let mut res = exec_query(&world, query)?; | 154 | let mut res = exec_query(&world, query, &token)?; |
148 | if res.is_empty() && !all_symbols { | 155 | if res.is_empty() && !all_symbols { |
149 | let mut query = Query::new(params.query); | 156 | let mut query = Query::new(params.query); |
150 | query.limit(128); | 157 | query.limit(128); |
151 | res = exec_query(&world, query)?; | 158 | res = exec_query(&world, query, &token)?; |
152 | } | 159 | } |
153 | 160 | ||
154 | return Ok(Some(res)); | 161 | return Ok(Some(res)); |
155 | 162 | ||
156 | fn exec_query(world: &ServerWorld, query: Query) -> Result<Vec<SymbolInformation>> { | 163 | fn exec_query(world: &ServerWorld, query: Query, token: &JobToken) -> Result<Vec<SymbolInformation>> { |
157 | let mut res = Vec::new(); | 164 | let mut res = Vec::new(); |
158 | for (file_id, symbol) in world.analysis().symbol_search(query) { | 165 | for (file_id, symbol) in world.analysis().symbol_search(query, token) { |
159 | let line_index = world.analysis().file_line_index(file_id); | 166 | let line_index = world.analysis().file_line_index(file_id); |
160 | let info = SymbolInformation { | 167 | let info = SymbolInformation { |
161 | name: symbol.name.to_string(), | 168 | name: symbol.name.to_string(), |
@@ -175,12 +182,13 @@ pub fn handle_workspace_symbol( | |||
175 | pub fn handle_goto_definition( | 182 | pub fn handle_goto_definition( |
176 | world: ServerWorld, | 183 | world: ServerWorld, |
177 | params: req::TextDocumentPositionParams, | 184 | params: req::TextDocumentPositionParams, |
185 | token: JobToken, | ||
178 | ) -> Result<Option<req::GotoDefinitionResponse>> { | 186 | ) -> Result<Option<req::GotoDefinitionResponse>> { |
179 | let file_id = params.text_document.try_conv_with(&world)?; | 187 | let file_id = params.text_document.try_conv_with(&world)?; |
180 | let line_index = world.analysis().file_line_index(file_id); | 188 | let line_index = world.analysis().file_line_index(file_id); |
181 | let offset = params.position.conv_with(&line_index); | 189 | let offset = params.position.conv_with(&line_index); |
182 | let mut res = Vec::new(); | 190 | let mut res = Vec::new(); |
183 | for (file_id, symbol) in world.analysis().approximately_resolve_symbol(file_id, offset) { | 191 | for (file_id, symbol) in world.analysis().approximately_resolve_symbol(file_id, offset, &token) { |
184 | let line_index = world.analysis().file_line_index(file_id); | 192 | let line_index = world.analysis().file_line_index(file_id); |
185 | let location = to_location( | 193 | let location = to_location( |
186 | file_id, symbol.node_range, | 194 | file_id, symbol.node_range, |
@@ -194,6 +202,7 @@ pub fn handle_goto_definition( | |||
194 | pub fn handle_parent_module( | 202 | pub fn handle_parent_module( |
195 | world: ServerWorld, | 203 | world: ServerWorld, |
196 | params: TextDocumentIdentifier, | 204 | params: TextDocumentIdentifier, |
205 | _token: JobToken, | ||
197 | ) -> Result<Vec<Location>> { | 206 | ) -> Result<Vec<Location>> { |
198 | let file_id = params.try_conv_with(&world)?; | 207 | let file_id = params.try_conv_with(&world)?; |
199 | let mut res = Vec::new(); | 208 | let mut res = Vec::new(); |
@@ -211,6 +220,7 @@ pub fn handle_parent_module( | |||
211 | pub fn handle_runnables( | 220 | pub fn handle_runnables( |
212 | world: ServerWorld, | 221 | world: ServerWorld, |
213 | params: req::RunnablesParams, | 222 | params: req::RunnablesParams, |
223 | _token: JobToken, | ||
214 | ) -> Result<Vec<req::Runnable>> { | 224 | ) -> Result<Vec<req::Runnable>> { |
215 | let file_id = params.text_document.try_conv_with(&world)?; | 225 | let file_id = params.text_document.try_conv_with(&world)?; |
216 | let line_index = world.analysis().file_line_index(file_id); | 226 | let line_index = world.analysis().file_line_index(file_id); |
@@ -260,6 +270,7 @@ pub fn handle_runnables( | |||
260 | pub fn handle_decorations( | 270 | pub fn handle_decorations( |
261 | world: ServerWorld, | 271 | world: ServerWorld, |
262 | params: TextDocumentIdentifier, | 272 | params: TextDocumentIdentifier, |
273 | _token: JobToken, | ||
263 | ) -> Result<Vec<Decoration>> { | 274 | ) -> Result<Vec<Decoration>> { |
264 | let file_id = params.try_conv_with(&world)?; | 275 | let file_id = params.try_conv_with(&world)?; |
265 | Ok(highlight(&world, file_id)) | 276 | Ok(highlight(&world, file_id)) |
@@ -268,6 +279,7 @@ pub fn handle_decorations( | |||
268 | pub fn handle_completion( | 279 | pub fn handle_completion( |
269 | world: ServerWorld, | 280 | world: ServerWorld, |
270 | params: req::CompletionParams, | 281 | params: req::CompletionParams, |
282 | _token: JobToken, | ||
271 | ) -> Result<Option<req::CompletionResponse>> { | 283 | ) -> Result<Option<req::CompletionResponse>> { |
272 | let file_id = params.text_document.try_conv_with(&world)?; | 284 | let file_id = params.text_document.try_conv_with(&world)?; |
273 | let line_index = world.analysis().file_line_index(file_id); | 285 | let line_index = world.analysis().file_line_index(file_id); |
@@ -297,6 +309,7 @@ pub fn handle_completion( | |||
297 | pub fn handle_code_action( | 309 | pub fn handle_code_action( |
298 | world: ServerWorld, | 310 | world: ServerWorld, |
299 | params: req::CodeActionParams, | 311 | params: req::CodeActionParams, |
312 | _token: JobToken, | ||
300 | ) -> Result<Option<Vec<Command>>> { | 313 | ) -> Result<Option<Vec<Command>>> { |
301 | let file_id = params.text_document.try_conv_with(&world)?; | 314 | let file_id = params.text_document.try_conv_with(&world)?; |
302 | let line_index = world.analysis().file_line_index(file_id); | 315 | let line_index = world.analysis().file_line_index(file_id); |