diff options
Diffstat (limited to 'crates/server/src/main_loop/handlers.rs')
-rw-r--r-- | crates/server/src/main_loop/handlers.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/crates/server/src/main_loop/handlers.rs b/crates/server/src/main_loop/handlers.rs index b68e93e46..e7ac53028 100644 --- a/crates/server/src/main_loop/handlers.rs +++ b/crates/server/src/main_loop/handlers.rs | |||
@@ -4,6 +4,7 @@ use languageserver_types::{ | |||
4 | Diagnostic, DiagnosticSeverity, Url, DocumentSymbol, | 4 | Diagnostic, DiagnosticSeverity, Url, DocumentSymbol, |
5 | Command, TextDocumentIdentifier, WorkspaceEdit, | 5 | Command, TextDocumentIdentifier, WorkspaceEdit, |
6 | SymbolInformation, Position, Location, TextEdit, | 6 | SymbolInformation, Position, Location, TextEdit, |
7 | CompletionItem, | ||
7 | }; | 8 | }; |
8 | use serde_json::{to_value, from_value}; | 9 | use serde_json::{to_value, from_value}; |
9 | use libanalysis::{Query}; | 10 | use libanalysis::{Query}; |
@@ -259,6 +260,28 @@ pub fn handle_parent_module( | |||
259 | Ok(res) | 260 | Ok(res) |
260 | } | 261 | } |
261 | 262 | ||
263 | pub fn handle_completion( | ||
264 | world: ServerWorld, | ||
265 | params: req::CompletionParams, | ||
266 | ) -> Result<Option<req::CompletionResponse>> { | ||
267 | let file_id = params.text_document.try_conv_with(&world)?; | ||
268 | let file = world.analysis().file_syntax(file_id)?; | ||
269 | let line_index = world.analysis().file_line_index(file_id)?; | ||
270 | let offset = params.position.conv_with(&line_index); | ||
271 | let items = match libeditor::scope_completion(&file, offset) { | ||
272 | None => return Ok(None), | ||
273 | Some(items) => items, | ||
274 | }; | ||
275 | let items = items.into_iter() | ||
276 | .map(|item| CompletionItem { | ||
277 | label: item.name, | ||
278 | .. Default::default() | ||
279 | }) | ||
280 | .collect(); | ||
281 | |||
282 | Ok(Some(req::CompletionResponse::Array(items))) | ||
283 | } | ||
284 | |||
262 | pub fn handle_execute_command( | 285 | pub fn handle_execute_command( |
263 | world: ServerWorld, | 286 | world: ServerWorld, |
264 | mut params: req::ExecuteCommandParams, | 287 | mut params: req::ExecuteCommandParams, |