|
|
@ -166,7 +166,7 @@ impl LanguageConfiguration {
|
|
|
|
None
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
let language = get_language(self.language_id);
|
|
|
|
let language = get_language(self.language_id);
|
|
|
|
let mut config = HighlightConfiguration::new(
|
|
|
|
let config = HighlightConfiguration::new(
|
|
|
|
language,
|
|
|
|
language,
|
|
|
|
&highlights_query,
|
|
|
|
&highlights_query,
|
|
|
|
&injections_query,
|
|
|
|
&injections_query,
|
|
|
@ -332,7 +332,8 @@ impl Syntax {
|
|
|
|
|
|
|
|
|
|
|
|
// update root layer
|
|
|
|
// update root layer
|
|
|
|
PARSER.with(|ts_parser| {
|
|
|
|
PARSER.with(|ts_parser| {
|
|
|
|
syntax.root_layer.parse(
|
|
|
|
// TODO: handle the returned `Result` properly.
|
|
|
|
|
|
|
|
let _ = syntax.root_layer.parse(
|
|
|
|
&mut ts_parser.borrow_mut(),
|
|
|
|
&mut ts_parser.borrow_mut(),
|
|
|
|
&syntax.config,
|
|
|
|
&syntax.config,
|
|
|
|
source,
|
|
|
|
source,
|
|
|
@ -387,7 +388,7 @@ impl Syntax {
|
|
|
|
source: RopeSlice<'a>,
|
|
|
|
source: RopeSlice<'a>,
|
|
|
|
range: Option<std::ops::Range<usize>>,
|
|
|
|
range: Option<std::ops::Range<usize>>,
|
|
|
|
cancellation_flag: Option<&'a AtomicUsize>,
|
|
|
|
cancellation_flag: Option<&'a AtomicUsize>,
|
|
|
|
mut injection_callback: impl FnMut(&str) -> Option<&'a HighlightConfiguration> + 'a,
|
|
|
|
injection_callback: impl FnMut(&str) -> Option<&'a HighlightConfiguration> + 'a,
|
|
|
|
) -> impl Iterator<Item = Result<HighlightEvent, Error>> + 'a {
|
|
|
|
) -> impl Iterator<Item = Result<HighlightEvent, Error>> + 'a {
|
|
|
|
// The `captures` iterator borrows the `Tree` and the `QueryCursor`, which
|
|
|
|
// The `captures` iterator borrows the `Tree` and the `QueryCursor`, which
|
|
|
|
// prevents them from being moved. But both of these values are really just
|
|
|
|
// prevents them from being moved. But both of these values are really just
|
|
|
@ -494,8 +495,8 @@ impl LanguageLayer {
|
|
|
|
ts_parser: &mut TsParser,
|
|
|
|
ts_parser: &mut TsParser,
|
|
|
|
config: &HighlightConfiguration,
|
|
|
|
config: &HighlightConfiguration,
|
|
|
|
source: &Rope,
|
|
|
|
source: &Rope,
|
|
|
|
mut depth: usize,
|
|
|
|
_depth: usize,
|
|
|
|
mut ranges: Vec<Range>,
|
|
|
|
ranges: Vec<Range>,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
if ts_parser.parser.set_included_ranges(&ranges).is_ok() {
|
|
|
|
if ts_parser.parser.set_included_ranges(&ranges).is_ok() {
|
|
|
|
ts_parser
|
|
|
|
ts_parser
|
|
|
@ -1644,13 +1645,13 @@ fn injection_for_match<'a>(
|
|
|
|
(language_name, content_node, include_children)
|
|
|
|
(language_name, content_node, include_children)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn shrink_and_clear<T>(vec: &mut Vec<T>, capacity: usize) {
|
|
|
|
// fn shrink_and_clear<T>(vec: &mut Vec<T>, capacity: usize) {
|
|
|
|
if vec.len() > capacity {
|
|
|
|
// if vec.len() > capacity {
|
|
|
|
vec.truncate(capacity);
|
|
|
|
// vec.truncate(capacity);
|
|
|
|
vec.shrink_to_fit();
|
|
|
|
// vec.shrink_to_fit();
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
vec.clear();
|
|
|
|
// vec.clear();
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
pub struct Merge<I> {
|
|
|
|
pub struct Merge<I> {
|
|
|
|
iter: I,
|
|
|
|
iter: I,
|
|
|
@ -1691,7 +1692,7 @@ impl<I: Iterator<Item = HighlightEvent>> Iterator for Merge<I> {
|
|
|
|
loop {
|
|
|
|
loop {
|
|
|
|
match (self.next_event, &self.next_span) {
|
|
|
|
match (self.next_event, &self.next_span) {
|
|
|
|
// this happens when range is partially or fully offscreen
|
|
|
|
// this happens when range is partially or fully offscreen
|
|
|
|
(Some(Source { start, end }), Some((span, range))) if start > range.start => {
|
|
|
|
(Some(Source { start, .. }), Some((span, range))) if start > range.start => {
|
|
|
|
if start > range.end {
|
|
|
|
if start > range.end {
|
|
|
|
self.next_span = self.spans.next();
|
|
|
|
self.next_span = self.spans.next();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -1711,7 +1712,7 @@ impl<I: Iterator<Item = HighlightEvent>> Iterator for Merge<I> {
|
|
|
|
self.next_event = self.iter.next();
|
|
|
|
self.next_event = self.iter.next();
|
|
|
|
Some(HighlightEnd)
|
|
|
|
Some(HighlightEnd)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
(Some(Source { start, end }), Some((span, range))) if start < range.start => {
|
|
|
|
(Some(Source { start, end }), Some((_, range))) if start < range.start => {
|
|
|
|
let intersect = range.start.min(end);
|
|
|
|
let intersect = range.start.min(end);
|
|
|
|
let event = Source {
|
|
|
|
let event = Source {
|
|
|
|
start,
|
|
|
|
start,
|
|
|
@ -1766,7 +1767,7 @@ impl<I: Iterator<Item = HighlightEvent>> Iterator for Merge<I> {
|
|
|
|
Some(event)
|
|
|
|
Some(event)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// can happen if deleting and cursor at EOF, and diagnostic reaches past the end
|
|
|
|
// can happen if deleting and cursor at EOF, and diagnostic reaches past the end
|
|
|
|
(None, Some((span, range))) => {
|
|
|
|
(None, Some((_, _))) => {
|
|
|
|
self.next_span = None;
|
|
|
|
self.next_span = None;
|
|
|
|
None
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1809,7 +1810,7 @@ mod test {
|
|
|
|
.collect();
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
|
|
|
|
let language = get_language(Lang::Rust);
|
|
|
|
let language = get_language(Lang::Rust);
|
|
|
|
let mut config = HighlightConfiguration::new(
|
|
|
|
let config = HighlightConfiguration::new(
|
|
|
|
language,
|
|
|
|
language,
|
|
|
|
&std::fs::read_to_string(
|
|
|
|
&std::fs::read_to_string(
|
|
|
|
"../helix-syntax/languages/tree-sitter-rust/queries/highlights.scm",
|
|
|
|
"../helix-syntax/languages/tree-sitter-rust/queries/highlights.scm",
|
|
|
@ -1853,7 +1854,7 @@ mod test {
|
|
|
|
use crate::State;
|
|
|
|
use crate::State;
|
|
|
|
use tree_sitter::InputEdit;
|
|
|
|
use tree_sitter::InputEdit;
|
|
|
|
|
|
|
|
|
|
|
|
let mut state = State::new("hello world!\ntest 123".into());
|
|
|
|
let state = State::new("hello world!\ntest 123".into());
|
|
|
|
let transaction = Transaction::change(
|
|
|
|
let transaction = Transaction::change(
|
|
|
|
&state.doc,
|
|
|
|
&state.doc,
|
|
|
|
vec![(6, 11, Some("test".into())), (12, 17, None)].into_iter(),
|
|
|
|
vec![(6, 11, Some("test".into())), (12, 17, None)].into_iter(),
|
|
|
|