From e75d97a758c69a355eea095922820b5bfb348797 Mon Sep 17 00:00:00 2001 From: Anton Gilgur Date: Mon, 8 Aug 2022 15:14:04 -0400 Subject: [PATCH] optim(watch): don't reset DocumentRegistry b/t watch cycles (#388) - we can re-use the same one during watch instead of resetting it in the `options` hook - should make the LS a bit faster / more efficient in watch mode as most source files are shared between watch cycles --- src/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 19c7b35..6195b3e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -31,6 +31,7 @@ const typescript: PluginImpl = (options) => let tsConfigPath: string | undefined; let servicesHost: LanguageServiceHost; let service: tsTypes.LanguageService; + let documentRegistry: tsTypes.DocumentRegistry; // keep the same DocumentRegistry between watch cycles let noErrors = true; const declarations: { [name: string]: { type: tsTypes.OutputFile; map?: tsTypes.OutputFile } } = {}; const checkedFiles = new Set(); @@ -98,6 +99,7 @@ const typescript: PluginImpl = (options) => pluginOptions.typescript = require("typescript"); } setTypescriptModule(pluginOptions.typescript); + documentRegistry = tsModule.createDocumentRegistry(); const self: Plugin = { @@ -135,8 +137,7 @@ const typescript: PluginImpl = (options) => filter = createFilter(context, pluginOptions, parsedConfig); servicesHost = new LanguageServiceHost(parsedConfig, pluginOptions.transformers, pluginOptions.cwd); - - service = tsModule.createLanguageService(servicesHost, tsModule.createDocumentRegistry()); + service = tsModule.createLanguageService(servicesHost, documentRegistry); servicesHost.setLanguageService(service); // printing compiler option errors