aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_lsp_server/src/main_loop/handlers.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_lsp_server/src/main_loop/handlers.rs')
-rw-r--r--crates/ra_lsp_server/src/main_loop/handlers.rs24
1 files changed, 23 insertions, 1 deletions
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};
11use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FilePosition}; 11use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FilePosition};
12use ra_syntax::text_utils::contains_offset_nonstrict; 12use ra_syntax::{TextUnit, text_utils::contains_offset_nonstrict};
13use rustc_hash::FxHashMap; 13use rustc_hash::FxHashMap;
14use serde_json::to_value; 14use 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,