diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_lsp_server/src/caps.rs | 2 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/handlers.rs | 24 |
2 files changed, 24 insertions, 2 deletions
diff --git a/crates/ra_lsp_server/src/caps.rs b/crates/ra_lsp_server/src/caps.rs index bcf857fce..560f64989 100644 --- a/crates/ra_lsp_server/src/caps.rs +++ b/crates/ra_lsp_server/src/caps.rs | |||
@@ -19,7 +19,7 @@ pub fn server_capabilities() -> ServerCapabilities { | |||
19 | hover_provider: Some(true), | 19 | hover_provider: Some(true), |
20 | completion_provider: Some(CompletionOptions { | 20 | completion_provider: Some(CompletionOptions { |
21 | resolve_provider: None, | 21 | resolve_provider: None, |
22 | trigger_characters: None, | 22 | trigger_characters: Some(vec![":".to_string()]), |
23 | }), | 23 | }), |
24 | signature_help_provider: Some(SignatureHelpOptions { | 24 | signature_help_provider: Some(SignatureHelpOptions { |
25 | trigger_characters: Some(vec!["(".to_string(), ",".to_string(), ")".to_string()]), | 25 | trigger_characters: Some(vec!["(".to_string(), ",".to_string(), ")".to_string()]), |
diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index c872b0dc4..27933a7ae 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs | |||
@@ -9,7 +9,7 @@ use languageserver_types::{ | |||
9 | WorkspaceEdit, ParameterInformation, SignatureInformation, Hover, HoverContents, | 9 | WorkspaceEdit, ParameterInformation, SignatureInformation, Hover, HoverContents, |
10 | }; | 10 | }; |
11 | use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FilePosition}; | 11 | use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FilePosition}; |
12 | use ra_syntax::text_utils::contains_offset_nonstrict; | 12 | use ra_syntax::{TextUnit, text_utils::contains_offset_nonstrict}; |
13 | use rustc_hash::FxHashMap; | 13 | use rustc_hash::FxHashMap; |
14 | use serde_json::to_value; | 14 | use serde_json::to_value; |
15 | 15 | ||
@@ -381,6 +381,28 @@ pub fn handle_completion( | |||
381 | let offset = params.position.conv_with(&line_index); | 381 | let offset = params.position.conv_with(&line_index); |
382 | FilePosition { file_id, offset } | 382 | FilePosition { file_id, offset } |
383 | }; | 383 | }; |
384 | let completion_triggered_after_single_colon = { | ||
385 | let mut res = false; | ||
386 | if let Some(ctx) = params.context { | ||
387 | if ctx.trigger_character.unwrap_or(String::new()) == ":" { | ||
388 | let source_file = world.analysis().file_syntax(position.file_id); | ||
389 | let syntax = source_file.syntax(); | ||
390 | let text = syntax.text(); | ||
391 | if let Some(next_char) = text.char_at(position.offset) { | ||
392 | let diff = TextUnit::of_char(next_char) + TextUnit::of_char(':'); | ||
393 | let prev_char = position.offset - diff; | ||
394 | if text.char_at(prev_char) != Some(':') { | ||
395 | res = true; | ||
396 | } | ||
397 | } | ||
398 | } | ||
399 | } | ||
400 | res | ||
401 | }; | ||
402 | if completion_triggered_after_single_colon { | ||
403 | return Ok(None); | ||
404 | } | ||
405 | |||
384 | let items = match world.analysis().completions(position)? { | 406 | let items = match world.analysis().completions(position)? { |
385 | None => return Ok(None), | 407 | None => return Ok(None), |
386 | Some(items) => items, | 408 | Some(items) => items, |