mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
Auto merge of #17736 - hyf0:hyf_09234908234, r=Veykril
feat(ide-completion): explictly show `async` keyword on `impl trait` methods OLD: <img width="676" alt="image" src="https://github.com/user-attachments/assets/f6fa626f-6b6d-4c22-af27-b0755e7a6bf8"> Now: <img width="684" alt="image" src="https://github.com/user-attachments/assets/efbaac0e-c805-4dd2-859d-3e44b2886dbb"> --- This is an preparation for https://github.com/rust-lang/rust-analyzer/issues/17719. ```rust use std::future::Future; trait DesugaredAsyncTrait { fn foo(&self) -> impl Future<Output = usize> + Send; fn bar(&self) -> impl Future<Output = usize> + Send; } struct Foo; impl DesugaredAsyncTrait for Foo { fn foo(&self) -> impl Future<Output = usize> + Send { async { 1 } } // async fn bar(&self) -> usize { 1 } } fn main() { let fut = Foo.bar(); fn _assert_send<T: Send>(_: T) {} _assert_send(fut); } ``` If we don't distinguish `async` or not. It would be confusing to generate sugared version `async fn foo ....` and original form `fn foo` for `async fn in trait` that is defined in desugar form.
This commit is contained in:
commit
510a8ffff3
2 changed files with 13 additions and 5 deletions
|
@ -180,8 +180,10 @@ fn add_function_impl(
|
||||||
) {
|
) {
|
||||||
let fn_name = func.name(ctx.db);
|
let fn_name = func.name(ctx.db);
|
||||||
|
|
||||||
|
let is_async = func.is_async(ctx.db);
|
||||||
let label = format_smolstr!(
|
let label = format_smolstr!(
|
||||||
"fn {}({})",
|
"{}fn {}({})",
|
||||||
|
if is_async { "async " } else { "" },
|
||||||
fn_name.display(ctx.db),
|
fn_name.display(ctx.db),
|
||||||
if func.assoc_fn_params(ctx.db).is_empty() { "" } else { ".." }
|
if func.assoc_fn_params(ctx.db).is_empty() { "" } else { ".." }
|
||||||
);
|
);
|
||||||
|
@ -193,9 +195,13 @@ fn add_function_impl(
|
||||||
});
|
});
|
||||||
|
|
||||||
let mut item = CompletionItem::new(completion_kind, replacement_range, label);
|
let mut item = CompletionItem::new(completion_kind, replacement_range, label);
|
||||||
item.lookup_by(format!("fn {}", fn_name.display(ctx.db)))
|
item.lookup_by(format!(
|
||||||
.set_documentation(func.docs(ctx.db))
|
"{}fn {}",
|
||||||
.set_relevance(CompletionRelevance { is_item_from_trait: true, ..Default::default() });
|
if is_async { "async " } else { "" },
|
||||||
|
fn_name.display(ctx.db)
|
||||||
|
))
|
||||||
|
.set_documentation(func.docs(ctx.db))
|
||||||
|
.set_relevance(CompletionRelevance { is_item_from_trait: true, ..Default::default() });
|
||||||
|
|
||||||
if let Some(source) = ctx.sema.source(func) {
|
if let Some(source) = ctx.sema.source(func) {
|
||||||
let assoc_item = ast::AssocItem::Fn(source.value);
|
let assoc_item = ast::AssocItem::Fn(source.value);
|
||||||
|
|
|
@ -299,6 +299,7 @@ trait Test {
|
||||||
const CONST1: ();
|
const CONST1: ();
|
||||||
fn function0();
|
fn function0();
|
||||||
fn function1();
|
fn function1();
|
||||||
|
async fn function2();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Test for () {
|
impl Test for () {
|
||||||
|
@ -310,8 +311,9 @@ impl Test for () {
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
ct const CONST1: () =
|
ct const CONST1: () =
|
||||||
|
fn async fn function2()
|
||||||
fn fn function1()
|
fn fn function1()
|
||||||
ma makro!(…) macro_rules! makro
|
ma makro!(…) macro_rules! makro
|
||||||
md module
|
md module
|
||||||
ta type Type1 =
|
ta type Type1 =
|
||||||
kw crate::
|
kw crate::
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue