mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 11:59:49 +00:00
Cleanup term search related changes
This commit is contained in:
parent
88964c0b6a
commit
125791386d
26 changed files with 590 additions and 516 deletions
|
@ -159,9 +159,8 @@ impl Completions {
|
|||
}
|
||||
|
||||
pub(crate) fn add_expr(&mut self, ctx: &CompletionContext<'_>, expr: &hir::term_search::Expr) {
|
||||
match render_expr(ctx, expr) {
|
||||
Some(item) => item.add_to(self, ctx.db),
|
||||
None => (),
|
||||
if let Some(item) = render_expr(ctx, expr) {
|
||||
item.add_to(self, ctx.db)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -759,7 +758,6 @@ pub(super) fn complete_name_ref(
|
|||
flyimport::import_on_the_fly_dot(acc, ctx, dot_access);
|
||||
dot::complete_dot(acc, ctx, dot_access);
|
||||
postfix::complete_postfix(acc, ctx, dot_access);
|
||||
expr::complete_expr(acc, ctx);
|
||||
}
|
||||
NameRefKind::Keyword(item) => {
|
||||
keyword::complete_for_and_where(acc, ctx, item);
|
||||
|
|
|
@ -342,7 +342,7 @@ pub(crate) fn complete_expr(acc: &mut Completions, ctx: &CompletionContext<'_>)
|
|||
|
||||
if let Some(ty) = &ctx.expected_type {
|
||||
// Ignore unit types as they are not very interesting
|
||||
if ty.is_unit() {
|
||||
if ty.is_unit() || ty.is_unknown() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -297,6 +297,7 @@ pub enum CompletionItemKind {
|
|||
Method,
|
||||
Snippet,
|
||||
UnresolvedReference,
|
||||
Expression,
|
||||
}
|
||||
|
||||
impl_from!(SymbolKind for CompletionItemKind);
|
||||
|
@ -341,6 +342,7 @@ impl CompletionItemKind {
|
|||
CompletionItemKind::Method => "me",
|
||||
CompletionItemKind::Snippet => "sn",
|
||||
CompletionItemKind::UnresolvedReference => "??",
|
||||
CompletionItemKind::Expression => "ex",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -295,22 +295,24 @@ pub(crate) fn render_expr(
|
|||
.unwrap_or_else(|| String::from("..."))
|
||||
};
|
||||
|
||||
let label = expr.gen_source_code(
|
||||
&ctx.scope,
|
||||
&mut label_formatter,
|
||||
ctx.config.prefer_no_std,
|
||||
ctx.config.prefer_prelude,
|
||||
);
|
||||
let label = expr
|
||||
.gen_source_code(
|
||||
&ctx.scope,
|
||||
&mut label_formatter,
|
||||
ctx.config.prefer_no_std,
|
||||
ctx.config.prefer_prelude,
|
||||
)
|
||||
.ok()?;
|
||||
|
||||
let source_range = match ctx.original_token.parent() {
|
||||
Some(node) => match node.ancestors().find_map(|n| ast::Path::cast(n)) {
|
||||
Some(node) => match node.ancestors().find_map(ast::Path::cast) {
|
||||
Some(path) => path.syntax().text_range(),
|
||||
None => node.text_range(),
|
||||
},
|
||||
None => ctx.source_range(),
|
||||
};
|
||||
|
||||
let mut item = CompletionItem::new(CompletionItemKind::Snippet, source_range, label.clone());
|
||||
let mut item = CompletionItem::new(CompletionItemKind::Expression, source_range, label.clone());
|
||||
|
||||
let snippet = format!(
|
||||
"{}$0",
|
||||
|
@ -320,6 +322,7 @@ pub(crate) fn render_expr(
|
|||
ctx.config.prefer_no_std,
|
||||
ctx.config.prefer_prelude
|
||||
)
|
||||
.ok()?
|
||||
);
|
||||
let edit = TextEdit::replace(source_range, snippet);
|
||||
item.snippet_edit(ctx.config.snippet_cap?, edit);
|
||||
|
@ -1034,6 +1037,7 @@ fn func(input: Struct) { }
|
|||
st Self [type]
|
||||
sp Self [type]
|
||||
st Struct [type]
|
||||
ex Struct [type]
|
||||
lc self [local]
|
||||
fn func(…) []
|
||||
me self.test() []
|
||||
|
@ -1058,6 +1062,9 @@ fn main() {
|
|||
"#,
|
||||
expect![[r#"
|
||||
lc input [type+name+local]
|
||||
ex input [type]
|
||||
ex true [type]
|
||||
ex false [type]
|
||||
lc inputbad [local]
|
||||
fn main() []
|
||||
fn test(…) []
|
||||
|
@ -1738,6 +1745,10 @@ fn f() { A { bar: b$0 }; }
|
|||
expect![[r#"
|
||||
fn bar() [type+name]
|
||||
fn baz() [type]
|
||||
ex baz() [type]
|
||||
ex bar() [type]
|
||||
ex A { bar: baz() }.bar [type]
|
||||
ex A { bar: bar() }.bar [type]
|
||||
st A []
|
||||
fn f() []
|
||||
"#]],
|
||||
|
@ -1822,6 +1833,8 @@ fn main() {
|
|||
lc s [type+name+local]
|
||||
st S [type]
|
||||
st S [type]
|
||||
ex s [type]
|
||||
ex S [type]
|
||||
fn foo(…) []
|
||||
fn main() []
|
||||
"#]],
|
||||
|
@ -1839,6 +1852,8 @@ fn main() {
|
|||
lc ssss [type+local]
|
||||
st S [type]
|
||||
st S [type]
|
||||
ex ssss [type]
|
||||
ex S [type]
|
||||
fn foo(…) []
|
||||
fn main() []
|
||||
"#]],
|
||||
|
@ -1871,6 +1886,8 @@ fn main() {
|
|||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
ex core::ops::Deref::deref(&T(S)) (use core::ops::Deref) [type_could_unify]
|
||||
ex core::ops::Deref::deref(&t) (use core::ops::Deref) [type_could_unify]
|
||||
lc m [local]
|
||||
lc t [local]
|
||||
lc &t [type+local]
|
||||
|
@ -1919,6 +1936,8 @@ fn main() {
|
|||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
ex core::ops::DerefMut::deref_mut(&mut T(S)) (use core::ops::DerefMut) [type_could_unify]
|
||||
ex core::ops::DerefMut::deref_mut(&mut t) (use core::ops::DerefMut) [type_could_unify]
|
||||
lc m [local]
|
||||
lc t [local]
|
||||
lc &mut t [type+local]
|
||||
|
@ -1967,6 +1986,8 @@ fn bar(t: Foo) {}
|
|||
ev Foo::A [type]
|
||||
ev Foo::B [type]
|
||||
en Foo [type]
|
||||
ex Foo::A [type]
|
||||
ex Foo::B [type]
|
||||
fn bar(…) []
|
||||
fn foo() []
|
||||
"#]],
|
||||
|
@ -2020,6 +2041,8 @@ fn main() {
|
|||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
ex core::ops::Deref::deref(&T(S)) (use core::ops::Deref) [type_could_unify]
|
||||
ex core::ops::Deref::deref(&bar()) (use core::ops::Deref) [type_could_unify]
|
||||
st S []
|
||||
st &S [type]
|
||||
st S []
|
||||
|
@ -2233,6 +2256,7 @@ fn foo() {
|
|||
"#,
|
||||
expect![[r#"
|
||||
lc foo [type+local]
|
||||
ex foo [type]
|
||||
ev Foo::A(…) [type_could_unify]
|
||||
ev Foo::B [type_could_unify]
|
||||
en Foo [type_could_unify]
|
||||
|
@ -2267,8 +2291,6 @@ fn main() {
|
|||
&[CompletionItemKind::Snippet, CompletionItemKind::Method],
|
||||
expect![[r#"
|
||||
sn not [snippet]
|
||||
sn true [type]
|
||||
sn false [type]
|
||||
me not() (use ops::Not) [type_could_unify+requires_import]
|
||||
sn if []
|
||||
sn while []
|
||||
|
|
|
@ -97,11 +97,11 @@ fn func(param0 @ (param1, param2): (i32, i32)) {
|
|||
kw unsafe
|
||||
kw while
|
||||
kw while let
|
||||
sn ifletlocal
|
||||
sn letlocal
|
||||
sn matcharm
|
||||
sn param1
|
||||
sn param2
|
||||
ex ifletlocal
|
||||
ex letlocal
|
||||
ex matcharm
|
||||
ex param1
|
||||
ex param2
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
@ -243,11 +243,11 @@ fn complete_in_block() {
|
|||
kw use
|
||||
kw while
|
||||
kw while let
|
||||
sn false
|
||||
sn macro_rules
|
||||
sn pd
|
||||
sn ppd
|
||||
sn true
|
||||
ex false
|
||||
ex true
|
||||
"#]],
|
||||
)
|
||||
}
|
||||
|
@ -690,8 +690,8 @@ fn main() {
|
|||
"#,
|
||||
expect![[r#"
|
||||
fn test() fn() -> Zulu
|
||||
sn Zulu
|
||||
sn Zulu::test()
|
||||
ex Zulu
|
||||
ex Zulu::test()
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
|
|
@ -192,8 +192,8 @@ fn main() {
|
|||
bt u32 u32
|
||||
kw crate::
|
||||
kw self::
|
||||
sn Foo::default()
|
||||
sn foo
|
||||
ex Foo::default()
|
||||
ex foo
|
||||
"#]],
|
||||
);
|
||||
check(
|
||||
|
|
|
@ -225,10 +225,10 @@ impl S {
|
|||
fn foo() { let _ = lib::S::$0 }
|
||||
"#,
|
||||
expect![[r#"
|
||||
ct PUBLIC_CONST pub const PUBLIC_CONST: u32
|
||||
fn public_method() fn()
|
||||
ta PublicType pub type PublicType = u32
|
||||
"#]],
|
||||
ct PUBLIC_CONST pub const PUBLIC_CONST: u32
|
||||
fn public_method() fn()
|
||||
ta PublicType pub type PublicType = u32
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -242,8 +242,8 @@ impl U { fn m() { } }
|
|||
fn foo() { let _ = U::$0 }
|
||||
"#,
|
||||
expect![[r#"
|
||||
fn m() fn()
|
||||
"#]],
|
||||
fn m() fn()
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -256,8 +256,8 @@ trait Trait { fn m(); }
|
|||
fn foo() { let _ = Trait::$0 }
|
||||
"#,
|
||||
expect![[r#"
|
||||
fn m() (as Trait) fn()
|
||||
"#]],
|
||||
fn m() (as Trait) fn()
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -273,8 +273,8 @@ impl Trait for S {}
|
|||
fn foo() { let _ = S::$0 }
|
||||
"#,
|
||||
expect![[r#"
|
||||
fn m() (as Trait) fn()
|
||||
"#]],
|
||||
fn m() (as Trait) fn()
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -290,8 +290,8 @@ impl Trait for S {}
|
|||
fn foo() { let _ = <S as Trait>::$0 }
|
||||
"#,
|
||||
expect![[r#"
|
||||
fn m() (as Trait) fn()
|
||||
"#]],
|
||||
fn m() (as Trait) fn()
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -396,9 +396,9 @@ macro_rules! foo { () => {} }
|
|||
fn main() { let _ = crate::$0 }
|
||||
"#,
|
||||
expect![[r#"
|
||||
fn main() fn()
|
||||
ma foo!(…) macro_rules! foo
|
||||
"#]],
|
||||
fn main() fn()
|
||||
ma foo!(…) macro_rules! foo
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -694,8 +694,10 @@ fn bar() -> Bar {
|
|||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
fn foo() (as Foo) fn() -> Self
|
||||
"#]],
|
||||
fn foo() (as Foo) fn() -> Self
|
||||
ex Bar
|
||||
ex bar()
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -722,6 +724,8 @@ fn bar() -> Bar {
|
|||
expect![[r#"
|
||||
fn bar() fn()
|
||||
fn foo() (as Foo) fn() -> Self
|
||||
ex Bar
|
||||
ex bar()
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
@ -748,6 +752,8 @@ fn bar() -> Bar {
|
|||
"#,
|
||||
expect![[r#"
|
||||
fn foo() (as Foo) fn() -> Self
|
||||
ex Bar
|
||||
ex bar()
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
@ -1230,10 +1236,6 @@ fn here_we_go() {
|
|||
"#,
|
||||
expect![[r#"
|
||||
st Bar (alias Qux) Bar
|
||||
sn ()
|
||||
sn false
|
||||
sn here_we_go()
|
||||
sn true
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
@ -1288,10 +1290,6 @@ fn here_we_go() {
|
|||
kw unsafe
|
||||
kw while
|
||||
kw while let
|
||||
sn ()
|
||||
sn false
|
||||
sn here_we_go()
|
||||
sn true
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue