fix(language-server): bypass cache for version-less documents

This commit is contained in:
2026-08-18 20:38:37 +05:30
parent 7301849a7f
commit 6074d19c43
2 changed files with 23 additions and 3 deletions
+7 -3
View File
@@ -100,12 +100,16 @@ export function isInsideHtml(document: TextDocument, offset: number): boolean {
const regionCache = new Map<string, { version: number; regions: HtmlRegion[] }>();
function regionsFor(document: TextDocument): HtmlRegion[] {
const version = document.version ?? -1;
// Documents without a version have no way to signal changes, so bypass cache.
if (document.version === undefined) {
return viewRegions(document.text);
}
const cached = regionCache.get(document.uri);
if (cached && cached.version === version) return cached.regions;
if (cached && cached.version === document.version) return cached.regions;
const regions = viewRegions(document.text);
regionCache.set(document.uri, { version, regions });
regionCache.set(document.uri, { version: document.version, regions });
return regions;
}