diff options
Diffstat (limited to 'support/texlab/src/features/inlay_hint.rs')
-rw-r--r-- | support/texlab/src/features/inlay_hint.rs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/support/texlab/src/features/inlay_hint.rs b/support/texlab/src/features/inlay_hint.rs new file mode 100644 index 0000000000..6d53259900 --- /dev/null +++ b/support/texlab/src/features/inlay_hint.rs @@ -0,0 +1,45 @@ +mod label; + +use lsp_types::{InlayHint, InlayHintLabel, Range, Url}; +use rowan::TextSize; + +use crate::{ + db::Workspace, + util::{line_index::LineIndex, line_index_ext::LineIndexExt}, + Db, +}; + +pub fn find_all(db: &dyn Db, uri: &Url, range: Range) -> Option<Vec<InlayHint>> { + let document = Workspace::get(db).lookup_uri(db, uri)?; + let line_index = document.contents(db).line_index(db); + + let mut builder = InlayHintBuilder { + line_index, + hints: Vec::new(), + }; + + let range = line_index.offset_lsp_range(range); + label::find_hints(db, document, range, &mut builder); + Some(builder.hints) +} + +struct InlayHintBuilder<'db> { + line_index: &'db LineIndex, + hints: Vec<InlayHint>, +} + +impl<'db> InlayHintBuilder<'db> { + pub fn push(&mut self, offset: TextSize, text: String) { + let position = self.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, + }); + } +} |