Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions crates/hir/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,13 @@ fn write_function<'db>(f: &mut HirFormatter<'_, 'db>, func_id: FunctionId) -> Re

write_generic_params(GenericDefId::FunctionId(func_id), f)?;

let too_long_param = data.params.len() > 4;
f.write_char('(')?;

if too_long_param {
f.write_str("\n ")?;
}

let mut first = true;
let mut skip_self = 0;
if let Some(self_param) = func.self_param(db) {
Expand All @@ -182,11 +187,12 @@ fn write_function<'db>(f: &mut HirFormatter<'_, 'db>, func_id: FunctionId) -> Re
skip_self = 1;
}

let comma = if too_long_param { ",\n " } else { ", " };
// FIXME: Use resolved `param.ty` once we no longer discard lifetimes
let body = db.body(func_id.into());
for (type_ref, param) in data.params.iter().zip(func.assoc_fn_params(db)).skip(skip_self) {
if !first {
f.write_str(", ")?;
f.write_str(comma)?;
} else {
first = false;
}
Expand All @@ -201,11 +207,14 @@ fn write_function<'db>(f: &mut HirFormatter<'_, 'db>, func_id: FunctionId) -> Re

if data.is_varargs() {
if !first {
f.write_str(", ")?;
f.write_str(comma)?;
}
f.write_str("...")?;
}

if too_long_param {
f.write_char('\n')?;
}
f.write_char(')')?;

// `FunctionData::ret_type` will be `::core::future::Future<Output = ...>` for async fns.
Expand Down
93 changes: 93 additions & 0 deletions crates/ide/src/hover/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9719,6 +9719,99 @@ fn test_hover_function_with_pat_param() {
);
}

#[test]
fn test_hover_function_with_too_long_param() {
check(
r#"
fn fn_$0(
attrs: impl IntoIterator<Item = ast::Attr>,
visibility: Option<ast::Visibility>,
fn_name: ast::Name,
type_params: Option<ast::GenericParamList>,
where_clause: Option<ast::WhereClause>,
params: ast::ParamList,
body: ast::BlockExpr,
ret_type: Option<ast::RetType>,
is_async: bool,
is_const: bool,
is_unsafe: bool,
is_gen: bool,
) -> ast::Fn {}
"#,
expect![[r#"
*fn_*

```rust
ra_test_fixture
```

```rust
fn fn_(
attrs: impl IntoIterator<Item = ast::Attr>,
visibility: Option<ast::Visibility>,
fn_name: ast::Name,
type_params: Option<ast::GenericParamList>,
where_clause: Option<ast::WhereClause>,
params: ast::ParamList,
body: ast::BlockExpr,
ret_type: Option<ast::RetType>,
is_async: bool,
is_const: bool,
is_unsafe: bool,
is_gen: bool
) -> ast::Fn
```
"#]],
);

check(
r#"
fn fn_$0(
&self,
attrs: impl IntoIterator<Item = ast::Attr>,
visibility: Option<ast::Visibility>,
fn_name: ast::Name,
type_params: Option<ast::GenericParamList>,
where_clause: Option<ast::WhereClause>,
params: ast::ParamList,
body: ast::BlockExpr,
ret_type: Option<ast::RetType>,
is_async: bool,
is_const: bool,
is_unsafe: bool,
is_gen: bool,
...
) -> ast::Fn {}
"#,
expect![[r#"
*fn_*

```rust
ra_test_fixture
```

```rust
fn fn_(
&self,
attrs: impl IntoIterator<Item = ast::Attr>,
visibility: Option<ast::Visibility>,
fn_name: ast::Name,
type_params: Option<ast::GenericParamList>,
where_clause: Option<ast::WhereClause>,
params: ast::ParamList,
body: ast::BlockExpr,
ret_type: Option<ast::RetType>,
is_async: bool,
is_const: bool,
is_unsafe: bool,
is_gen: bool,
...
) -> ast::Fn
```
"#]],
);
}

#[test]
fn hover_path_inside_block_scope() {
check(
Expand Down