From b2584971dac9bfee1c912d088380d16f2d97efbc Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Fri, 24 Jun 2022 12:34:42 -0400 Subject: [PATCH] fix(host): `getScriptSnapshot` must also call `fileNames.add` (#364) - the `fileNames` Set that was previously introduced in c86e07bc caused a regression during watch mode - this is because `setSnapshot` was updated to call `this.fileNames.add`, but `getScriptSnapshot` was not - instead of updating both to be the same, we can just call `setSnapshot` from `getScriptSnapshot` as this code is supposed to be identical - also rename `data` -> `source` for consistency and clarity (`source` is a more specific name) --- src/host.ts | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/host.ts b/src/host.ts index 8df432d4..b0a2b615 100644 --- a/src/host.ts +++ b/src/host.ts @@ -27,11 +27,11 @@ export class LanguageServiceHost implements tsTypes.LanguageServiceHost this.service = service; } - public setSnapshot(fileName: string, data: string): tsTypes.IScriptSnapshot + public setSnapshot(fileName: string, source: string): tsTypes.IScriptSnapshot { fileName = normalize(fileName); - const snapshot = tsModule.ScriptSnapshot.fromString(data); + const snapshot = tsModule.ScriptSnapshot.fromString(source); this.snapshots[fileName] = snapshot; this.versions[fileName] = (this.versions[fileName] || 0) + 1; this.fileNames.add(fileName); @@ -47,11 +47,7 @@ export class LanguageServiceHost implements tsTypes.LanguageServiceHost const source = tsModule.sys.readFile(fileName); if (source) - { - this.snapshots[fileName] = tsModule.ScriptSnapshot.fromString(source); - this.versions[fileName] = (this.versions[fileName] || 0) + 1; - return this.snapshots[fileName]; - } + return this.setSnapshot(fileName, source); return undefined; }