mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Compute closure captures
This commit is contained in:
parent
51d5862caf
commit
59b6f2d9f2
42 changed files with 2537 additions and 433 deletions
|
@ -5,7 +5,8 @@ use std::{
|
|||
|
||||
use either::Either;
|
||||
use hir::{
|
||||
known, HasVisibility, HirDisplay, HirDisplayError, HirWrite, ModuleDef, ModuleDefId, Semantics,
|
||||
known, ClosureStyle, HasVisibility, HirDisplay, HirDisplayError, HirWrite, ModuleDef,
|
||||
ModuleDefId, Semantics,
|
||||
};
|
||||
use ide_db::{base_db::FileRange, famous_defs::FamousDefs, RootDatabase};
|
||||
use itertools::Itertools;
|
||||
|
@ -45,6 +46,7 @@ pub struct InlayHintsConfig {
|
|||
pub param_names_for_lifetime_elision_hints: bool,
|
||||
pub hide_named_constructor_hints: bool,
|
||||
pub hide_closure_initialization_hints: bool,
|
||||
pub closure_style: ClosureStyle,
|
||||
pub max_length: Option<usize>,
|
||||
pub closing_brace_hints_min_lines: Option<usize>,
|
||||
}
|
||||
|
@ -291,6 +293,7 @@ fn label_of_ty(
|
|||
mut max_length: Option<usize>,
|
||||
ty: hir::Type,
|
||||
label_builder: &mut InlayHintLabelBuilder<'_>,
|
||||
config: &InlayHintsConfig,
|
||||
) -> Result<(), HirDisplayError> {
|
||||
let iter_item_type = hint_iterator(sema, famous_defs, &ty);
|
||||
match iter_item_type {
|
||||
|
@ -321,11 +324,14 @@ fn label_of_ty(
|
|||
label_builder.write_str(LABEL_ITEM)?;
|
||||
label_builder.end_location_link();
|
||||
label_builder.write_str(LABEL_MIDDLE2)?;
|
||||
rec(sema, famous_defs, max_length, ty, label_builder)?;
|
||||
rec(sema, famous_defs, max_length, ty, label_builder, config)?;
|
||||
label_builder.write_str(LABEL_END)?;
|
||||
Ok(())
|
||||
}
|
||||
None => ty.display_truncated(sema.db, max_length).write_to(label_builder),
|
||||
None => ty
|
||||
.display_truncated(sema.db, max_length)
|
||||
.with_closure_style(config.closure_style)
|
||||
.write_to(label_builder),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -335,7 +341,7 @@ fn label_of_ty(
|
|||
location: None,
|
||||
result: InlayHintLabel::default(),
|
||||
};
|
||||
let _ = rec(sema, famous_defs, config.max_length, ty, &mut label_builder);
|
||||
let _ = rec(sema, famous_defs, config.max_length, ty, &mut label_builder, config);
|
||||
let r = label_builder.finish();
|
||||
Some(r)
|
||||
}
|
||||
|
@ -481,6 +487,7 @@ fn closure_has_block_body(closure: &ast::ClosureExpr) -> bool {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use expect_test::Expect;
|
||||
use hir::ClosureStyle;
|
||||
use itertools::Itertools;
|
||||
use test_utils::extract_annotations;
|
||||
|
||||
|
@ -504,6 +511,7 @@ mod tests {
|
|||
binding_mode_hints: false,
|
||||
hide_named_constructor_hints: false,
|
||||
hide_closure_initialization_hints: false,
|
||||
closure_style: ClosureStyle::ImplFn,
|
||||
param_names_for_lifetime_elision_hints: false,
|
||||
max_length: None,
|
||||
closing_brace_hints_min_lines: None,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue