Merge pull request #18093 from RyanCavanaugh/detectBadPlugins
Detect bad plugins and work around them
This commit is contained in:
commit
1f0e7b02ea
1 changed files with 16 additions and 2 deletions
|
@ -998,16 +998,22 @@ namespace ts.server {
|
||||||
if (this.projectService.globalPlugins) {
|
if (this.projectService.globalPlugins) {
|
||||||
// Enable global plugins with synthetic configuration entries
|
// Enable global plugins with synthetic configuration entries
|
||||||
for (const globalPluginName of this.projectService.globalPlugins) {
|
for (const globalPluginName of this.projectService.globalPlugins) {
|
||||||
|
// Skip empty names from odd commandline parses
|
||||||
|
if (!globalPluginName) continue;
|
||||||
|
|
||||||
// Skip already-locally-loaded plugins
|
// Skip already-locally-loaded plugins
|
||||||
if (options.plugins && options.plugins.some(p => p.name === globalPluginName)) continue;
|
if (options.plugins && options.plugins.some(p => p.name === globalPluginName)) continue;
|
||||||
|
|
||||||
// Provide global: true so plugins can detect why they can't find their config
|
// Provide global: true so plugins can detect why they can't find their config
|
||||||
|
this.projectService.logger.info(`Loading global plugin ${globalPluginName}`);
|
||||||
this.enablePlugin({ name: globalPluginName, global: true } as PluginImport, searchPaths);
|
this.enablePlugin({ name: globalPluginName, global: true } as PluginImport, searchPaths);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private enablePlugin(pluginConfigEntry: PluginImport, searchPaths: string[]) {
|
private enablePlugin(pluginConfigEntry: PluginImport, searchPaths: string[]) {
|
||||||
|
this.projectService.logger.info(`Enabling plugin ${pluginConfigEntry.name} from candidate paths: ${searchPaths.join(",")}`);
|
||||||
|
|
||||||
const log = (message: string) => {
|
const log = (message: string) => {
|
||||||
this.projectService.logger.info(message);
|
this.projectService.logger.info(message);
|
||||||
};
|
};
|
||||||
|
@ -1019,7 +1025,7 @@ namespace ts.server {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.projectService.logger.info(`Couldn't find ${pluginConfigEntry.name} anywhere in paths: ${searchPaths.join(",")}`);
|
this.projectService.logger.info(`Couldn't find ${pluginConfigEntry.name}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
private enableProxy(pluginModuleFactory: PluginModuleFactory, configEntry: PluginImport) {
|
private enableProxy(pluginModuleFactory: PluginModuleFactory, configEntry: PluginImport) {
|
||||||
|
@ -1038,7 +1044,15 @@ namespace ts.server {
|
||||||
};
|
};
|
||||||
|
|
||||||
const pluginModule = pluginModuleFactory({ typescript: ts });
|
const pluginModule = pluginModuleFactory({ typescript: ts });
|
||||||
this.languageService = pluginModule.create(info);
|
const newLS = pluginModule.create(info);
|
||||||
|
for (const k of Object.keys(this.languageService)) {
|
||||||
|
if (!(k in newLS)) {
|
||||||
|
this.projectService.logger.info(`Plugin activation warning: Missing proxied method ${k} in created LS. Patching.`);
|
||||||
|
(newLS as any)[k] = (this.languageService as any)[k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.projectService.logger.info(`Plugin validation succeded`);
|
||||||
|
this.languageService = newLS;
|
||||||
this.plugins.push(pluginModule);
|
this.plugins.push(pluginModule);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
|
|
Loading…
Reference in a new issue