mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-28 02:29:44 +00:00
Remove unnecessary parameters in inlay-hint computation
This commit is contained in:
parent
25808c1ba1
commit
d2164fe08b
10 changed files with 41 additions and 58 deletions
|
|
@ -6,7 +6,7 @@ use std::{
|
|||
use either::Either;
|
||||
use hir::{
|
||||
ClosureStyle, DisplayTarget, EditionedFileId, HasVisibility, HirDisplay, HirDisplayError,
|
||||
HirWrite, ModuleDef, ModuleDefId, Semantics, sym,
|
||||
HirWrite, InRealFile, ModuleDef, ModuleDefId, Semantics, sym,
|
||||
};
|
||||
use ide_db::{FileRange, RootDatabase, famous_defs::FamousDefs, text_edit::TextEditBuilder};
|
||||
use ide_db::{FxHashSet, text_edit::TextEdit};
|
||||
|
|
@ -95,16 +95,16 @@ pub(crate) fn inlay_hints(
|
|||
return acc;
|
||||
};
|
||||
let famous_defs = FamousDefs(&sema, scope.krate());
|
||||
let display_target = famous_defs.1.to_display_target(sema.db);
|
||||
|
||||
let ctx = &mut InlayHintCtx::default();
|
||||
let mut hints = |event| {
|
||||
if let Some(node) = handle_event(ctx, event) {
|
||||
hints(&mut acc, ctx, &famous_defs, config, file_id, node);
|
||||
hints(&mut acc, ctx, &famous_defs, config, file_id, display_target, node);
|
||||
}
|
||||
};
|
||||
let mut preorder = file.preorder();
|
||||
while let Some(event) = preorder.next() {
|
||||
// FIXME: This can miss some hints that require the parent of the range to calculate
|
||||
if matches!((&event, range_limit), (WalkEvent::Enter(node), Some(range)) if range.intersect(node.text_range()).is_none())
|
||||
{
|
||||
preorder.skip_subtree();
|
||||
|
|
@ -144,10 +144,12 @@ pub(crate) fn inlay_hints_resolve(
|
|||
let famous_defs = FamousDefs(&sema, scope.krate());
|
||||
let mut acc = Vec::new();
|
||||
|
||||
let display_target = famous_defs.1.to_display_target(sema.db);
|
||||
|
||||
let ctx = &mut InlayHintCtx::default();
|
||||
let mut hints = |event| {
|
||||
if let Some(node) = handle_event(ctx, event) {
|
||||
hints(&mut acc, ctx, &famous_defs, config, file_id, node);
|
||||
hints(&mut acc, ctx, &famous_defs, config, file_id, display_target, node);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -202,17 +204,19 @@ fn handle_event(ctx: &mut InlayHintCtx, node: WalkEvent<SyntaxNode>) -> Option<S
|
|||
fn hints(
|
||||
hints: &mut Vec<InlayHint>,
|
||||
ctx: &mut InlayHintCtx,
|
||||
famous_defs @ FamousDefs(sema, _): &FamousDefs<'_, '_>,
|
||||
famous_defs @ FamousDefs(sema, _krate): &FamousDefs<'_, '_>,
|
||||
config: &InlayHintsConfig,
|
||||
file_id: EditionedFileId,
|
||||
display_target: DisplayTarget,
|
||||
node: SyntaxNode,
|
||||
) {
|
||||
let file_id = file_id.editioned_file_id(sema.db);
|
||||
let Some(krate) = sema.first_crate(file_id.file_id()) else {
|
||||
return;
|
||||
};
|
||||
let display_target = krate.to_display_target(sema.db);
|
||||
closing_brace::hints(hints, sema, config, file_id, display_target, node.clone());
|
||||
closing_brace::hints(
|
||||
hints,
|
||||
sema,
|
||||
config,
|
||||
display_target,
|
||||
InRealFile { file_id, value: node.clone() },
|
||||
);
|
||||
if let Some(any_has_generic_args) = ast::AnyHasGenericArgs::cast(node.clone()) {
|
||||
generic_param::hints(hints, famous_defs, config, any_has_generic_args);
|
||||
}
|
||||
|
|
@ -231,18 +235,18 @@ fn hints(
|
|||
closure_captures::hints(hints, famous_defs, config, it.clone());
|
||||
closure_ret::hints(hints, famous_defs, config, display_target, it)
|
||||
},
|
||||
ast::Expr::RangeExpr(it) => range_exclusive::hints(hints, famous_defs, config, file_id, it),
|
||||
ast::Expr::RangeExpr(it) => range_exclusive::hints(hints, famous_defs, config, it),
|
||||
_ => Some(()),
|
||||
}
|
||||
},
|
||||
ast::Pat(it) => {
|
||||
binding_mode::hints(hints, famous_defs, config, file_id, &it);
|
||||
binding_mode::hints(hints, famous_defs, config, &it);
|
||||
match it {
|
||||
ast::Pat::IdentPat(it) => {
|
||||
bind_pat::hints(hints, famous_defs, config, display_target, &it);
|
||||
}
|
||||
ast::Pat::RangePat(it) => {
|
||||
range_exclusive::hints(hints, famous_defs, config, file_id, it);
|
||||
range_exclusive::hints(hints, famous_defs, config, it);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
|
@ -250,30 +254,33 @@ fn hints(
|
|||
},
|
||||
ast::Item(it) => match it {
|
||||
ast::Item::Fn(it) => {
|
||||
implicit_drop::hints(hints, famous_defs, config, file_id, &it);
|
||||
implicit_drop::hints(hints, famous_defs, config, display_target, &it);
|
||||
if let Some(extern_block) = &ctx.extern_block_parent {
|
||||
extern_block::fn_hints(hints, famous_defs, config, file_id, &it, extern_block);
|
||||
extern_block::fn_hints(hints, famous_defs, config, &it, extern_block);
|
||||
}
|
||||
lifetime::fn_hints(hints, ctx, famous_defs, config, file_id, it)
|
||||
lifetime::fn_hints(hints, ctx, famous_defs, config, it)
|
||||
},
|
||||
ast::Item::Static(it) => {
|
||||
if let Some(extern_block) = &ctx.extern_block_parent {
|
||||
extern_block::static_hints(hints, famous_defs, config, file_id, &it, extern_block);
|
||||
extern_block::static_hints(hints, famous_defs, config, &it, extern_block);
|
||||
}
|
||||
implicit_static::hints(hints, famous_defs, config, file_id, Either::Left(it))
|
||||
implicit_static::hints(hints, famous_defs, config, Either::Left(it))
|
||||
},
|
||||
ast::Item::Const(it) => implicit_static::hints(hints, famous_defs, config, file_id, Either::Right(it)),
|
||||
ast::Item::Enum(it) => discriminant::enum_hints(hints, famous_defs, config, file_id, it),
|
||||
ast::Item::ExternBlock(it) => extern_block::extern_block_hints(hints, famous_defs, config, file_id, it),
|
||||
ast::Item::Const(it) => implicit_static::hints(hints, famous_defs, config, Either::Right(it)),
|
||||
ast::Item::Enum(it) => discriminant::enum_hints(hints, famous_defs, config, it),
|
||||
ast::Item::ExternBlock(it) => extern_block::extern_block_hints(hints, famous_defs, config, it),
|
||||
_ => None,
|
||||
},
|
||||
// FIXME: trait object type elisions
|
||||
ast::Type(ty) => match ty {
|
||||
ast::Type::FnPtrType(ptr) => lifetime::fn_ptr_hints(hints, ctx, famous_defs, config, file_id, ptr),
|
||||
ast::Type::PathType(path) => lifetime::fn_path_hints(hints, ctx, famous_defs, config, file_id, path),
|
||||
ast::Type::FnPtrType(ptr) => lifetime::fn_ptr_hints(hints, ctx, famous_defs, config, ptr),
|
||||
ast::Type::PathType(path) => {
|
||||
lifetime::fn_path_hints(hints, ctx, famous_defs, config, path);
|
||||
Some(())
|
||||
},
|
||||
_ => Some(()),
|
||||
},
|
||||
ast::GenericParamList(it) => bounds::hints(hints, famous_defs, config, file_id, it),
|
||||
ast::GenericParamList(it) => bounds::hints(hints, famous_defs, config, it),
|
||||
_ => Some(()),
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ use hir::Mutability;
|
|||
use ide_db::famous_defs::FamousDefs;
|
||||
|
||||
use ide_db::text_edit::TextEditBuilder;
|
||||
use span::EditionedFileId;
|
||||
use syntax::ast::{self, AstNode};
|
||||
|
||||
use crate::{InlayHint, InlayHintLabel, InlayHintPosition, InlayHintsConfig, InlayKind};
|
||||
|
|
@ -17,7 +16,6 @@ pub(super) fn hints(
|
|||
acc: &mut Vec<InlayHint>,
|
||||
FamousDefs(sema, _): &FamousDefs<'_, '_>,
|
||||
config: &InlayHintsConfig,
|
||||
_file_id: EditionedFileId,
|
||||
pat: &ast::Pat,
|
||||
) -> Option<()> {
|
||||
if !config.binding_mode_hints {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
//! Currently this renders the implied `Sized` bound.
|
||||
use ide_db::{FileRange, famous_defs::FamousDefs};
|
||||
|
||||
use span::EditionedFileId;
|
||||
use syntax::ast::{self, AstNode, HasTypeBounds};
|
||||
|
||||
use crate::{
|
||||
|
|
@ -15,7 +14,6 @@ pub(super) fn hints(
|
|||
acc: &mut Vec<InlayHint>,
|
||||
famous_defs @ FamousDefs(sema, _): &FamousDefs<'_, '_>,
|
||||
config: &InlayHintsConfig,
|
||||
_file_id: EditionedFileId,
|
||||
params: ast::GenericParamList,
|
||||
) -> Option<()> {
|
||||
if !config.sized_bound {
|
||||
|
|
|
|||
|
|
@ -3,9 +3,8 @@
|
|||
//! fn g() {
|
||||
//! } /* fn g */
|
||||
//! ```
|
||||
use hir::{DisplayTarget, HirDisplay, Semantics};
|
||||
use hir::{DisplayTarget, HirDisplay, InRealFile, Semantics};
|
||||
use ide_db::{FileRange, RootDatabase};
|
||||
use span::EditionedFileId;
|
||||
use syntax::{
|
||||
SyntaxKind, SyntaxNode, T,
|
||||
ast::{self, AstNode, HasLoopBody, HasName},
|
||||
|
|
@ -21,15 +20,14 @@ pub(super) fn hints(
|
|||
acc: &mut Vec<InlayHint>,
|
||||
sema: &Semantics<'_, RootDatabase>,
|
||||
config: &InlayHintsConfig,
|
||||
file_id: EditionedFileId,
|
||||
display_target: DisplayTarget,
|
||||
original_node: SyntaxNode,
|
||||
InRealFile { file_id, value: node }: InRealFile<SyntaxNode>,
|
||||
) -> Option<()> {
|
||||
let min_lines = config.closing_brace_hints_min_lines?;
|
||||
|
||||
let name = |it: ast::Name| it.syntax().text_range();
|
||||
|
||||
let mut node = original_node.clone();
|
||||
let mut node = node.clone();
|
||||
let mut closing_token;
|
||||
let (label, name_range) = if let Some(item_list) = ast::AssocItemList::cast(node.clone()) {
|
||||
closing_token = item_list.r_curly_token()?;
|
||||
|
|
@ -44,7 +42,7 @@ pub(super) fn hints(
|
|||
let hint_text = match trait_ {
|
||||
Some(tr) => format!(
|
||||
"impl {} for {}",
|
||||
tr.name(sema.db).display(sema.db, file_id.edition()),
|
||||
tr.name(sema.db).display(sema.db, display_target.edition),
|
||||
ty.display_truncated(sema.db, config.max_length, display_target,
|
||||
)),
|
||||
None => format!("impl {}", ty.display_truncated(sema.db, config.max_length, display_target)),
|
||||
|
|
@ -142,7 +140,8 @@ pub(super) fn hints(
|
|||
return None;
|
||||
}
|
||||
|
||||
let linked_location = name_range.map(|range| FileRange { file_id: file_id.into(), range });
|
||||
let linked_location =
|
||||
name_range.map(|range| FileRange { file_id: file_id.file_id(sema.db), range });
|
||||
acc.push(InlayHint {
|
||||
range: closing_token.text_range(),
|
||||
kind: InlayKind::ClosingBrace,
|
||||
|
|
@ -151,7 +150,7 @@ pub(super) fn hints(
|
|||
position: InlayHintPosition::After,
|
||||
pad_left: true,
|
||||
pad_right: false,
|
||||
resolve_parent: Some(original_node.text_range()),
|
||||
resolve_parent: Some(node.text_range()),
|
||||
});
|
||||
|
||||
None
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@
|
|||
use hir::Semantics;
|
||||
use ide_db::text_edit::TextEdit;
|
||||
use ide_db::{RootDatabase, famous_defs::FamousDefs};
|
||||
use span::EditionedFileId;
|
||||
use syntax::ast::{self, AstNode, HasName};
|
||||
|
||||
use crate::{
|
||||
|
|
@ -19,7 +18,6 @@ pub(super) fn enum_hints(
|
|||
acc: &mut Vec<InlayHint>,
|
||||
FamousDefs(sema, _): &FamousDefs<'_, '_>,
|
||||
config: &InlayHintsConfig,
|
||||
_: EditionedFileId,
|
||||
enum_: ast::Enum,
|
||||
) -> Option<()> {
|
||||
if let DiscriminantHints::Never = config.discriminant_hints {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
//! Extern block hints
|
||||
use ide_db::{famous_defs::FamousDefs, text_edit::TextEdit};
|
||||
use span::EditionedFileId;
|
||||
use syntax::{AstNode, SyntaxToken, ast};
|
||||
|
||||
use crate::{InlayHint, InlayHintsConfig};
|
||||
|
|
@ -9,7 +8,6 @@ pub(super) fn extern_block_hints(
|
|||
acc: &mut Vec<InlayHint>,
|
||||
FamousDefs(sema, _): &FamousDefs<'_, '_>,
|
||||
config: &InlayHintsConfig,
|
||||
_file_id: EditionedFileId,
|
||||
extern_block: ast::ExternBlock,
|
||||
) -> Option<()> {
|
||||
if extern_block.unsafe_token().is_some() {
|
||||
|
|
@ -36,7 +34,6 @@ pub(super) fn fn_hints(
|
|||
acc: &mut Vec<InlayHint>,
|
||||
FamousDefs(sema, _): &FamousDefs<'_, '_>,
|
||||
config: &InlayHintsConfig,
|
||||
_file_id: EditionedFileId,
|
||||
fn_: &ast::Fn,
|
||||
extern_block: &ast::ExternBlock,
|
||||
) -> Option<()> {
|
||||
|
|
@ -55,7 +52,6 @@ pub(super) fn static_hints(
|
|||
acc: &mut Vec<InlayHint>,
|
||||
FamousDefs(sema, _): &FamousDefs<'_, '_>,
|
||||
config: &InlayHintsConfig,
|
||||
_file_id: EditionedFileId,
|
||||
static_: &ast::Static,
|
||||
extern_block: &ast::ExternBlock,
|
||||
) -> Option<()> {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ use hir::{
|
|||
};
|
||||
use ide_db::{FileRange, famous_defs::FamousDefs};
|
||||
|
||||
use span::EditionedFileId;
|
||||
use syntax::{
|
||||
ToSmolStr,
|
||||
ast::{self, AstNode},
|
||||
|
|
@ -25,7 +24,7 @@ pub(super) fn hints(
|
|||
acc: &mut Vec<InlayHint>,
|
||||
FamousDefs(sema, _): &FamousDefs<'_, '_>,
|
||||
config: &InlayHintsConfig,
|
||||
file_id: EditionedFileId,
|
||||
display_target: hir::DisplayTarget,
|
||||
node: &ast::Fn,
|
||||
) -> Option<()> {
|
||||
if !config.implicit_drop_hints {
|
||||
|
|
@ -94,7 +93,7 @@ pub(super) fn hints(
|
|||
MirSpan::Unknown => continue,
|
||||
};
|
||||
let binding = &hir.bindings[binding_idx];
|
||||
let name = binding.name.display_no_db(file_id.edition()).to_smolstr();
|
||||
let name = binding.name.display_no_db(display_target.edition).to_smolstr();
|
||||
if name.starts_with("<ra@") {
|
||||
continue; // Ignore desugared variables
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
use either::Either;
|
||||
use ide_db::famous_defs::FamousDefs;
|
||||
use ide_db::text_edit::TextEdit;
|
||||
use span::EditionedFileId;
|
||||
use syntax::{
|
||||
SyntaxKind,
|
||||
ast::{self, AstNode},
|
||||
|
|
@ -17,7 +16,6 @@ pub(super) fn hints(
|
|||
acc: &mut Vec<InlayHint>,
|
||||
FamousDefs(_sema, _): &FamousDefs<'_, '_>,
|
||||
config: &InlayHintsConfig,
|
||||
_file_id: EditionedFileId,
|
||||
statik_or_const: Either<ast::Static, ast::Const>,
|
||||
) -> Option<()> {
|
||||
if config.lifetime_elision_hints != LifetimeElisionHints::Always {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ use std::iter;
|
|||
|
||||
use ide_db::{FxHashMap, famous_defs::FamousDefs, syntax_helpers::node_ext::walk_ty};
|
||||
use itertools::Itertools;
|
||||
use span::EditionedFileId;
|
||||
use syntax::{SmolStr, format_smolstr};
|
||||
use syntax::{
|
||||
SyntaxKind, SyntaxToken,
|
||||
|
|
@ -23,7 +22,6 @@ pub(super) fn fn_hints(
|
|||
ctx: &mut InlayHintCtx,
|
||||
fd: &FamousDefs<'_, '_>,
|
||||
config: &InlayHintsConfig,
|
||||
file_id: EditionedFileId,
|
||||
func: ast::Fn,
|
||||
) -> Option<()> {
|
||||
if config.lifetime_elision_hints == LifetimeElisionHints::Never {
|
||||
|
|
@ -40,7 +38,6 @@ pub(super) fn fn_hints(
|
|||
ctx,
|
||||
fd,
|
||||
config,
|
||||
file_id,
|
||||
param_list.params().filter_map(|it| {
|
||||
Some((
|
||||
it.pat().and_then(|it| match it {
|
||||
|
|
@ -74,7 +71,6 @@ pub(super) fn fn_ptr_hints(
|
|||
ctx: &mut InlayHintCtx,
|
||||
fd: &FamousDefs<'_, '_>,
|
||||
config: &InlayHintsConfig,
|
||||
file_id: EditionedFileId,
|
||||
func: ast::FnPtrType,
|
||||
) -> Option<()> {
|
||||
if config.lifetime_elision_hints == LifetimeElisionHints::Never {
|
||||
|
|
@ -97,7 +93,6 @@ pub(super) fn fn_ptr_hints(
|
|||
ctx,
|
||||
fd,
|
||||
config,
|
||||
file_id,
|
||||
param_list.params().filter_map(|it| {
|
||||
Some((
|
||||
it.pat().and_then(|it| match it {
|
||||
|
|
@ -140,7 +135,6 @@ pub(super) fn fn_path_hints(
|
|||
ctx: &mut InlayHintCtx,
|
||||
fd: &FamousDefs<'_, '_>,
|
||||
config: &InlayHintsConfig,
|
||||
file_id: EditionedFileId,
|
||||
func: ast::PathType,
|
||||
) -> Option<()> {
|
||||
if config.lifetime_elision_hints == LifetimeElisionHints::Never {
|
||||
|
|
@ -163,7 +157,6 @@ pub(super) fn fn_path_hints(
|
|||
ctx,
|
||||
fd,
|
||||
config,
|
||||
file_id,
|
||||
param_list.type_args().filter_map(|it| Some((None, it.ty()?))),
|
||||
generic_param_list,
|
||||
ret_type,
|
||||
|
|
@ -202,7 +195,6 @@ fn hints_(
|
|||
ctx: &mut InlayHintCtx,
|
||||
FamousDefs(_, _): &FamousDefs<'_, '_>,
|
||||
config: &InlayHintsConfig,
|
||||
_file_id: EditionedFileId,
|
||||
params: impl Iterator<Item = (Option<ast::Name>, ast::Type)>,
|
||||
generic_param_list: Option<ast::GenericParamList>,
|
||||
ret_type: Option<ast::RetType>,
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@
|
|||
//! if let ../* < */100 = 50 {}
|
||||
//! ```
|
||||
use ide_db::famous_defs::FamousDefs;
|
||||
use span::EditionedFileId;
|
||||
use syntax::{SyntaxToken, T, ast};
|
||||
|
||||
use crate::{InlayHint, InlayHintsConfig};
|
||||
|
|
@ -13,7 +12,6 @@ pub(super) fn hints(
|
|||
acc: &mut Vec<InlayHint>,
|
||||
FamousDefs(_sema, _): &FamousDefs<'_, '_>,
|
||||
config: &InlayHintsConfig,
|
||||
_file_id: EditionedFileId,
|
||||
range: impl ast::RangeItem,
|
||||
) -> Option<()> {
|
||||
(config.range_exclusive_hints && range.end().is_some())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue