Skip to content

Commit

Permalink
perf: auto import cache for svelte-kit language service proxy (#2513)
Browse files Browse the repository at this point in the history
#2464

getPackageJsonsVisibleToFile and getGlobalTypingsCacheLocation are singleton so this should definitely be fine. The proxy language service has the exact list of entry files and the auto-typing also doesn't add any export so it should be fine to just proxy these methods.
  • Loading branch information
jasonlyu123 authored Sep 25, 2024
1 parent 81019d9 commit 35af691
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions packages/typescript-plugin/src/language-service/sveltekit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ interface KitSnapshot {
addedCode: InternalHelpers.AddedCode[];
}

declare module 'typescript/lib/tsserverlibrary' {
interface LanguageServiceHost {
/** @internal */ getCachedExportInfoMap?(): unknown;
/** @internal */ getModuleSpecifierCache?(): unknown;
/** @internal */ getGlobalTypingsCacheLocation?(): string | undefined;
/** @internal */ getSymlinkCache?(files: readonly ts.SourceFile[]): unknown;
/** @internal */ getPackageJsonsVisibleToFile?(
fileName: string,
rootDir?: string
): readonly unknown[];
/** @internal */ getPackageJsonAutoImportProvider?(): ts.Program | undefined;

/** @internal*/ getModuleResolutionCache?(): ts.ModuleResolutionCache;
}
}

const cache = new WeakMap<
ts.server.PluginCreateInfo,
{
Expand Down Expand Up @@ -719,6 +735,51 @@ function getProxiedLanguageService(info: ts.server.PluginCreateInfo, ts: _ts, lo
? (...args: Parameters<NonNullable<ts.LanguageServiceHost['realpath']>>) =>
originalLanguageServiceHost.realpath!(...args)
: undefined;

getProjectReferences = originalLanguageServiceHost.getProjectReferences
? () => originalLanguageServiceHost.getProjectReferences!()
: undefined;

getParsedCommandLine = originalLanguageServiceHost.getParsedCommandLine
? (fileName: string) => originalLanguageServiceHost.getParsedCommandLine!(fileName)
: undefined;

getCachedExportInfoMap = originalLanguageServiceHost.getCachedExportInfoMap
? () => originalLanguageServiceHost.getCachedExportInfoMap!()
: undefined;

getModuleSpecifierCache = originalLanguageServiceHost.getModuleSpecifierCache
? () => originalLanguageServiceHost.getModuleSpecifierCache!()
: undefined;

getGlobalTypingsCacheLocation = originalLanguageServiceHost.getGlobalTypingsCacheLocation
? () => originalLanguageServiceHost.getGlobalTypingsCacheLocation!()
: undefined;

getSymlinkCache = originalLanguageServiceHost.getSymlinkCache
? (...args: any[]) =>
originalLanguageServiceHost.getSymlinkCache!(
// @ts-ignore
...args
)
: undefined;

getPackageJsonsVisibleToFile = originalLanguageServiceHost.getPackageJsonsVisibleToFile
? (...args: any[]) =>
originalLanguageServiceHost.getPackageJsonsVisibleToFile!(
// @ts-ignore
...args
)
: undefined;

getPackageJsonAutoImportProvider =
originalLanguageServiceHost.getPackageJsonAutoImportProvider
? () => originalLanguageServiceHost.getPackageJsonAutoImportProvider!()
: undefined;

getModuleResolutionCache = originalLanguageServiceHost.getModuleResolutionCache
? () => originalLanguageServiceHost.getModuleResolutionCache!()
: undefined;
}

// Ideally we'd create a full Proxy of the language service, but that seems to have cache issues
Expand Down

0 comments on commit 35af691

Please sign in to comment.