use super::{CompletionItem, CompletionKind, RenderContext};
use crate::SymbolKind;
use mun_hir::HirDisplay;
pub(super) struct FunctionRender<'a> {
ctx: RenderContext<'a>,
name: String,
func: mun_hir::Function,
}
impl<'a> FunctionRender<'a> {
pub fn new(
ctx: RenderContext<'a>,
local_name: Option<String>,
func: mun_hir::Function,
) -> Option<FunctionRender<'a>> {
let name = local_name.unwrap_or_else(|| func.name(ctx.db()).to_string());
Some(Self { ctx, name, func })
}
pub fn render(self) -> CompletionItem {
CompletionItem::builder(CompletionKind::Reference, self.name.clone())
.kind(SymbolKind::Function)
.detail(self.detail())
.finish()
}
fn detail(&self) -> String {
let ty = self.func.ret_type(self.ctx.db());
format!("-> {}", ty.display(self.ctx.db()))
}
}