Skip to content

Commit

Permalink
fix(host): getScriptSnapshot must also call fileNames.add (#364)
Browse files Browse the repository at this point in the history
- the `fileNames` Set that was previously introduced in c86e07b 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)
  • Loading branch information
agilgur5 authored Jun 24, 2022
1 parent 74f6761 commit b258497
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down

0 comments on commit b258497

Please sign in to comment.