diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-11-21 16:07:14 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-11-21 16:07:14 +0000 |
commit | 1f36cef7d33edb7624f041d6eec7e597e2d6d80b (patch) | |
tree | 27e037f5d6f81bb27fbd4f0320bcd9170951884c /crates/ra_lsp_server/src | |
parent | ac874b64550c103249e2b951d92e2f1a8c9a5828 (diff) | |
parent | e8c50f091581637058838ee75ceb33ee9ef99a81 (diff) |
Merge #238
238: Use `:` as a trigger character for completion r=matklad a=matklad
Note that VSCode asks for completion after *first* `:` as well:
use crate:
we use hacks to protect against that, and to give completions only
after the second `:`.
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_lsp_server/src')
-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, |