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

View File

@ -31,6 +31,7 @@ const typescript: PluginImpl<RPT2Options> = (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<string>();
@ -98,6 +99,7 @@ const typescript: PluginImpl<RPT2Options> = (options) =>
pluginOptions.typescript = require("typescript");
}
setTypescriptModule(pluginOptions.typescript);
documentRegistry = tsModule.createDocumentRegistry();
const self: Plugin = {
@ -135,8 +137,7 @@ const typescript: PluginImpl<RPT2Options> = (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