optim(cache): don't check imports for syntactic diagnostics (#389)

- 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
This commit is contained in:
Anton Gilgur 2022-08-08 15:14:46 -04:00 committed by GitHub
parent e75d97a758
commit 70c6e253e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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