@@ -2,8 +2,8 @@ import type { Position, TextDocument } from "@cursorless/common";
22import type { QueryMatch } from "./QueryCapture" ;
33
44export class Cache {
5- private documentUri : string = "" ;
65 private documentVersion : number = - 1 ;
6+ private documentUri : string = "" ;
77 private documentLanguageId : string = "" ;
88 private startPosition : Position | undefined ;
99 private endPosition : Position | undefined ;
@@ -24,11 +24,11 @@ export class Cache {
2424 endPosition : Position | undefined ,
2525 ) {
2626 return (
27- this . documentUri === document . uri . toString ( ) &&
2827 this . documentVersion === document . version &&
28+ this . documentUri === document . uri . toString ( ) &&
2929 this . documentLanguageId === document . languageId &&
30- this . startPosition === startPosition &&
31- this . endPosition === endPosition
30+ positionsEqual ( this . startPosition , startPosition ) &&
31+ positionsEqual ( this . endPosition , endPosition )
3232 ) ;
3333 }
3434
@@ -38,8 +38,8 @@ export class Cache {
3838 endPosition : Position | undefined ,
3939 matches : QueryMatch [ ] ,
4040 ) {
41- this . documentUri = document . uri . toString ( ) ;
4241 this . documentVersion = document . version ;
42+ this . documentUri = document . uri . toString ( ) ;
4343 this . documentLanguageId = document . languageId ;
4444 this . startPosition = startPosition ;
4545 this . endPosition = endPosition ;
@@ -51,4 +51,11 @@ export class Cache {
5151 }
5252}
5353
54+ function positionsEqual ( a : Position | undefined , b : Position | undefined ) {
55+ if ( a == null || b == null ) {
56+ return a === b ;
57+ }
58+ return a . isEqual ( b ) ;
59+ }
60+
5461export const treeSitterQueryCache = new Cache ( ) ;
0 commit comments