mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
7900: show function params in completion detail r=matklad a=JoshMcguigan This resolves #7842 by updating the detail for function completions from `-> T` to `fn(T, U) -> V`. I added an expicit unit test for this, `ide_completion::render::fn_detail_includes_args_and_return_type`, which passes. Lots of other unit tests fail (~60 of them) due to this change, although I believe the failures are purely cosmetic (they were testing the exact format of this output). I'm happy to go update those tests, but before I do that I'd like to make sure this is in fact the format we want for the detail? edit - I realized `UPDATE_EXPECT=1 cargo test` automatically updates `expect!` tests. Big 👍 to whoever worked on that! So I'll go ahead and update all these tests soon. But I still would like to confirm `fn(T, U) -> V` is the desired content in the `detail` field. 8000: Use hir formatter for hover text r=matklad a=oxalica Fix #2765 , (should) fix #4665 Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com> Co-authored-by: oxalica <oxalicc@pm.me>
This commit is contained in:
commit
1a82af3527
21 changed files with 1058 additions and 212 deletions
|
@ -29,6 +29,8 @@ mod has_source;
|
|||
pub mod diagnostics;
|
||||
pub mod db;
|
||||
|
||||
mod display;
|
||||
|
||||
use std::{iter, sync::Arc};
|
||||
|
||||
use arrayvec::ArrayVec;
|
||||
|
@ -50,7 +52,6 @@ use hir_def::{
|
|||
use hir_expand::{diagnostics::DiagnosticSink, name::name, MacroDefKind};
|
||||
use hir_ty::{
|
||||
autoderef,
|
||||
display::{write_bounds_like_dyn_trait_with_prefix, HirDisplayError, HirFormatter},
|
||||
method_resolution::{self, TyFingerprint},
|
||||
primitive::UintTy,
|
||||
to_assoc_type_id,
|
||||
|
@ -572,6 +573,12 @@ impl Struct {
|
|||
}
|
||||
}
|
||||
|
||||
impl HasVisibility for Struct {
|
||||
fn visibility(&self, db: &dyn HirDatabase) -> Visibility {
|
||||
db.struct_data(self.id).visibility.resolve(db.upcast(), &self.id.resolver(db.upcast()))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct Union {
|
||||
pub(crate) id: UnionId,
|
||||
|
@ -604,6 +611,12 @@ impl Union {
|
|||
}
|
||||
}
|
||||
|
||||
impl HasVisibility for Union {
|
||||
fn visibility(&self, db: &dyn HirDatabase) -> Visibility {
|
||||
db.union_data(self.id).visibility.resolve(db.upcast(), &self.id.resolver(db.upcast()))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct Enum {
|
||||
pub(crate) id: EnumId,
|
||||
|
@ -631,6 +644,12 @@ impl Enum {
|
|||
}
|
||||
}
|
||||
|
||||
impl HasVisibility for Enum {
|
||||
fn visibility(&self, db: &dyn HirDatabase) -> Visibility {
|
||||
db.enum_data(self.id).visibility.resolve(db.upcast(), &self.id.resolver(db.upcast()))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct Variant {
|
||||
pub(crate) parent: Enum,
|
||||
|
@ -822,7 +841,8 @@ impl Function {
|
|||
db.function_data(self.id)
|
||||
.params
|
||||
.iter()
|
||||
.map(|type_ref| {
|
||||
.enumerate()
|
||||
.map(|(idx, type_ref)| {
|
||||
let ty = Type {
|
||||
krate,
|
||||
ty: InEnvironment {
|
||||
|
@ -830,7 +850,7 @@ impl Function {
|
|||
environment: environment.clone(),
|
||||
},
|
||||
};
|
||||
Param { ty }
|
||||
Param { func: self, ty, idx }
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
@ -844,7 +864,7 @@ impl Function {
|
|||
}
|
||||
|
||||
pub fn is_unsafe(self, db: &dyn HirDatabase) -> bool {
|
||||
db.function_data(self.id).is_unsafe
|
||||
db.function_data(self.id).qualifier.is_unsafe
|
||||
}
|
||||
|
||||
pub fn diagnostics(self, db: &dyn HirDatabase, sink: &mut DiagnosticSink) {
|
||||
|
@ -893,6 +913,9 @@ impl From<hir_ty::Mutability> for Access {
|
|||
|
||||
#[derive(Debug)]
|
||||
pub struct Param {
|
||||
func: Function,
|
||||
/// The index in parameter list, including self parameter.
|
||||
idx: usize,
|
||||
ty: Type,
|
||||
}
|
||||
|
||||
|
@ -900,6 +923,15 @@ impl Param {
|
|||
pub fn ty(&self) -> &Type {
|
||||
&self.ty
|
||||
}
|
||||
|
||||
pub fn pattern_source(&self, db: &dyn HirDatabase) -> Option<ast::Pat> {
|
||||
let params = self.func.source(db)?.value.param_list()?;
|
||||
if params.self_param().is_some() {
|
||||
params.params().nth(self.idx.checked_sub(1)?)?.pat()
|
||||
} else {
|
||||
params.params().nth(self.idx)?.pat()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
|
@ -922,6 +954,14 @@ impl SelfParam {
|
|||
})
|
||||
.unwrap_or(Access::Owned)
|
||||
}
|
||||
|
||||
pub fn display(self, db: &dyn HirDatabase) -> &'static str {
|
||||
match self.access(db) {
|
||||
Access::Shared => "&self",
|
||||
Access::Exclusive => "&mut self",
|
||||
Access::Owned => "self",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HasVisibility for Function {
|
||||
|
@ -949,6 +989,10 @@ impl Const {
|
|||
pub fn name(self, db: &dyn HirDatabase) -> Option<Name> {
|
||||
db.const_data(self.id).name.clone()
|
||||
}
|
||||
|
||||
pub fn type_ref(self, db: &dyn HirDatabase) -> TypeRef {
|
||||
db.const_data(self.id).type_ref.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl HasVisibility for Const {
|
||||
|
@ -982,6 +1026,12 @@ impl Static {
|
|||
}
|
||||
}
|
||||
|
||||
impl HasVisibility for Static {
|
||||
fn visibility(&self, db: &dyn HirDatabase) -> Visibility {
|
||||
db.static_data(self.id).visibility.resolve(db.upcast(), &self.id.resolver(db.upcast()))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct Trait {
|
||||
pub(crate) id: TraitId,
|
||||
|
@ -1001,7 +1051,13 @@ impl Trait {
|
|||
}
|
||||
|
||||
pub fn is_auto(self, db: &dyn HirDatabase) -> bool {
|
||||
db.trait_data(self.id).auto
|
||||
db.trait_data(self.id).is_auto
|
||||
}
|
||||
}
|
||||
|
||||
impl HasVisibility for Trait {
|
||||
fn visibility(&self, db: &dyn HirDatabase) -> Visibility {
|
||||
db.trait_data(self.id).visibility.resolve(db.upcast(), &self.id.resolver(db.upcast()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1413,19 +1469,6 @@ impl TypeParam {
|
|||
}
|
||||
}
|
||||
|
||||
impl HirDisplay for TypeParam {
|
||||
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
|
||||
write!(f, "{}", self.name(f.db))?;
|
||||
let bounds = f.db.generic_predicates_for_param(self.id);
|
||||
let substs = Substs::type_params(f.db, self.id.parent);
|
||||
let predicates = bounds.iter().cloned().map(|b| b.subst(&substs)).collect::<Vec<_>>();
|
||||
if !(predicates.is_empty() || f.omit_verbose_types()) {
|
||||
write_bounds_like_dyn_trait_with_prefix(":", &predicates, f)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct LifetimeParam {
|
||||
pub(crate) id: LifetimeParamId,
|
||||
|
@ -2059,12 +2102,6 @@ impl Type {
|
|||
}
|
||||
}
|
||||
|
||||
impl HirDisplay for Type {
|
||||
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
|
||||
self.ty.value.hir_fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: closures
|
||||
#[derive(Debug)]
|
||||
pub struct Callable {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue