|
|
@ -139,31 +139,34 @@ impl EditorView {
|
|
|
|
start..end
|
|
|
|
start..end
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: range doesn't actually restrict source, just highlight range
|
|
|
|
match doc.syntax() {
|
|
|
|
let highlights = match doc.syntax() {
|
|
|
|
|
|
|
|
Some(syntax) => {
|
|
|
|
Some(syntax) => {
|
|
|
|
syntax
|
|
|
|
let iter = syntax
|
|
|
|
|
|
|
|
// TODO: range doesn't actually restrict source, just highlight range
|
|
|
|
.highlight_iter(text.slice(..), Some(range), None)
|
|
|
|
.highlight_iter(text.slice(..), Some(range), None)
|
|
|
|
.map(|event| event.unwrap())
|
|
|
|
.map(|event| event.unwrap())
|
|
|
|
.collect() // TODO: we collect here to avoid holding the lock, fix later
|
|
|
|
.map(move |event| match event {
|
|
|
|
|
|
|
|
// convert byte offsets to char offset
|
|
|
|
|
|
|
|
HighlightEvent::Source { start, end } => {
|
|
|
|
|
|
|
|
let start =
|
|
|
|
|
|
|
|
text.byte_to_char(ensure_grapheme_boundary_next_byte(text, start));
|
|
|
|
|
|
|
|
let end =
|
|
|
|
|
|
|
|
text.byte_to_char(ensure_grapheme_boundary_next_byte(text, end));
|
|
|
|
|
|
|
|
HighlightEvent::Source { start, end }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
event => event,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Box::new(iter)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None => vec![HighlightEvent::Source {
|
|
|
|
None => Box::new(
|
|
|
|
start: range.start,
|
|
|
|
[HighlightEvent::Source {
|
|
|
|
end: range.end,
|
|
|
|
start: text.byte_to_char(range.start),
|
|
|
|
}],
|
|
|
|
end: text.byte_to_char(range.end),
|
|
|
|
|
|
|
|
}]
|
|
|
|
|
|
|
|
.into_iter(),
|
|
|
|
|
|
|
|
),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.into_iter()
|
|
|
|
|
|
|
|
.map(move |event| match event {
|
|
|
|
|
|
|
|
// convert byte offsets to char offset
|
|
|
|
|
|
|
|
HighlightEvent::Source { start, end } => {
|
|
|
|
|
|
|
|
let start = text.byte_to_char(ensure_grapheme_boundary_next_byte(text, start));
|
|
|
|
|
|
|
|
let end = text.byte_to_char(ensure_grapheme_boundary_next_byte(text, end));
|
|
|
|
|
|
|
|
HighlightEvent::Source { start, end }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
event => event,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Box::new(highlights)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Get highlight spans for document diagnostics
|
|
|
|
/// Get highlight spans for document diagnostics
|
|
|
|