refactor completions to use TextEdit instead of InsertText

This commit is contained in:
gfreezy 2019-01-19 22:02:50 +08:00
parent fa43ef30f4
commit d08e81cdd8
54 changed files with 2320 additions and 313 deletions

View file

@ -15,7 +15,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
hir::Def::Module(module) => {
let module_scope = module.scope(ctx.db);
for (name, res) in module_scope.entries() {
CompletionItem::new(CompletionKind::Reference, name.to_string())
CompletionItem::new(CompletionKind::Reference, ctx, name.to_string())
.from_resolution(ctx, res)
.add_to(acc);
}
@ -24,7 +24,7 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
e.variants(ctx.db)
.into_iter()
.for_each(|(variant_name, _variant)| {
CompletionItem::new(CompletionKind::Reference, variant_name.to_string())
CompletionItem::new(CompletionKind::Reference, ctx, variant_name.to_string())
.kind(CompletionItemKind::EnumVariant)
.add_to(acc)
});
@ -35,7 +35,8 @@ pub(super) fn complete_path(acc: &mut Completions, ctx: &CompletionContext) {
#[cfg(test)]
mod tests {
use crate::completion::{CompletionKind, check_completion};
use crate::completion::CompletionKind;
use crate::completion::completion_item::check_completion;
fn check_reference_completion(code: &str, expected_completions: &str) {
check_completion(code, expected_completions, CompletionKind::Reference);
@ -44,6 +45,7 @@ mod tests {
#[test]
fn completes_use_item_starting_with_self() {
check_reference_completion(
"use_item_starting_with_self",
r"
use self::m::<|>;
@ -51,13 +53,13 @@ mod tests {
struct Bar;
}
",
"Bar",
);
}
#[test]
fn completes_use_item_starting_with_crate() {
check_reference_completion(
"use_item_starting_with_crate",
"
//- /lib.rs
mod foo;
@ -65,13 +67,13 @@ mod tests {
//- /foo.rs
use crate::Sp<|>
",
"Spam;foo",
);
}
#[test]
fn completes_nested_use_tree() {
check_reference_completion(
"nested_use_tree",
"
//- /lib.rs
mod foo;
@ -79,13 +81,13 @@ mod tests {
//- /foo.rs
use crate::{Sp<|>};
",
"Spam;foo",
);
}
#[test]
fn completes_deeply_nested_use_tree() {
check_reference_completion(
"deeply_nested_use_tree",
"
//- /lib.rs
mod foo;
@ -97,37 +99,37 @@ mod tests {
//- /foo.rs
use crate::{bar::{baz::Sp<|>}};
",
"Spam",
);
}
#[test]
fn completes_enum_variant() {
check_reference_completion(
"reference_completion",
"
//- /lib.rs
enum E { Foo, Bar(i32) }
fn foo() { let _ = E::<|> }
",
"Foo;Bar",
);
}
#[test]
fn dont_render_function_parens_in_use_item() {
check_reference_completion(
"dont_render_function_parens_in_use_item",
"
//- /lib.rs
mod m { pub fn foo() {} }
use crate::m::f<|>;
",
"foo",
)
}
#[test]
fn dont_render_function_parens_if_already_call() {
check_reference_completion(
"dont_render_function_parens_if_already_call",
"
//- /lib.rs
fn frobnicate() {}
@ -135,7 +137,6 @@ mod tests {
frob<|>();
}
",
"main;frobnicate",
)
}
}