@@ -3238,7 +3238,7 @@ class LanguageLayer {
3238
3238
// Do nothing; we don't need to set this boundary.
3239
3239
} else {
3240
3240
// The range must end somewhere within our range.
3241
- //
3241
+ //
3242
3242
// Close the boundaries in the opposite order of how we opened them.
3243
3243
for ( let i = languageScopeIds . length - 1 ; i >= 0 ; i -- ) {
3244
3244
this . scopeResolver . setBoundary (
@@ -3767,7 +3767,7 @@ class LanguageLayer {
3767
3767
}
3768
3768
3769
3769
getOrParseTree ( { force = true , anonymous = false } = { } ) {
3770
- if ( ! this . treeIsDirty || ! force ) { return this . tree ; }
3770
+ if ( this . tree && ( ! this . treeIsDirty || ! force ) ) { return this . tree ; }
3771
3771
3772
3772
// Eventually we'll take this out, but for now it serves as an indicator of
3773
3773
// how often we have to manually re-parse in between transactions —
@@ -4146,8 +4146,15 @@ class NodeRangeSet {
4146
4146
const previousRanges = this . previous ?. getRanges ( buffer ) ;
4147
4147
let result = [ ] ;
4148
4148
4149
- for ( const node of this . nodeSpecs ) {
4149
+ for ( let node of this . nodeSpecs ) {
4150
+ // An injection point isn't given the point at which the buffer ends, so
4151
+ // it's free to return an `endIndex` of `Infinity` here and rely on us to
4152
+ // clip it to the boundary of the buffer.
4153
+ if ( node . endIndex === Infinity ) {
4154
+ node = this . _clipRange ( node , buffer ) ;
4155
+ }
4150
4156
let position = node . startPosition , index = node . startIndex ;
4157
+
4151
4158
if ( node . children && ! this . includeChildren ) {
4152
4159
// If `includeChildren` is `false`, we're effectively collecting all
4153
4160
// the disjoint text nodes that are direct descendants of this node.
@@ -4203,6 +4210,13 @@ class NodeRangeSet {
4203
4210
return this . _consolidateRanges ( result ) ;
4204
4211
}
4205
4212
4213
+ _clipRange ( range , buffer ) {
4214
+ // Convert this range spec to an actual `Range`, clip it, then convert it
4215
+ // back to a range spec with accurate `startIndex` and `endIndex` values.
4216
+ let clippedRange = buffer . clipRange ( rangeForNode ( range ) ) ;
4217
+ return rangeToTreeSitterRangeSpec ( clippedRange , buffer ) ;
4218
+ }
4219
+
4206
4220
// Combine adjacent ranges to minimize the number of boundaries.
4207
4221
_consolidateRanges ( ranges ) {
4208
4222
if ( ranges . length === 1 ) { return ranges ; }
0 commit comments