vimdoc_language_server/
shared.rs1use lsp_types::{Position, Range};
2
3use crate::parser::{Document, Span};
4
5#[must_use]
6pub fn tag_name_at(doc: &Document, pos: Position) -> Option<String> {
7 find_span_at(doc.tag_refs(), pos)
8 .or_else(|| find_span_at(doc.tag_defs(), pos))
9 .map(|s| s.name.clone())
10}
11
12pub fn find_span_at<'a>(
13 mut spans: impl Iterator<Item = &'a Span>,
14 pos: Position,
15) -> Option<&'a Span> {
16 spans.find(|s| position_in_range(pos, s.range))
17}
18
19fn position_in_range(pos: Position, range: Range) -> bool {
20 let line = pos.line;
21 let ch = pos.character;
22 line == range.start.line && ch >= range.start.character && ch < range.end.character
23}