Skip to content

Commit

Permalink
[tree-sitter] Ensure that candidate injection range doesn’t shrink
Browse files Browse the repository at this point in the history
When a region of the buffer changes, we want to consider all injections that touch that range, even if they aren't fully enclosed by the range. So we need to be able to grow the original range when searching for injection layers.

This fixes a bug in which the candidate range could inadvertently _shrink_.
  • Loading branch information
savetheclocktower committed Nov 10, 2023
1 parent 193a3dc commit fc67477
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/wasm-tree-sitter-language-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -3838,13 +3838,13 @@ class LanguageLayer {
if (existingInjectionMarkers.length > 0) {
// Enlarge our range to contain all of the injection zones in the
// affected buffer range.
let earliest, latest;
let earliest = range.start, latest = range.end;
for (let marker of existingInjectionMarkers) {
range = marker.getRange();
if (!earliest || range.start.compare(earliest) === -1) {
if (range.start.compare(earliest) === -1) {
earliest = range.start;
}
if (!latest || range.end.compare(latest) === 1) {
if (range.end.compare(latest) === 1) {
latest = range.end;
}
}
Expand Down

0 comments on commit fc67477

Please sign in to comment.