mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 09:27:27 +00:00
Use char for trigger character
This commit is contained in:
parent
9ceaff91d3
commit
ea594c4c44
6 changed files with 16 additions and 15 deletions
|
@ -143,7 +143,7 @@ pub fn completions(
|
|||
db: &RootDatabase,
|
||||
config: &CompletionConfig,
|
||||
position: FilePosition,
|
||||
trigger_character: Option<&str>,
|
||||
trigger_character: Option<char>,
|
||||
) -> Option<Completions> {
|
||||
let ctx = &CompletionContext::new(db, position, config)?;
|
||||
let mut acc = Completions::default();
|
||||
|
@ -151,7 +151,7 @@ pub fn completions(
|
|||
{
|
||||
let acc = &mut acc;
|
||||
// prevent `(` from triggering unwanted completion noise
|
||||
if trigger_character != Some("(") {
|
||||
if trigger_character != Some('(') {
|
||||
completions::attribute::complete_attribute(acc, ctx);
|
||||
completions::attribute::complete_derive(acc, ctx);
|
||||
completions::attribute::complete_known_attribute_input(acc, ctx);
|
||||
|
|
|
@ -88,7 +88,7 @@ pub(crate) fn completion_list_no_kw(ra_fixture: &str) -> String {
|
|||
|
||||
pub(crate) fn completion_list_with_trigger_character(
|
||||
ra_fixture: &str,
|
||||
trigger_character: Option<&str>,
|
||||
trigger_character: Option<char>,
|
||||
) -> String {
|
||||
completion_list_with_config(TEST_CONFIG, ra_fixture, true, trigger_character)
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ fn completion_list_with_config(
|
|||
config: CompletionConfig,
|
||||
ra_fixture: &str,
|
||||
include_keywords: bool,
|
||||
trigger_character: Option<&str>,
|
||||
trigger_character: Option<char>,
|
||||
) -> String {
|
||||
// filter out all but one builtintype completion for smaller test outputs
|
||||
let items = get_all_items(config, ra_fixture, trigger_character);
|
||||
|
@ -225,7 +225,7 @@ pub(crate) fn check_pattern_is_applicable(code: &str, check: impl FnOnce(SyntaxE
|
|||
pub(crate) fn get_all_items(
|
||||
config: CompletionConfig,
|
||||
code: &str,
|
||||
trigger_character: Option<&str>,
|
||||
trigger_character: Option<char>,
|
||||
) -> Vec<CompletionItem> {
|
||||
let (db, position) = position(code);
|
||||
let res = crate::completions(&db, &config, position, trigger_character)
|
||||
|
|
|
@ -7,8 +7,8 @@ fn check(ra_fixture: &str, expect: Expect) {
|
|||
expect.assert_eq(&actual);
|
||||
}
|
||||
|
||||
fn check_with_trigger_character(ra_fixture: &str, trigger_character: Option<&str>, expect: Expect) {
|
||||
let actual = completion_list_with_trigger_character(ra_fixture, trigger_character);
|
||||
fn check_with_trigger_character(ra_fixture: &str, trigger_character: char, expect: Expect) {
|
||||
let actual = completion_list_with_trigger_character(ra_fixture, Some(trigger_character));
|
||||
expect.assert_eq(&actual)
|
||||
}
|
||||
|
||||
|
@ -124,7 +124,7 @@ fn trigger_by_l_paren() {
|
|||
r#"
|
||||
fn foo($0)
|
||||
"#,
|
||||
Some("("),
|
||||
'(',
|
||||
expect![[]],
|
||||
)
|
||||
}
|
||||
|
|
|
@ -8,8 +8,8 @@ fn check(ra_fixture: &str, expect: Expect) {
|
|||
expect.assert_eq(&actual)
|
||||
}
|
||||
|
||||
fn check_with_trigger_character(ra_fixture: &str, trigger_character: Option<&str>, expect: Expect) {
|
||||
let actual = completion_list_with_trigger_character(ra_fixture, trigger_character);
|
||||
fn check_with_trigger_character(ra_fixture: &str, trigger_character: char, expect: Expect) {
|
||||
let actual = completion_list_with_trigger_character(ra_fixture, Some(trigger_character));
|
||||
expect.assert_eq(&actual)
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ fn empty_pub() {
|
|||
r#"
|
||||
pub($0)
|
||||
"#,
|
||||
Some("("),
|
||||
'(',
|
||||
expect![[r#"
|
||||
kw crate
|
||||
kw in
|
||||
|
|
|
@ -548,7 +548,7 @@ impl Analysis {
|
|||
&self,
|
||||
config: &CompletionConfig,
|
||||
position: FilePosition,
|
||||
trigger_character: Option<&str>,
|
||||
trigger_character: Option<char>,
|
||||
) -> Cancellable<Option<Vec<CompletionItem>>> {
|
||||
self.with_db(|db| {
|
||||
ide_completion::completions(db, config, position, trigger_character).map(Into::into)
|
||||
|
|
|
@ -796,9 +796,10 @@ pub(crate) fn handle_completion(
|
|||
let _p = profile::span("handle_completion");
|
||||
let text_document_position = params.text_document_position.clone();
|
||||
let position = from_proto::file_position(&snap, params.text_document_position)?;
|
||||
let completion_trigger_character = params.context.and_then(|ctx| ctx.trigger_character);
|
||||
let completion_trigger_character =
|
||||
params.context.and_then(|ctx| ctx.trigger_character).and_then(|s| s.chars().next());
|
||||
|
||||
if Some(":") == completion_trigger_character.as_deref() {
|
||||
if Some(':') == completion_trigger_character {
|
||||
let source_file = snap.analysis.parse(position.file_id)?;
|
||||
let left_token = source_file.syntax().token_at_offset(position.offset).left_biased();
|
||||
let completion_triggered_after_single_colon = match left_token {
|
||||
|
@ -814,7 +815,7 @@ pub(crate) fn handle_completion(
|
|||
let items = match snap.analysis.completions(
|
||||
completion_config,
|
||||
position,
|
||||
completion_trigger_character.as_deref(),
|
||||
completion_trigger_character,
|
||||
)? {
|
||||
None => return Ok(None),
|
||||
Some(items) => items,
|
||||
|
|
Loading…
Reference in a new issue