Auto merge of #13822 - WaffleLapkin:famous, r=Veykril

internal: Pass `FamousDefs` around in inlay hints

Bind after at go brrrrr
This commit is contained in:
bors 2022-12-22 11:25:54 +00:00
commit b48a1ae004
4 changed files with 14 additions and 19 deletions

View file

@ -232,8 +232,7 @@ impl InlayHintLabelBuilder<'_> {
}
fn label_of_ty(
sema: &Semantics<'_, RootDatabase>,
desc_pat: &impl AstNode,
famous_defs @ FamousDefs(sema, _): &FamousDefs<'_, '_>,
config: &InlayHintsConfig,
ty: hir::Type,
) -> Option<InlayHintLabel> {
@ -263,8 +262,6 @@ fn label_of_ty(
};
}
let krate = sema.scope(desc_pat.syntax())?.krate();
let famous_defs = FamousDefs(sema, krate);
let mut label_builder = InlayHintLabelBuilder {
db: sema.db,
last_part: String::new(),
@ -329,7 +326,7 @@ pub(crate) fn inlay_hints(
fn hints(
hints: &mut Vec<InlayHint>,
FamousDefs(sema, _): &FamousDefs<'_, '_>,
famous_defs @ FamousDefs(sema, _): &FamousDefs<'_, '_>,
config: &InlayHintsConfig,
file_id: FileId,
node: SyntaxNode,
@ -338,14 +335,14 @@ fn hints(
match_ast! {
match node {
ast::Expr(expr) => {
chaining::hints(hints, sema, config, file_id, &expr);
chaining::hints(hints, famous_defs, config, file_id, &expr);
adjustment::hints(hints, sema, config, &expr);
match expr {
ast::Expr::CallExpr(it) => param_name::hints(hints, sema, config, ast::Expr::from(it)),
ast::Expr::MethodCallExpr(it) => {
param_name::hints(hints, sema, config, ast::Expr::from(it))
}
ast::Expr::ClosureExpr(it) => closure_ret::hints(hints, sema, config, file_id, it),
ast::Expr::ClosureExpr(it) => closure_ret::hints(hints, famous_defs, config, file_id, it),
// We could show reborrows for all expressions, but usually that is just noise to the user
// and the main point here is to show why "moving" a mutable reference doesn't necessarily move it
// ast::Expr::PathExpr(_) => reborrow_hints(hints, sema, config, &expr),
@ -355,7 +352,7 @@ fn hints(
ast::Pat(it) => {
binding_mode::hints(hints, sema, config, &it);
if let ast::Pat::IdentPat(it) = it {
bind_pat::hints(hints, sema, config, file_id, &it);
bind_pat::hints(hints, famous_defs, config, file_id, &it);
}
Some(())
},

View file

@ -4,7 +4,7 @@
//! let _x /* i32 */= f(4, 4);
//! ```
use hir::{Semantics, TypeInfo};
use ide_db::{base_db::FileId, RootDatabase};
use ide_db::{base_db::FileId, famous_defs::FamousDefs, RootDatabase};
use itertools::Itertools;
use syntax::{
@ -20,7 +20,7 @@ use super::label_of_ty;
pub(super) fn hints(
acc: &mut Vec<InlayHint>,
sema: &Semantics<'_, RootDatabase>,
famous_defs @ FamousDefs(sema, _): &FamousDefs<'_, '_>,
config: &InlayHintsConfig,
file_id: FileId,
pat: &ast::IdentPat,
@ -37,7 +37,7 @@ pub(super) fn hints(
return None;
}
let label = label_of_ty(sema, desc_pat, config, ty)?;
let label = label_of_ty(famous_defs, config, ty)?;
if config.hide_named_constructor_hints
&& is_named_constructor(sema, pat, &label.to_string()).is_some()

View file

@ -1,6 +1,5 @@
//! Implementation of "chaining" inlay hints.
use hir::Semantics;
use ide_db::RootDatabase;
use ide_db::famous_defs::FamousDefs;
use syntax::{
ast::{self, AstNode},
Direction, NodeOrToken, SyntaxKind, T,
@ -12,7 +11,7 @@ use super::label_of_ty;
pub(super) fn hints(
acc: &mut Vec<InlayHint>,
sema: &Semantics<'_, RootDatabase>,
famous_defs @ FamousDefs(sema, _): &FamousDefs<'_, '_>,
config: &InlayHintsConfig,
file_id: FileId,
expr: &ast::Expr,
@ -61,7 +60,7 @@ pub(super) fn hints(
acc.push(InlayHint {
range: expr.syntax().text_range(),
kind: InlayKind::ChainingHint,
label: label_of_ty(sema, desc_expr, config, ty)?,
label: label_of_ty(famous_defs, config, ty)?,
tooltip: Some(InlayTooltip::HoverRanged(file_id, expr.syntax().text_range())),
});
}

View file

@ -1,6 +1,5 @@
//! Implementation of "closure return type" inlay hints.
use hir::Semantics;
use ide_db::{base_db::FileId, RootDatabase};
use ide_db::{base_db::FileId, famous_defs::FamousDefs};
use syntax::ast::{self, AstNode};
use crate::{
@ -12,7 +11,7 @@ use super::label_of_ty;
pub(super) fn hints(
acc: &mut Vec<InlayHint>,
sema: &Semantics<'_, RootDatabase>,
famous_defs @ FamousDefs(sema, _): &FamousDefs<'_, '_>,
config: &InlayHintsConfig,
file_id: FileId,
closure: ast::ClosureExpr,
@ -43,7 +42,7 @@ pub(super) fn hints(
acc.push(InlayHint {
range: param_list.syntax().text_range(),
kind: InlayKind::ClosureReturnTypeHint,
label: label_of_ty(sema, &param_list, config, ty)?,
label: label_of_ty(famous_defs, config, ty)?,
tooltip: Some(InlayTooltip::HoverRanged(file_id, param_list.syntax().text_range())),
});
Some(())