1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
mod label;
use base_db::{Document, Project, Workspace};
use lsp_types::{InlayHint, InlayHintLabel, Range, Url};
use rowan::{TextRange, TextSize};
use crate::util::line_index_ext::LineIndexExt;
pub fn find_all(workspace: &Workspace, uri: &Url, range: Range) -> Option<Vec<InlayHint>> {
let document = workspace.lookup(uri)?;
let range = document.line_index.offset_lsp_range(range);
let project = workspace.project(document);
let mut builder = InlayHintBuilder {
workspace,
document,
project,
range,
hints: Vec::new(),
};
label::find_hints(&mut builder);
Some(builder.hints)
}
struct InlayHintBuilder<'a> {
workspace: &'a Workspace,
document: &'a Document,
project: Project<'a>,
range: TextRange,
hints: Vec<InlayHint>,
}
impl<'db> InlayHintBuilder<'db> {
pub fn push(&mut self, offset: TextSize, text: String) {
let position = self.document.line_index.line_col_lsp(offset);
self.hints.push(InlayHint {
position,
label: InlayHintLabel::String(text),
kind: None,
text_edits: None,
tooltip: None,
padding_left: Some(true),
padding_right: None,
data: None,
});
}
}
|