use crate::base::FileId;
use crate::hir::SymbolIndex;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum InlayHintKind {
Type,
Parameter,
}
#[derive(Debug, Clone)]
pub struct InlayHint {
pub line: u32,
pub col: u32,
pub label: String,
pub kind: InlayHintKind,
pub padding_left: bool,
pub padding_right: bool,
}
pub fn inlay_hints(
index: &SymbolIndex,
file: FileId,
range: Option<(u32, u32, u32, u32)>,
) -> Vec<InlayHint> {
let mut hints = Vec::new();
for symbol in index.symbols_in_file(file) {
if let Some((start_line, start_col, end_line, end_col)) = range {
if symbol.start_line < start_line
|| symbol.end_line > end_line
|| (symbol.start_line == start_line && symbol.start_col < start_col)
|| (symbol.end_line == end_line && symbol.end_col > end_col)
{
continue;
}
}
if symbol.kind.is_usage() && !symbol.supertypes.is_empty() {
let type_name = &symbol.supertypes[0];
let hint_col = symbol.start_col + symbol.name.len() as u32;
hints.push(InlayHint {
line: symbol.start_line,
col: hint_col,
label: format!(": {type_name}"),
kind: InlayHintKind::Type,
padding_left: false,
padding_right: true,
});
}
}
hints
}