Skip to content

Commit

Permalink
optim(cache): don't check imports for syntactic diagnostics (#389)
Browse files Browse the repository at this point in the history
- Per the TS LS Wiki (https://github.com/microsoft/TypeScript/wiki/Using-the-Language-Service-API#design-goals), syntactic diagnostics only need to parse the specific file in question
  - since syntax is independent of imports; imports only affect semantics
  • Loading branch information
agilgur5 authored Aug 8, 2022
1 parent e75d97a commit 70c6e25
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/tscache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ export class TsCache

private getDiagnostics(type: string, cache: ICache<IDiagnostics[]>, id: string, snapshot: tsTypes.IScriptSnapshot, check: () => tsTypes.Diagnostic[]): IDiagnostics[]
{
return this.getCached(cache, id, snapshot, true, () => convertDiagnostic(type, check()));
// don't need to check imports for syntactic diagnostics (per https://github.com/microsoft/TypeScript/wiki/Using-the-Language-Service-API#design-goals)
return this.getCached(cache, id, snapshot, type === "semantic", () => convertDiagnostic(type, check()));
}

private getCached<CacheType>(cache: ICache<CacheType>, id: string, snapshot: tsTypes.IScriptSnapshot, checkImports: boolean, convert: () => CacheType): CacheType
Expand Down

0 comments on commit 70c6e25

Please sign in to comment.