diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/libeditor/src/completion.rs | 2 | ||||
-rw-r--r-- | crates/server/src/caps.rs | 6 | ||||
-rw-r--r-- | crates/server/src/main_loop/handlers.rs | 23 | ||||
-rw-r--r-- | crates/server/src/main_loop/mod.rs | 4 | ||||
-rw-r--r-- | crates/server/src/req.rs | 1 |
5 files changed, 34 insertions, 2 deletions
diff --git a/crates/libeditor/src/completion.rs b/crates/libeditor/src/completion.rs index 16c9ead74..aeed19559 100644 --- a/crates/libeditor/src/completion.rs +++ b/crates/libeditor/src/completion.rs | |||
@@ -14,7 +14,7 @@ use { | |||
14 | 14 | ||
15 | #[derive(Debug)] | 15 | #[derive(Debug)] |
16 | pub struct CompletionItem { | 16 | pub struct CompletionItem { |
17 | name: String, | 17 | pub name: String, |
18 | } | 18 | } |
19 | 19 | ||
20 | pub fn scope_completion(file: &File, offset: TextUnit) -> Option<Vec<CompletionItem>> { | 20 | pub fn scope_completion(file: &File, offset: TextUnit) -> Option<Vec<CompletionItem>> { |
diff --git a/crates/server/src/caps.rs b/crates/server/src/caps.rs index ffebd9b47..98499bb05 100644 --- a/crates/server/src/caps.rs +++ b/crates/server/src/caps.rs | |||
@@ -4,6 +4,7 @@ use languageserver_types::{ | |||
4 | TextDocumentSyncOptions, | 4 | TextDocumentSyncOptions, |
5 | TextDocumentSyncKind, | 5 | TextDocumentSyncKind, |
6 | ExecuteCommandOptions, | 6 | ExecuteCommandOptions, |
7 | CompletionOptions, | ||
7 | }; | 8 | }; |
8 | 9 | ||
9 | pub fn server_capabilities() -> ServerCapabilities { | 10 | pub fn server_capabilities() -> ServerCapabilities { |
@@ -18,7 +19,10 @@ pub fn server_capabilities() -> ServerCapabilities { | |||
18 | } | 19 | } |
19 | )), | 20 | )), |
20 | hover_provider: None, | 21 | hover_provider: None, |
21 | completion_provider: None, | 22 | completion_provider: Some(CompletionOptions { |
23 | resolve_provider: None, | ||
24 | trigger_characters: None, | ||
25 | }), | ||
22 | signature_help_provider: None, | 26 | signature_help_provider: None, |
23 | definition_provider: Some(true), | 27 | definition_provider: Some(true), |
24 | type_definition_provider: None, | 28 | type_definition_provider: None, |
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, |
diff --git a/crates/server/src/main_loop/mod.rs b/crates/server/src/main_loop/mod.rs index 1e65041e2..5213ecc04 100644 --- a/crates/server/src/main_loop/mod.rs +++ b/crates/server/src/main_loop/mod.rs | |||
@@ -28,6 +28,7 @@ use { | |||
28 | handle_find_matching_brace, | 28 | handle_find_matching_brace, |
29 | handle_parent_module, | 29 | handle_parent_module, |
30 | handle_join_lines, | 30 | handle_join_lines, |
31 | handle_completion, | ||
31 | }, | 32 | }, |
32 | }; | 33 | }; |
33 | 34 | ||
@@ -143,6 +144,9 @@ fn on_request( | |||
143 | handle_request_on_threadpool::<req::GotoDefinition>( | 144 | handle_request_on_threadpool::<req::GotoDefinition>( |
144 | &mut req, pool, world, sender, handle_goto_definition, | 145 | &mut req, pool, world, sender, handle_goto_definition, |
145 | )?; | 146 | )?; |
147 | handle_request_on_threadpool::<req::Completion>( | ||
148 | &mut req, pool, world, sender, handle_completion, | ||
149 | )?; | ||
146 | handle_request_on_threadpool::<req::ParentModule>( | 150 | handle_request_on_threadpool::<req::ParentModule>( |
147 | &mut req, pool, world, sender, handle_parent_module, | 151 | &mut req, pool, world, sender, handle_parent_module, |
148 | )?; | 152 | )?; |
diff --git a/crates/server/src/req.rs b/crates/server/src/req.rs index c431deeb4..6d3466b66 100644 --- a/crates/server/src/req.rs +++ b/crates/server/src/req.rs | |||
@@ -11,6 +11,7 @@ pub use languageserver_types::{ | |||
11 | WorkspaceSymbolParams, | 11 | WorkspaceSymbolParams, |
12 | TextDocumentPositionParams, | 12 | TextDocumentPositionParams, |
13 | TextEdit, | 13 | TextEdit, |
14 | CompletionParams, CompletionResponse, | ||
14 | }; | 15 | }; |
15 | 16 | ||
16 | 17 | ||