on master help sign in
cleanup
66a8612Blaž Hrastnik
helix-core/src/syntax.rs+6−17
@@ -209,12 +209,9 @@ impl LanguageConfiguration {
209 &highlights_query,
209 &highlights_query,
210 &injections_query,
210 &injections_query,
211 &locals_query,
211 &locals_query,
212− );
212+ )
213+ .unwrap(); // TODO: avoid panic
213
214
214− let config = match config {
215− Ok(config) => config,
216− Err(err) => panic!("{}", err),
217− }; // TODO: avoid panic
218 config.configure(scopes);
215 config.configure(scopes);
219 Some(Arc::new(config))
216 Some(Arc::new(config))
220 }
217 }
@@ -392,12 +389,6 @@ pub struct TsParser {
392 cursors: Vec<QueryCursor>,
389 cursors: Vec<QueryCursor>,
393}
390}
394
391
395−impl fmt::Debug for TsParser {
396− fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
397− f.debug_struct("TsParser").finish()
398− }
399−}
400−
401// could also just use a pool, or a single instance?
392// could also just use a pool, or a single instance?
402thread_local! {
393thread_local! {
403 pub static PARSER: RefCell<TsParser> = RefCell::new(TsParser {
394 pub static PARSER: RefCell<TsParser> = RefCell::new(TsParser {
@@ -433,14 +424,12 @@ impl Syntax {
433 }],
424 }],
434 };
425 };
435
426
436− // track markers of injections
437 // track scope_descriptor: a Vec of scopes for item in tree
427 // track scope_descriptor: a Vec of scopes for item in tree
438
428
439 let mut layers = HopSlotMap::default();
429 let mut layers = HopSlotMap::default();
440 let root = layers.insert(root_layer);
430 let root = layers.insert(root_layer);
441
431
442 let mut syntax = Self {
432 let mut syntax = Self {
443− // grammar,
444 root,
433 root,
445 layers,
434 layers,
446 loader,
435 loader,
@@ -724,15 +713,15 @@ impl Syntax {
724 .layers
713 .layers
725 .iter()
714 .iter()
726 .filter_map(|(_, layer)| {
715 .filter_map(|(_, layer)| {
716+ // TODO: if range doesn't overlap layer range, skip it
717+ // we can calculate intersection and use it later for set_byte_range
718+
727 // Reuse a cursor from the pool if available.
719 // Reuse a cursor from the pool if available.
728 let mut cursor = PARSER.with(|ts_parser| {
720 let mut cursor = PARSER.with(|ts_parser| {
729 let highlighter = &mut ts_parser.borrow_mut();
721 let highlighter = &mut ts_parser.borrow_mut();
730 highlighter.cursors.pop().unwrap_or_else(QueryCursor::new)
722 highlighter.cursors.pop().unwrap_or_else(QueryCursor::new)
731 });
723 });
732
724
733− // TODO: if range doesn't overlap layer range, skip it
734− // we can calculate intersection and use it later for set_byte_range
735−
736 // The `captures` iterator borrows the `Tree` and the `QueryCursor`, which
725 // The `captures` iterator borrows the `Tree` and the `QueryCursor`, which
737 // prevents them from being moved. But both of these values are really just
726 // prevents them from being moved. But both of these values are really just
738 // pointers, so it's actually ok to move them.
727 // pointers, so it's actually ok to move them.
@@ -783,7 +772,7 @@ impl Syntax {
783
772
784 let mut result = HighlightIter {
773 let mut result = HighlightIter {
785 source,
774 source,
786− byte_offset: range.map_or(0, |r| r.start), // TODO: simplify
775+ byte_offset: range.map_or(0, |r| r.start),
787 cancellation_flag,
776 cancellation_flag,
788 iter_count: 0,
777 iter_count: 0,
789 layers,
778 layers,