Skip to content

Commit 1f0e7b0

Browse files
Merge pull request #18093 from RyanCavanaugh/detectBadPlugins
Detect bad plugins and work around them
2 parents d90814b + 67f2716 commit 1f0e7b0

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/server/project.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -998,16 +998,22 @@ namespace ts.server {
998998
if (this.projectService.globalPlugins) {
999999
// Enable global plugins with synthetic configuration entries
10001000
for (const globalPluginName of this.projectService.globalPlugins) {
1001+
// Skip empty names from odd commandline parses
1002+
if (!globalPluginName) continue;
1003+
10011004
// Skip already-locally-loaded plugins
10021005
if (options.plugins && options.plugins.some(p => p.name === globalPluginName)) continue;
10031006

10041007
// Provide global: true so plugins can detect why they can't find their config
1008+
this.projectService.logger.info(`Loading global plugin ${globalPluginName}`);
10051009
this.enablePlugin({ name: globalPluginName, global: true } as PluginImport, searchPaths);
10061010
}
10071011
}
10081012
}
10091013

10101014
private enablePlugin(pluginConfigEntry: PluginImport, searchPaths: string[]) {
1015+
this.projectService.logger.info(`Enabling plugin ${pluginConfigEntry.name} from candidate paths: ${searchPaths.join(",")}`);
1016+
10111017
const log = (message: string) => {
10121018
this.projectService.logger.info(message);
10131019
};
@@ -1019,7 +1025,7 @@ namespace ts.server {
10191025
return;
10201026
}
10211027
}
1022-
this.projectService.logger.info(`Couldn't find ${pluginConfigEntry.name} anywhere in paths: ${searchPaths.join(",")}`);
1028+
this.projectService.logger.info(`Couldn't find ${pluginConfigEntry.name}`);
10231029
}
10241030

10251031
private enableProxy(pluginModuleFactory: PluginModuleFactory, configEntry: PluginImport) {
@@ -1038,7 +1044,15 @@ namespace ts.server {
10381044
};
10391045

10401046
const pluginModule = pluginModuleFactory({ typescript: ts });
1041-
this.languageService = pluginModule.create(info);
1047+
const newLS = pluginModule.create(info);
1048+
for (const k of Object.keys(this.languageService)) {
1049+
if (!(k in newLS)) {
1050+
this.projectService.logger.info(`Plugin activation warning: Missing proxied method ${k} in created LS. Patching.`);
1051+
(newLS as any)[k] = (this.languageService as any)[k];
1052+
}
1053+
}
1054+
this.projectService.logger.info(`Plugin validation succeded`);
1055+
this.languageService = newLS;
10421056
this.plugins.push(pluginModule);
10431057
}
10441058
catch (e) {

0 commit comments

Comments
 (0)