Unnamed repository; edit this file 'description' to name the repository.
rough, but appears to work
Jeroen Vannevel 2022-02-15
parent f0210f8 · commit 73e4949
-rw-r--r--Cargo.toml2
-rw-r--r--crates/hir/src/display.rs4
-rw-r--r--crates/hir_def/src/item_tree/pretty.rs6
-rw-r--r--crates/hir_def/src/type_ref.rs18
-rw-r--r--crates/hir_ty/src/display.rs26
-rw-r--r--crates/hir_ty/src/lower.rs2
-rw-r--r--crates/ide/src/hover.rs1
-rw-r--r--crates/ide/src/hover/render.rs1
-rw-r--r--crates/ide/src/hover/tests.rs36
9 files changed, 81 insertions, 15 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 3f83041bec..1b322acdc6 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -5,7 +5,7 @@ exclude = ["crates/proc_macro_test/imp"]
[profile.dev]
# Disabling debug info speeds up builds a bunch,
# and we don't rely on it for debugging that much.
-debug = 0
+debug = 2
[profile.dev.package]
# These speed up local tests.
diff --git a/crates/hir/src/display.rs b/crates/hir/src/display.rs
index 1e949771ea..19402c1c25 100644
--- a/crates/hir/src/display.rs
+++ b/crates/hir/src/display.rs
@@ -22,7 +22,9 @@ use crate::{
impl HirDisplay for Function {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
+ println!("Formatting for Function");
let data = f.db.function_data(self.id);
+ println!("data: {:?}", &data);
write_visibility(self.module(f.db).id, self.visibility(f.db), f)?;
if data.is_default() {
write!(f, "default ")?;
@@ -461,6 +463,7 @@ impl HirDisplay for Trait {
impl HirDisplay for TypeAlias {
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
+ println!("Formatting for TypeAlias");
write_visibility(self.module(f.db).id, self.visibility(f.db), f)?;
let data = f.db.type_alias_data(self.id);
write!(f, "type {}", data.name)?;
@@ -468,6 +471,7 @@ impl HirDisplay for TypeAlias {
write!(f, ": ")?;
f.write_joined(&data.bounds, " + ")?;
}
+ println!("type_ref: {:?}", &data.type_ref);
if let Some(ty) = &data.type_ref {
write!(f, " = ")?;
ty.hir_fmt(f)?;
diff --git a/crates/hir_def/src/item_tree/pretty.rs b/crates/hir_def/src/item_tree/pretty.rs
index eaaff5a21f..4d57e484c1 100644
--- a/crates/hir_def/src/item_tree/pretty.rs
+++ b/crates/hir_def/src/item_tree/pretty.rs
@@ -496,11 +496,11 @@ impl<'a> Printer<'a> {
let (ret, args) =
args_and_ret.split_last().expect("TypeRef::Fn is missing return type");
w!(self, "fn(");
- for (i, arg) in args.iter().enumerate() {
+ for (i, (name, typeref)) in args.iter().enumerate() {
if i != 0 {
w!(self, ", ");
}
- self.print_type_ref(arg);
+ self.print_type_ref(&typeref);
}
if *varargs {
if !args.is_empty() {
@@ -509,7 +509,7 @@ impl<'a> Printer<'a> {
w!(self, "...");
}
w!(self, ") -> ");
- self.print_type_ref(ret);
+ self.print_type_ref(&ret.1);
}
TypeRef::Macro(_ast_id) => {
w!(self, "<macro>");
diff --git a/crates/hir_def/src/type_ref.rs b/crates/hir_def/src/type_ref.rs
index cfc69feccc..3c2e036ab9 100644
--- a/crates/hir_def/src/type_ref.rs
+++ b/crates/hir_def/src/type_ref.rs
@@ -3,7 +3,7 @@
use hir_expand::{name::Name, AstId, InFile};
use std::convert::TryInto;
-use syntax::ast;
+use syntax::{ast, AstNode};
use crate::{body::LowerCtx, intern::Interned, path::Path};
@@ -89,7 +89,7 @@ pub enum TypeRef {
Array(Box<TypeRef>, ConstScalar),
Slice(Box<TypeRef>),
/// A fn pointer. Last element of the vector is the return type.
- Fn(Vec<TypeRef>, bool /*varargs*/),
+ Fn(Vec<(Option<String>, TypeRef)>, bool /*varargs*/),
// For
ImplTrait(Vec<Interned<TypeBound>>),
DynTrait(Vec<Interned<TypeBound>>),
@@ -188,11 +188,16 @@ impl TypeRef {
is_varargs = param.dotdotdot_token().is_some();
}
- pl.params().map(|p| p.ty()).map(|it| TypeRef::from_ast_opt(ctx, it)).collect()
+ pl.params().map(|p| (p.pat(), p.ty())).map(|it| {
+ println!("{it:?}");
+ let type_ref = TypeRef::from_ast_opt(ctx, it.1);
+ let name = it.0.unwrap().syntax().text().to_string();
+ (Some(name), type_ref)
+ }).collect()
} else {
Vec::new()
};
- params.push(ret_ty);
+ params.push((None, ret_ty));
TypeRef::Fn(params, is_varargs)
}
// for types are close enough for our purposes to the inner type for now...
@@ -230,7 +235,10 @@ impl TypeRef {
fn go(type_ref: &TypeRef, f: &mut impl FnMut(&TypeRef)) {
f(type_ref);
match type_ref {
- TypeRef::Fn(types, _) | TypeRef::Tuple(types) => {
+ TypeRef::Fn(types, _) => {
+ types.iter().for_each(|t| go(&t.1, f))
+ }
+ TypeRef::Tuple(types) => {
types.iter().for_each(|t| go(t, f))
}
TypeRef::RawPtr(type_ref, _)
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs
index f02f4ac024..bca628a5c8 100644
--- a/crates/hir_ty/src/display.rs
+++ b/crates/hir_ty/src/display.rs
@@ -239,6 +239,7 @@ where
T: HirDisplay,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ println!("formatting..");
match self.t.hir_fmt(&mut HirFormatter {
db: self.db,
fmt: f,
@@ -341,6 +342,9 @@ impl HirDisplay for Ty {
return write!(f, "{}", TYPE_HINT_TRUNCATION);
}
+ let interner_kind = self.kind(Interner);
+ println!("interner kind: {interner_kind:?}");
+
match self.kind(Interner) {
TyKind::Never => write!(f, "!")?,
TyKind::Str => write!(f, "str")?,
@@ -1094,15 +1098,27 @@ impl HirDisplay for TypeRef {
inner.hir_fmt(f)?;
write!(f, "]")?;
}
- TypeRef::Fn(tys, is_varargs) => {
- // FIXME: Function pointer qualifiers.
+ TypeRef::Fn(parameters, is_varargs) => {
write!(f, "fn(")?;
- f.write_joined(&tys[..tys.len() - 1], ", ")?;
+ for index in 0..parameters.len() - 1 {
+ let (param_name,param_type) = &parameters[index];
+ match param_name {
+ Some(name) => {
+ write!(f, "{}: ", name)?;
+ param_type.hir_fmt(f)?;
+ },
+ None => write!(f, " : {:?}", param_type)?,
+ };
+
+ if index != parameters.len() - 2 {
+ write!(f, ", ")?;
+ }
+ }
if *is_varargs {
- write!(f, "{}...", if tys.len() == 1 { "" } else { ", " })?;
+ write!(f, "{}...", if parameters.len() == 1 { "" } else { ", " })?;
}
write!(f, ")")?;
- let ret_ty = tys.last().unwrap();
+ let ret_ty = &parameters.last().unwrap().1;
match ret_ty {
TypeRef::Tuple(tup) if tup.is_empty() => {}
_ => {
diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs
index 55b1a67ea7..4873693e8c 100644
--- a/crates/hir_ty/src/lower.rs
+++ b/crates/hir_ty/src/lower.rs
@@ -201,7 +201,7 @@ impl<'a> TyLoweringContext<'a> {
TypeRef::Placeholder => TyKind::Error.intern(Interner),
TypeRef::Fn(params, is_varargs) => {
let substs = self.with_shifted_in(DebruijnIndex::ONE, |ctx| {
- Substitution::from_iter(Interner, params.iter().map(|tr| ctx.lower_ty(tr)))
+ Substitution::from_iter(Interner, params.iter().map(|tr| ctx.lower_ty(&tr.1)))
});
TyKind::Function(FnPointer {
num_binders: 0, // FIXME lower `for<'a> fn()` correctly
diff --git a/crates/ide/src/hover.rs b/crates/ide/src/hover.rs
index 0eba0b09ba..550e1c1543 100644
--- a/crates/ide/src/hover.rs
+++ b/crates/ide/src/hover.rs
@@ -172,6 +172,7 @@ pub(crate) fn hover_for_definition(
Definition::BuiltinType(_) => Some(FamousDefs(sema, sema.scope(node).krate())),
_ => None,
};
+ println!("definition: {definition:?}");
if let Some(markup) = render::definition(sema.db, definition, famous_defs.as_ref(), config) {
let mut res = HoverResult::default();
res.markup = render::process_markup(sema.db, definition, &markup, config);
diff --git a/crates/ide/src/hover/render.rs b/crates/ide/src/hover/render.rs
index f94348ec58..0a5c335661 100644
--- a/crates/ide/src/hover/render.rs
+++ b/crates/ide/src/hover/render.rs
@@ -411,6 +411,7 @@ where
D: HasAttrs + HirDisplay,
{
let label = def.display(db).to_string();
+ println!("label: {label:?}");
let docs = def.attrs(db).docs();
(label, docs)
}
diff --git a/crates/ide/src/hover/tests.rs b/crates/ide/src/hover/tests.rs
index ed76c84ab4..ed9f6d507c 100644
--- a/crates/ide/src/hover/tests.rs
+++ b/crates/ide/src/hover/tests.rs
@@ -1311,6 +1311,42 @@ fn test_hover_function_show_qualifiers() {
}
#[test]
+fn test_hover_function_show_types() {
+ check(
+ r#"fn foo$0(a: i32, b:i32) -> i32 { 0 }"#,
+ expect![[r#"
+ *foo*
+
+ ```rust
+ test
+ ```
+
+ ```rust
+ fn foo(a: i32, b: i32) -> i32
+ ```
+ "#]],
+ );
+}
+
+#[test]
+fn test_hover_function_pointer_show_types() {
+ check(
+ r#"type foo$0 = fn(a: i32, b: i32) -> i32;"#,
+ expect![[r#"
+ *foo*
+
+ ```rust
+ test
+ ```
+
+ ```rust
+ type foo = fn(a: i32, b: i32) -> i32
+ ```
+ "#]],
+ );
+}
+
+#[test]
fn test_hover_trait_show_qualifiers() {
check_actions(
r"unsafe trait foo$0() {}",