Rename some sum_tree seek targets in SyntaxMap
This commit is contained in:
parent
86f51ade60
commit
ea42bc3c9b
1 changed files with 37 additions and 29 deletions
|
@ -91,7 +91,6 @@ struct SyntaxLayer {
|
||||||
range: Range<Anchor>,
|
range: Range<Anchor>,
|
||||||
tree: tree_sitter::Tree,
|
tree: tree_sitter::Tree,
|
||||||
language: Arc<Language>,
|
language: Arc<Language>,
|
||||||
combined: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -118,12 +117,15 @@ struct SyntaxLayerPosition {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
struct DepthAndMaxPosition(usize, Anchor);
|
struct ChangeStartPosition {
|
||||||
|
depth: usize,
|
||||||
|
position: Anchor,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
struct SyntaxLayerPositionBeforeChange {
|
struct SyntaxLayerPositionBeforeChange {
|
||||||
position: SyntaxLayerPosition,
|
position: SyntaxLayerPosition,
|
||||||
change: DepthAndMaxPosition,
|
change: ChangeStartPosition,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ParseStep {
|
struct ParseStep {
|
||||||
|
@ -234,9 +236,12 @@ impl SyntaxSnapshot {
|
||||||
|
|
||||||
// Preserve any layers at this depth that precede the first edit.
|
// Preserve any layers at this depth that precede the first edit.
|
||||||
if let Some((_, edit_range)) = edits.get(first_edit_ix_for_depth) {
|
if let Some((_, edit_range)) = edits.get(first_edit_ix_for_depth) {
|
||||||
let target = DepthAndMaxPosition(depth, edit_range.start);
|
let position = ChangeStartPosition {
|
||||||
if target.cmp(&cursor.start(), text).is_gt() {
|
depth,
|
||||||
let slice = cursor.slice(&target, Bias::Left, text);
|
position: edit_range.start,
|
||||||
|
};
|
||||||
|
if position.cmp(&cursor.start(), text).is_gt() {
|
||||||
|
let slice = cursor.slice(&position, Bias::Left, text);
|
||||||
layers.push_tree(slice, text);
|
layers.push_tree(slice, text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -359,7 +364,7 @@ impl SyntaxSnapshot {
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let step = queue.pop();
|
let step = queue.pop();
|
||||||
let target = if let Some(step) = &step {
|
let position = if let Some(step) = &step {
|
||||||
SyntaxLayerPosition {
|
SyntaxLayerPosition {
|
||||||
depth: step.depth,
|
depth: step.depth,
|
||||||
range: step.range.clone(),
|
range: step.range.clone(),
|
||||||
|
@ -374,15 +379,15 @@ impl SyntaxSnapshot {
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut done = cursor.item().is_none();
|
let mut done = cursor.item().is_none();
|
||||||
while !done && target.cmp(&cursor.end(text), &text).is_gt() {
|
while !done && position.cmp(&cursor.end(text), &text).is_gt() {
|
||||||
done = true;
|
done = true;
|
||||||
|
|
||||||
let bounded_target = SyntaxLayerPositionBeforeChange {
|
let bounded_position = SyntaxLayerPositionBeforeChange {
|
||||||
position: target.clone(),
|
position: position.clone(),
|
||||||
change: changed_regions.start_position(),
|
change: changed_regions.start_position(),
|
||||||
};
|
};
|
||||||
if bounded_target.cmp(&cursor.start(), &text).is_gt() {
|
if bounded_position.cmp(&cursor.start(), &text).is_gt() {
|
||||||
let slice = cursor.slice(&bounded_target, Bias::Left, text);
|
let slice = cursor.slice(&bounded_position, Bias::Left, text);
|
||||||
if !slice.is_empty() {
|
if !slice.is_empty() {
|
||||||
layers.push_tree(slice, &text);
|
layers.push_tree(slice, &text);
|
||||||
if changed_regions.prune(cursor.end(text), text) {
|
if changed_regions.prune(cursor.end(text), text) {
|
||||||
|
@ -391,10 +396,10 @@ impl SyntaxSnapshot {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while target.cmp(&cursor.end(text), text).is_gt() {
|
while position.cmp(&cursor.end(text), text).is_gt() {
|
||||||
let Some(layer) = cursor.item() else { break };
|
let Some(layer) = cursor.item() else { break };
|
||||||
|
|
||||||
if changed_regions.intersects(&layer, text) && !layer.combined {
|
if changed_regions.intersects(&layer, text) {
|
||||||
changed_regions.insert(
|
changed_regions.insert(
|
||||||
ChangedRegion {
|
ChangedRegion {
|
||||||
depth: layer.depth + 1,
|
depth: layer.depth + 1,
|
||||||
|
@ -430,11 +435,9 @@ impl SyntaxSnapshot {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let combined = matches!(step.mode, ParseMode::Combined { .. });
|
|
||||||
let mut included_ranges = step.included_ranges;
|
|
||||||
|
|
||||||
let tree;
|
let tree;
|
||||||
let changed_ranges;
|
let changed_ranges;
|
||||||
|
let mut included_ranges = step.included_ranges;
|
||||||
if let Some(old_layer) = old_layer {
|
if let Some(old_layer) = old_layer {
|
||||||
if let ParseMode::Combined {
|
if let ParseMode::Combined {
|
||||||
parent_layer_changed_ranges,
|
parent_layer_changed_ranges,
|
||||||
|
@ -484,7 +487,6 @@ impl SyntaxSnapshot {
|
||||||
range: step.range,
|
range: step.range,
|
||||||
tree: tree.clone(),
|
tree: tree.clone(),
|
||||||
language: step.language.clone(),
|
language: step.language.clone(),
|
||||||
combined,
|
|
||||||
},
|
},
|
||||||
&text,
|
&text,
|
||||||
);
|
);
|
||||||
|
@ -1074,7 +1076,8 @@ fn splice_included_ranges(
|
||||||
let new_range = new_ranges.peek();
|
let new_range = new_ranges.peek();
|
||||||
let mut changed_range = changed_ranges.peek();
|
let mut changed_range = changed_ranges.peek();
|
||||||
|
|
||||||
// process changed ranges before any overlapping new ranges
|
// Remove ranges that have changed before inserting any new ranges
|
||||||
|
// into those ranges.
|
||||||
if let Some((changed, new)) = changed_range.zip(new_range) {
|
if let Some((changed, new)) = changed_range.zip(new_range) {
|
||||||
if new.end_byte < changed.start {
|
if new.end_byte < changed.start {
|
||||||
changed_range = None;
|
changed_range = None;
|
||||||
|
@ -1093,7 +1096,7 @@ fn splice_included_ranges(
|
||||||
};
|
};
|
||||||
|
|
||||||
// If there are empty ranges, then there may be multiple ranges with the same
|
// If there are empty ranges, then there may be multiple ranges with the same
|
||||||
// start or end. Expand the splice to include any adjacent ranges. That touch
|
// start or end. Expand the splice to include any adjacent ranges that touch
|
||||||
// the changed range.
|
// the changed range.
|
||||||
while start_ix > 0 {
|
while start_ix > 0 {
|
||||||
if ranges[start_ix - 1].end_byte == changed.start {
|
if ranges[start_ix - 1].end_byte == changed.start {
|
||||||
|
@ -1191,12 +1194,17 @@ impl ChangedRegion {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ChangeRegionSet {
|
impl ChangeRegionSet {
|
||||||
fn start_position(&self) -> DepthAndMaxPosition {
|
fn start_position(&self) -> ChangeStartPosition {
|
||||||
self.0
|
self.0.first().map_or(
|
||||||
.first()
|
ChangeStartPosition {
|
||||||
.map_or(DepthAndMaxPosition(usize::MAX, Anchor::MAX), |region| {
|
depth: usize::MAX,
|
||||||
DepthAndMaxPosition(region.depth, region.range.start)
|
position: Anchor::MAX,
|
||||||
})
|
},
|
||||||
|
|region| ChangeStartPosition {
|
||||||
|
depth: region.depth,
|
||||||
|
position: region.range.start,
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn intersects(&self, layer: &SyntaxLayer, text: &BufferSnapshot) -> bool {
|
fn intersects(&self, layer: &SyntaxLayer, text: &BufferSnapshot) -> bool {
|
||||||
|
@ -1289,10 +1297,10 @@ impl<'a> SeekTarget<'a, SyntaxLayerSummary, SyntaxLayerSummary> for SyntaxLayerP
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> SeekTarget<'a, SyntaxLayerSummary, SyntaxLayerSummary> for DepthAndMaxPosition {
|
impl<'a> SeekTarget<'a, SyntaxLayerSummary, SyntaxLayerSummary> for ChangeStartPosition {
|
||||||
fn cmp(&self, cursor_location: &SyntaxLayerSummary, text: &BufferSnapshot) -> Ordering {
|
fn cmp(&self, cursor_location: &SyntaxLayerSummary, text: &BufferSnapshot) -> Ordering {
|
||||||
Ord::cmp(&self.0, &cursor_location.max_depth)
|
Ord::cmp(&self.depth, &cursor_location.max_depth)
|
||||||
.then_with(|| self.1.cmp(&cursor_location.range.end, text))
|
.then_with(|| self.position.cmp(&cursor_location.range.end, text))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue