mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +00:00
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 <aleksey.kladov@gmail.com>
This commit is contained in:
commit
1f36cef7d3
2 changed files with 24 additions and 2 deletions
|
@ -19,7 +19,7 @@ pub fn server_capabilities() -> ServerCapabilities {
|
||||||
hover_provider: Some(true),
|
hover_provider: Some(true),
|
||||||
completion_provider: Some(CompletionOptions {
|
completion_provider: Some(CompletionOptions {
|
||||||
resolve_provider: None,
|
resolve_provider: None,
|
||||||
trigger_characters: None,
|
trigger_characters: Some(vec![":".to_string()]),
|
||||||
}),
|
}),
|
||||||
signature_help_provider: Some(SignatureHelpOptions {
|
signature_help_provider: Some(SignatureHelpOptions {
|
||||||
trigger_characters: Some(vec!["(".to_string(), ",".to_string(), ")".to_string()]),
|
trigger_characters: Some(vec!["(".to_string(), ",".to_string(), ")".to_string()]),
|
||||||
|
|
|
@ -9,7 +9,7 @@ use languageserver_types::{
|
||||||
WorkspaceEdit, ParameterInformation, SignatureInformation, Hover, HoverContents,
|
WorkspaceEdit, ParameterInformation, SignatureInformation, Hover, HoverContents,
|
||||||
};
|
};
|
||||||
use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FilePosition};
|
use ra_analysis::{FileId, FoldKind, Query, RunnableKind, FilePosition};
|
||||||
use ra_syntax::text_utils::contains_offset_nonstrict;
|
use ra_syntax::{TextUnit, text_utils::contains_offset_nonstrict};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use serde_json::to_value;
|
use serde_json::to_value;
|
||||||
|
|
||||||
|
@ -381,6 +381,28 @@ pub fn handle_completion(
|
||||||
let offset = params.position.conv_with(&line_index);
|
let offset = params.position.conv_with(&line_index);
|
||||||
FilePosition { file_id, offset }
|
FilePosition { file_id, offset }
|
||||||
};
|
};
|
||||||
|
let completion_triggered_after_single_colon = {
|
||||||
|
let mut res = false;
|
||||||
|
if let Some(ctx) = params.context {
|
||||||
|
if ctx.trigger_character.unwrap_or(String::new()) == ":" {
|
||||||
|
let source_file = world.analysis().file_syntax(position.file_id);
|
||||||
|
let syntax = source_file.syntax();
|
||||||
|
let text = syntax.text();
|
||||||
|
if let Some(next_char) = text.char_at(position.offset) {
|
||||||
|
let diff = TextUnit::of_char(next_char) + TextUnit::of_char(':');
|
||||||
|
let prev_char = position.offset - diff;
|
||||||
|
if text.char_at(prev_char) != Some(':') {
|
||||||
|
res = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
res
|
||||||
|
};
|
||||||
|
if completion_triggered_after_single_colon {
|
||||||
|
return Ok(None);
|
||||||
|
}
|
||||||
|
|
||||||
let items = match world.analysis().completions(position)? {
|
let items = match world.analysis().completions(position)? {
|
||||||
None => return Ok(None),
|
None => return Ok(None),
|
||||||
Some(items) => items,
|
Some(items) => items,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue