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:
bors[bot] 2021-03-16 08:05:24 +00:00 committed by GitHub
commit 1a82af3527
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 1058 additions and 212 deletions

View file

@ -2,6 +2,7 @@
use hir::{HasSource, HirDisplay, Type};
use ide_db::SymbolKind;
use itertools::Itertools;
use syntax::ast::Fn;
use crate::{
@ -73,8 +74,42 @@ impl<'a> FunctionRender<'a> {
}
fn detail(&self) -> String {
let ty = self.func.ret_type(self.ctx.db());
format!("-> {}", ty.display(self.ctx.db()))
let ret_ty = self.func.ret_type(self.ctx.db());
let ret = if ret_ty.is_unit() {
// Omit the return type if it is the unit type
String::new()
} else {
format!(" {}", self.ty_display())
};
format!("fn({}){}", self.params_display(), ret)
}
fn params_display(&self) -> String {
if let Some(self_param) = self.func.self_param(self.ctx.db()) {
let params = self
.func
.assoc_fn_params(self.ctx.db())
.into_iter()
.skip(1) // skip the self param because we are manually handling that
.map(|p| p.ty().display(self.ctx.db()).to_string());
std::iter::once(self_param.display(self.ctx.db()).to_owned()).chain(params).join(", ")
} else {
let params = self
.func
.assoc_fn_params(self.ctx.db())
.into_iter()
.map(|p| p.ty().display(self.ctx.db()).to_string())
.join(", ");
params
}
}
fn ty_display(&self) -> String {
let ret_ty = self.func.ret_type(self.ctx.db());
format!("-> {}", ret_ty.display(self.ctx.db()))
}
fn add_arg(&self, arg: &str, ty: &Type) -> String {