mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 21:43:37 +00:00
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:
commit
b48a1ae004
4 changed files with 14 additions and 19 deletions
|
@ -232,8 +232,7 @@ impl InlayHintLabelBuilder<'_> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn label_of_ty(
|
fn label_of_ty(
|
||||||
sema: &Semantics<'_, RootDatabase>,
|
famous_defs @ FamousDefs(sema, _): &FamousDefs<'_, '_>,
|
||||||
desc_pat: &impl AstNode,
|
|
||||||
config: &InlayHintsConfig,
|
config: &InlayHintsConfig,
|
||||||
ty: hir::Type,
|
ty: hir::Type,
|
||||||
) -> Option<InlayHintLabel> {
|
) -> 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 {
|
let mut label_builder = InlayHintLabelBuilder {
|
||||||
db: sema.db,
|
db: sema.db,
|
||||||
last_part: String::new(),
|
last_part: String::new(),
|
||||||
|
@ -329,7 +326,7 @@ pub(crate) fn inlay_hints(
|
||||||
|
|
||||||
fn hints(
|
fn hints(
|
||||||
hints: &mut Vec<InlayHint>,
|
hints: &mut Vec<InlayHint>,
|
||||||
FamousDefs(sema, _): &FamousDefs<'_, '_>,
|
famous_defs @ FamousDefs(sema, _): &FamousDefs<'_, '_>,
|
||||||
config: &InlayHintsConfig,
|
config: &InlayHintsConfig,
|
||||||
file_id: FileId,
|
file_id: FileId,
|
||||||
node: SyntaxNode,
|
node: SyntaxNode,
|
||||||
|
@ -338,14 +335,14 @@ fn hints(
|
||||||
match_ast! {
|
match_ast! {
|
||||||
match node {
|
match node {
|
||||||
ast::Expr(expr) => {
|
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);
|
adjustment::hints(hints, sema, config, &expr);
|
||||||
match expr {
|
match expr {
|
||||||
ast::Expr::CallExpr(it) => param_name::hints(hints, sema, config, ast::Expr::from(it)),
|
ast::Expr::CallExpr(it) => param_name::hints(hints, sema, config, ast::Expr::from(it)),
|
||||||
ast::Expr::MethodCallExpr(it) => {
|
ast::Expr::MethodCallExpr(it) => {
|
||||||
param_name::hints(hints, sema, config, ast::Expr::from(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
|
// 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
|
// 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),
|
// ast::Expr::PathExpr(_) => reborrow_hints(hints, sema, config, &expr),
|
||||||
|
@ -355,7 +352,7 @@ fn hints(
|
||||||
ast::Pat(it) => {
|
ast::Pat(it) => {
|
||||||
binding_mode::hints(hints, sema, config, &it);
|
binding_mode::hints(hints, sema, config, &it);
|
||||||
if let ast::Pat::IdentPat(it) = 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(())
|
Some(())
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
//! let _x /* i32 */= f(4, 4);
|
//! let _x /* i32 */= f(4, 4);
|
||||||
//! ```
|
//! ```
|
||||||
use hir::{Semantics, TypeInfo};
|
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 itertools::Itertools;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
|
@ -20,7 +20,7 @@ use super::label_of_ty;
|
||||||
|
|
||||||
pub(super) fn hints(
|
pub(super) fn hints(
|
||||||
acc: &mut Vec<InlayHint>,
|
acc: &mut Vec<InlayHint>,
|
||||||
sema: &Semantics<'_, RootDatabase>,
|
famous_defs @ FamousDefs(sema, _): &FamousDefs<'_, '_>,
|
||||||
config: &InlayHintsConfig,
|
config: &InlayHintsConfig,
|
||||||
file_id: FileId,
|
file_id: FileId,
|
||||||
pat: &ast::IdentPat,
|
pat: &ast::IdentPat,
|
||||||
|
@ -37,7 +37,7 @@ pub(super) fn hints(
|
||||||
return None;
|
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
|
if config.hide_named_constructor_hints
|
||||||
&& is_named_constructor(sema, pat, &label.to_string()).is_some()
|
&& is_named_constructor(sema, pat, &label.to_string()).is_some()
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
//! Implementation of "chaining" inlay hints.
|
//! Implementation of "chaining" inlay hints.
|
||||||
use hir::Semantics;
|
use ide_db::famous_defs::FamousDefs;
|
||||||
use ide_db::RootDatabase;
|
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, AstNode},
|
ast::{self, AstNode},
|
||||||
Direction, NodeOrToken, SyntaxKind, T,
|
Direction, NodeOrToken, SyntaxKind, T,
|
||||||
|
@ -12,7 +11,7 @@ use super::label_of_ty;
|
||||||
|
|
||||||
pub(super) fn hints(
|
pub(super) fn hints(
|
||||||
acc: &mut Vec<InlayHint>,
|
acc: &mut Vec<InlayHint>,
|
||||||
sema: &Semantics<'_, RootDatabase>,
|
famous_defs @ FamousDefs(sema, _): &FamousDefs<'_, '_>,
|
||||||
config: &InlayHintsConfig,
|
config: &InlayHintsConfig,
|
||||||
file_id: FileId,
|
file_id: FileId,
|
||||||
expr: &ast::Expr,
|
expr: &ast::Expr,
|
||||||
|
@ -61,7 +60,7 @@ pub(super) fn hints(
|
||||||
acc.push(InlayHint {
|
acc.push(InlayHint {
|
||||||
range: expr.syntax().text_range(),
|
range: expr.syntax().text_range(),
|
||||||
kind: InlayKind::ChainingHint,
|
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())),
|
tooltip: Some(InlayTooltip::HoverRanged(file_id, expr.syntax().text_range())),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
//! Implementation of "closure return type" inlay hints.
|
//! Implementation of "closure return type" inlay hints.
|
||||||
use hir::Semantics;
|
use ide_db::{base_db::FileId, famous_defs::FamousDefs};
|
||||||
use ide_db::{base_db::FileId, RootDatabase};
|
|
||||||
use syntax::ast::{self, AstNode};
|
use syntax::ast::{self, AstNode};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -12,7 +11,7 @@ use super::label_of_ty;
|
||||||
|
|
||||||
pub(super) fn hints(
|
pub(super) fn hints(
|
||||||
acc: &mut Vec<InlayHint>,
|
acc: &mut Vec<InlayHint>,
|
||||||
sema: &Semantics<'_, RootDatabase>,
|
famous_defs @ FamousDefs(sema, _): &FamousDefs<'_, '_>,
|
||||||
config: &InlayHintsConfig,
|
config: &InlayHintsConfig,
|
||||||
file_id: FileId,
|
file_id: FileId,
|
||||||
closure: ast::ClosureExpr,
|
closure: ast::ClosureExpr,
|
||||||
|
@ -43,7 +42,7 @@ pub(super) fn hints(
|
||||||
acc.push(InlayHint {
|
acc.push(InlayHint {
|
||||||
range: param_list.syntax().text_range(),
|
range: param_list.syntax().text_range(),
|
||||||
kind: InlayKind::ClosureReturnTypeHint,
|
kind: InlayKind::ClosureReturnTypeHint,
|
||||||
label: label_of_ty(sema, ¶m_list, config, ty)?,
|
label: label_of_ty(famous_defs, config, ty)?,
|
||||||
tooltip: Some(InlayTooltip::HoverRanged(file_id, param_list.syntax().text_range())),
|
tooltip: Some(InlayTooltip::HoverRanged(file_id, param_list.syntax().text_range())),
|
||||||
});
|
});
|
||||||
Some(())
|
Some(())
|
||||||
|
|
Loading…
Reference in a new issue