mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-29 06:23:25 +00:00
Add trailing ;
when completing assoc const/type
This commit is contained in:
parent
a64a70ebff
commit
a182156517
1 changed files with 25 additions and 15 deletions
|
@ -228,13 +228,17 @@ fn add_type_alias_impl(
|
||||||
let alias_name = type_alias.name(ctx.db).to_smol_str();
|
let alias_name = type_alias.name(ctx.db).to_smol_str();
|
||||||
|
|
||||||
let label = format!("type {} =", alias_name);
|
let label = format!("type {} =", alias_name);
|
||||||
let snippet = format!("type {} = ", alias_name);
|
let replacement = format!("type {} = ", alias_name);
|
||||||
|
|
||||||
let mut item = CompletionItem::new(SymbolKind::TypeAlias, replacement_range, label);
|
let mut item = CompletionItem::new(SymbolKind::TypeAlias, replacement_range, label);
|
||||||
item.text_edit(TextEdit::replace(replacement_range, snippet))
|
item.lookup_by(format!("type {}", alias_name))
|
||||||
.lookup_by(format!("type {}", alias_name))
|
|
||||||
.set_documentation(type_alias.docs(ctx.db))
|
.set_documentation(type_alias.docs(ctx.db))
|
||||||
.set_relevance(CompletionRelevance { is_item_from_trait: true, ..Default::default() });
|
.set_relevance(CompletionRelevance { is_item_from_trait: true, ..Default::default() });
|
||||||
|
match ctx.config.snippet_cap {
|
||||||
|
Some(cap) => item
|
||||||
|
.snippet_edit(cap, TextEdit::replace(replacement_range, format!("{}$0;", replacement))),
|
||||||
|
None => item.text_edit(TextEdit::replace(replacement_range, replacement)),
|
||||||
|
};
|
||||||
item.add_to(acc);
|
item.add_to(acc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,16 +261,22 @@ fn add_const_impl(
|
||||||
};
|
};
|
||||||
|
|
||||||
let label = make_const_compl_syntax(&transformed_const);
|
let label = make_const_compl_syntax(&transformed_const);
|
||||||
let snippet = format!("{} ", label);
|
let replacement = format!("{} ", label);
|
||||||
|
|
||||||
let mut item = CompletionItem::new(SymbolKind::Const, replacement_range, label);
|
let mut item = CompletionItem::new(SymbolKind::Const, replacement_range, label);
|
||||||
item.text_edit(TextEdit::replace(replacement_range, snippet))
|
item.lookup_by(format!("const {}", const_name))
|
||||||
.lookup_by(format!("const {}", const_name))
|
|
||||||
.set_documentation(const_.docs(ctx.db))
|
.set_documentation(const_.docs(ctx.db))
|
||||||
.set_relevance(CompletionRelevance {
|
.set_relevance(CompletionRelevance {
|
||||||
is_item_from_trait: true,
|
is_item_from_trait: true,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
|
match ctx.config.snippet_cap {
|
||||||
|
Some(cap) => item.snippet_edit(
|
||||||
|
cap,
|
||||||
|
TextEdit::replace(replacement_range, format!("{}$0;", replacement)),
|
||||||
|
),
|
||||||
|
None => item.text_edit(TextEdit::replace(replacement_range, replacement)),
|
||||||
|
};
|
||||||
item.add_to(acc);
|
item.add_to(acc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -678,7 +688,7 @@ trait Test {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Test for () {
|
impl Test for () {
|
||||||
type SomeType = \n\
|
type SomeType = $0;\n\
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
|
@ -703,7 +713,7 @@ trait Test {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Test for () {
|
impl Test for () {
|
||||||
const SOME_CONST: u16 = \n\
|
const SOME_CONST: u16 = $0;\n\
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
|
@ -725,7 +735,7 @@ trait Test {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Test for () {
|
impl Test for () {
|
||||||
const SOME_CONST: u16 = \n\
|
const SOME_CONST: u16 = $0;\n\
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
);
|
);
|
||||||
|
@ -784,8 +794,8 @@ impl Test for T {{
|
||||||
"default const OTHER_CONST: i32 = 0;",
|
"default const OTHER_CONST: i32 = 0;",
|
||||||
] {
|
] {
|
||||||
test("fn bar", "fn $0", "fn bar() {\n $0\n}", next_sibling);
|
test("fn bar", "fn $0", "fn bar() {\n $0\n}", next_sibling);
|
||||||
test("type Foo", "type $0", "type Foo = ", next_sibling);
|
test("type Foo", "type $0", "type Foo = $0;", next_sibling);
|
||||||
test("const CONST", "const $0", "const CONST: u16 = ", next_sibling);
|
test("const CONST", "const $0", "const CONST: u16 = $0;", next_sibling);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -831,8 +841,8 @@ impl Foo for T {{
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
test("fn function", "fn f$0", "fn function() {\n $0\n}");
|
test("fn function", "fn f$0", "fn function() {\n $0\n}");
|
||||||
test("type Type", "type T$0", "type Type = ");
|
test("type Type", "type T$0", "type Type = $0;");
|
||||||
test("const CONST", "const C$0", "const CONST: i32 = ");
|
test("const CONST", "const C$0", "const CONST: i32 = $0;");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -962,7 +972,7 @@ trait Foo<T> {
|
||||||
struct Bar;
|
struct Bar;
|
||||||
|
|
||||||
impl Foo<u32> for Bar {
|
impl Foo<u32> for Bar {
|
||||||
const B$0;
|
const B$0
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
r#"
|
r#"
|
||||||
|
@ -972,7 +982,7 @@ trait Foo<T> {
|
||||||
struct Bar;
|
struct Bar;
|
||||||
|
|
||||||
impl Foo<u32> for Bar {
|
impl Foo<u32> for Bar {
|
||||||
const BAR: u32 = ;
|
const BAR: u32 = $0;
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue