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)
This commit is contained in:
Anton Gilgur 2022-06-24 12:34:42 -04:00 committed by GitHub
parent 74f6761ff6
commit b2584971da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;
}