Skip to content

Commit 7b5247f

Browse files
Merge pull request #18605 from RyanCavanaugh/portExternalFilesFixes
Port plugin fixes from master
2 parents e9a9d2c + 6ed9bad commit 7b5247f

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/server/project.ts

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,8 @@ namespace ts.server {
742742
}
743743
// compute and return the difference
744744
const lastReportedFileNames = this.lastReportedFileNames;
745-
const currentFiles = arrayToSet(this.getFileNames());
745+
const externalFiles = this.getExternalFiles().map(f => toNormalizedPath(f));
746+
const currentFiles = arrayToSet(this.getFileNames().concat(externalFiles));
746747

747748
const added: string[] = [];
748749
const removed: string[] = [];
@@ -765,7 +766,8 @@ namespace ts.server {
765766
else {
766767
// unknown version - return everything
767768
const projectFileNames = this.getFileNames();
768-
this.lastReportedFileNames = arrayToSet(projectFileNames);
769+
const externalFiles = this.getExternalFiles().map(f => toNormalizedPath(f));
770+
this.lastReportedFileNames = arrayToSet(projectFileNames.concat(externalFiles));
769771
this.lastReportedVersion = this.projectStructureVersion;
770772
return { info, files: projectFileNames, projectErrors: this.getGlobalProjectErrors() };
771773
}
@@ -994,16 +996,22 @@ namespace ts.server {
994996
if (this.projectService.globalPlugins) {
995997
// Enable global plugins with synthetic configuration entries
996998
for (const globalPluginName of this.projectService.globalPlugins) {
999+
// Skip empty names from odd commandline parses
1000+
if (!globalPluginName) continue;
1001+
9971002
// Skip already-locally-loaded plugins
9981003
if (options.plugins && options.plugins.some(p => p.name === globalPluginName)) continue;
9991004

10001005
// Provide global: true so plugins can detect why they can't find their config
1006+
this.projectService.logger.info(`Loading global plugin ${globalPluginName}`);
10011007
this.enablePlugin({ name: globalPluginName, global: true } as PluginImport, searchPaths);
10021008
}
10031009
}
10041010
}
10051011

10061012
private enablePlugin(pluginConfigEntry: PluginImport, searchPaths: string[]) {
1013+
this.projectService.logger.info(`Enabling plugin ${pluginConfigEntry.name} from candidate paths: ${searchPaths.join(",")}`);
1014+
10071015
const log = (message: string) => {
10081016
this.projectService.logger.info(message);
10091017
};
@@ -1015,7 +1023,7 @@ namespace ts.server {
10151023
return;
10161024
}
10171025
}
1018-
this.projectService.logger.info(`Couldn't find ${pluginConfigEntry.name} anywhere in paths: ${searchPaths.join(",")}`);
1026+
this.projectService.logger.info(`Couldn't find ${pluginConfigEntry.name}`);
10191027
}
10201028

10211029
private enableProxy(pluginModuleFactory: PluginModuleFactory, configEntry: PluginImport) {
@@ -1034,7 +1042,15 @@ namespace ts.server {
10341042
};
10351043

10361044
const pluginModule = pluginModuleFactory({ typescript: ts });
1037-
this.languageService = pluginModule.create(info);
1045+
const newLS = pluginModule.create(info);
1046+
for (const k of Object.keys(this.languageService)) {
1047+
if (!(k in newLS)) {
1048+
this.projectService.logger.info(`Plugin activation warning: Missing proxied method ${k} in created LS. Patching.`);
1049+
(newLS as any)[k] = (this.languageService as any)[k];
1050+
}
1051+
}
1052+
this.projectService.logger.info(`Plugin validation succeded`);
1053+
this.languageService = newLS;
10381054
this.plugins.push(pluginModule);
10391055
}
10401056
catch (e) {
@@ -1066,6 +1082,9 @@ namespace ts.server {
10661082
}
10671083
catch (e) {
10681084
this.projectService.logger.info(`A plugin threw an exception in getExternalFiles: ${e}`);
1085+
if (e.stack) {
1086+
this.projectService.logger.info(e.stack);
1087+
}
10691088
}
10701089
}));
10711090
}
@@ -1174,6 +1193,7 @@ namespace ts.server {
11741193
public compileOnSaveEnabled: boolean,
11751194
private readonly projectFilePath?: string) {
11761195
super(externalProjectName, ProjectKind.External, projectService, documentRegistry, /*hasExplicitListOfFiles*/ true, languageServiceEnabled, compilerOptions, compileOnSaveEnabled);
1196+
11771197
}
11781198

11791199
getProjectRootPath() {

0 commit comments

Comments
 (0)