pull/1563/head^2
Blaž Hrastnik 2 years ago
parent 2302869836
commit 66a8612351

@ -209,12 +209,9 @@ impl LanguageConfiguration {
&highlights_query, &highlights_query,
&injections_query, &injections_query,
&locals_query, &locals_query,
); )
.unwrap(); // TODO: avoid panic
let config = match config {
Ok(config) => config,
Err(err) => panic!("{}", err),
}; // TODO: avoid panic
config.configure(scopes); config.configure(scopes);
Some(Arc::new(config)) Some(Arc::new(config))
} }
@ -392,12 +389,6 @@ pub struct TsParser {
cursors: Vec<QueryCursor>, cursors: Vec<QueryCursor>,
} }
impl fmt::Debug for TsParser {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("TsParser").finish()
}
}
// could also just use a pool, or a single instance? // could also just use a pool, or a single instance?
thread_local! { thread_local! {
pub static PARSER: RefCell<TsParser> = RefCell::new(TsParser { pub static PARSER: RefCell<TsParser> = RefCell::new(TsParser {
@ -433,14 +424,12 @@ impl Syntax {
}], }],
}; };
// track markers of injections
// track scope_descriptor: a Vec of scopes for item in tree // track scope_descriptor: a Vec of scopes for item in tree
let mut layers = HopSlotMap::default(); let mut layers = HopSlotMap::default();
let root = layers.insert(root_layer); let root = layers.insert(root_layer);
let mut syntax = Self { let mut syntax = Self {
// grammar,
root, root,
layers, layers,
loader, loader,
@ -724,15 +713,15 @@ impl Syntax {
.layers .layers
.iter() .iter()
.filter_map(|(_, layer)| { .filter_map(|(_, layer)| {
// TODO: if range doesn't overlap layer range, skip it
// we can calculate intersection and use it later for set_byte_range
// Reuse a cursor from the pool if available. // Reuse a cursor from the pool if available.
let mut cursor = PARSER.with(|ts_parser| { let mut cursor = PARSER.with(|ts_parser| {
let highlighter = &mut ts_parser.borrow_mut(); let highlighter = &mut ts_parser.borrow_mut();
highlighter.cursors.pop().unwrap_or_else(QueryCursor::new) highlighter.cursors.pop().unwrap_or_else(QueryCursor::new)
}); });
// TODO: if range doesn't overlap layer range, skip it
// we can calculate intersection and use it later for set_byte_range
// 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
// pointers, so it's actually ok to move them. // pointers, so it's actually ok to move them.
@ -783,7 +772,7 @@ impl Syntax {
let mut result = HighlightIter { let mut result = HighlightIter {
source, source,
byte_offset: range.map_or(0, |r| r.start), // TODO: simplify byte_offset: range.map_or(0, |r| r.start),
cancellation_flag, cancellation_flag,
iter_count: 0, iter_count: 0,
layers, layers,

Loading…
Cancel
Save