Skip to content

Commit 3b6b4a9

Browse files
committed
Add plugin override for watchFactory
1 parent 4f7694c commit 3b6b4a9

16 files changed

+39
-28
lines changed

src/compiler/sys.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,7 +1010,7 @@ export function createSystemWatchFunctions({
10101010
];
10111011
sysLog(`Enabling watchFactory ${isString(options.watchFactory) ? options.watchFactory : JSON.stringify(options.watchFactory)} from candidate paths: ${searchPaths.join(",")}`);
10121012
const { resolvedModule, errorLogs, pluginConfigEntry } = resolveModule<UserWatchFactoryModule>(
1013-
isString(options.watchFactory) ? { name: options.watchFactory } : options.watchFactory,
1013+
getWatchFactoryPlugin(options),
10141014
searchPaths,
10151015
getSystem(),
10161016
sysLog
@@ -1028,6 +1028,11 @@ export function createSystemWatchFunctions({
10281028
return setUserWatchFactory(options, /*userWatchFactory*/ undefined);
10291029
}
10301030

1031+
function getWatchFactoryPlugin(options: WatchOptions) {
1032+
const plugin = isString(options.watchFactory) ? { name: options.watchFactory } : options.watchFactory!;
1033+
return options.getHost?.().getPluginWithConfigOverride(plugin) || plugin;
1034+
}
1035+
10311036
function setUserWatchFactory(options: WatchOptions, userWatchFactory: UserWatchFactory | undefined) {
10321037
setWatchOptionInternalProperty(options, "getResolvedWatchFactory", userWatchFactory ? () => userWatchFactory : returnUndefined);
10331038
return userWatchFactory;

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7179,6 +7179,7 @@ export interface UserWatchFactory {
71797179
/**@internal*/
71807180
export interface WatchOptionsFactoryHost {
71817181
searchPaths: readonly string[];
7182+
getPluginWithConfigOverride(plugin: PluginImport): PluginImport;
71827183
}
71837184
export interface WatchOptions {
71847185
watchFile?: WatchFileKind;

src/server/editorServices.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ export class ProjectService {
971971
public readonly pluginProbeLocations: readonly string[];
972972
public readonly allowLocalPluginLoads: boolean;
973973
/** @internal */
974-
currentPluginConfigOverrides: Map<string, any> | undefined;
974+
private currentPluginConfigOverrides: Map<string, any> | undefined;
975975

976976
public readonly typesMapLocation: string | undefined;
977977

@@ -3274,7 +3274,8 @@ export class ProjectService {
32743274
/** @internal */
32753275
private setWatchOptionsFactoryHost(options: WatchOptions, canonicalConfigFilePath: NormalizedPath | undefined) {
32763276
setWatchOptionInternalProperty(options, "getHost", memoize(() => ({
3277-
searchPaths: this.getProjectPluginSearchPaths(canonicalConfigFilePath)
3277+
searchPaths: this.getProjectPluginSearchPaths(canonicalConfigFilePath),
3278+
getPluginWithConfigOverride: plugin => this.getPluginWithConfigOverride(plugin),
32783279
})));
32793280
}
32803281

@@ -4306,6 +4307,18 @@ export class ProjectService {
43064307
return searchPaths;
43074308
}
43084309

4310+
/** @internal */
4311+
getPluginWithConfigOverride(pluginConfigEntry: PluginImport) {
4312+
const configurationOverride = this.currentPluginConfigOverrides?.get(pluginConfigEntry.name);
4313+
if (configurationOverride) {
4314+
// Preserve the name property since it's immutable
4315+
const pluginName = pluginConfigEntry.name;
4316+
pluginConfigEntry = configurationOverride;
4317+
pluginConfigEntry.name = pluginName;
4318+
}
4319+
return pluginConfigEntry;
4320+
}
4321+
43094322
/** @internal */
43104323
requestEnablePlugin(project: Project, pluginConfigEntry: PluginImport, searchPaths: string[]) {
43114324
if (!this.host.importPlugin && !this.host.require) {

src/server/project.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1821,15 +1821,7 @@ export abstract class Project implements LanguageServiceHost, ModuleResolutionHo
18211821
*/
18221822
endEnablePlugin({ pluginConfigEntry, resolvedModule, errorLogs }: BeginEnablePluginResult) {
18231823
if (resolvedModule) {
1824-
const configurationOverride = this.projectService.currentPluginConfigOverrides?.get(pluginConfigEntry.name);
1825-
if (configurationOverride) {
1826-
// Preserve the name property since it's immutable
1827-
const pluginName = pluginConfigEntry.name;
1828-
pluginConfigEntry = configurationOverride;
1829-
pluginConfigEntry.name = pluginName;
1830-
}
1831-
1832-
this.enableProxy(resolvedModule, pluginConfigEntry);
1824+
this.enableProxy(resolvedModule, this.projectService.getPluginWithConfigOverride(pluginConfigEntry));
18331825
}
18341826
else {
18351827
forEach(errorLogs, message => this.projectService.logger.info(message));

tests/baselines/reference/tsserver/watchEnvironment/watchFactory-as-configuration-of-host-with-pluginOverride-allowLocalPluginLoads-object.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Info 10 [00:00:33.000] For info: /user/username/projects/myproject/a.ts :: Con
8484
Info 11 [00:00:34.000] Creating configuration project /user/username/projects/myproject/tsconfig.json
8585
Info 12 [00:00:35.000] FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}} Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
8686
CustomRequire:: Resolving myplugin from /a/pluginprobe1/node_modules
87-
Require:: Module myplugin created with config: {"name":"myplugin","myconfig":"somethingelse"} and options: {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
87+
Require:: Module myplugin created with config: {"init":"initialConfig","name":"myplugin"} and options: {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
8888
Custom watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
8989
Info 13 [00:00:36.000] Config: /user/username/projects/myproject/tsconfig.json : {
9090
"rootNames": [

tests/baselines/reference/tsserver/watchEnvironment/watchFactory-as-configuration-of-host-with-pluginOverride-allowLocalPluginLoads.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Info 10 [00:00:33.000] For info: /user/username/projects/myproject/a.ts :: Con
8181
Info 11 [00:00:34.000] Creating configuration project /user/username/projects/myproject/tsconfig.json
8282
Info 12 [00:00:35.000] FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin"} Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
8383
CustomRequire:: Resolving myplugin from /a/pluginprobe1/node_modules
84-
Require:: Module myplugin created with config: {"name":"myplugin"} and options: {"watchFactory":"myplugin"}
84+
Require:: Module myplugin created with config: {"init":"initialConfig","name":"myplugin"} and options: {"watchFactory":"myplugin"}
8585
Custom watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin"}
8686
Info 13 [00:00:36.000] Config: /user/username/projects/myproject/tsconfig.json : {
8787
"rootNames": [

tests/baselines/reference/tsserver/watchEnvironment/watchFactory-as-configuration-of-host-with-pluginOverride-object.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Info 10 [00:00:33.000] For info: /user/username/projects/myproject/a.ts :: Con
8484
Info 11 [00:00:34.000] Creating configuration project /user/username/projects/myproject/tsconfig.json
8585
Info 12 [00:00:35.000] FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}} Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
8686
CustomRequire:: Resolving myplugin from /a/pluginprobe1/node_modules
87-
Require:: Module myplugin created with config: {"name":"myplugin","myconfig":"somethingelse"} and options: {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
87+
Require:: Module myplugin created with config: {"init":"initialConfig","name":"myplugin"} and options: {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
8888
Custom watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
8989
Info 13 [00:00:36.000] Config: /user/username/projects/myproject/tsconfig.json : {
9090
"rootNames": [

tests/baselines/reference/tsserver/watchEnvironment/watchFactory-as-configuration-of-host-with-pluginOverride.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Info 10 [00:00:33.000] For info: /user/username/projects/myproject/a.ts :: Con
8181
Info 11 [00:00:34.000] Creating configuration project /user/username/projects/myproject/tsconfig.json
8282
Info 12 [00:00:35.000] FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin"} Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
8383
CustomRequire:: Resolving myplugin from /a/pluginprobe1/node_modules
84-
Require:: Module myplugin created with config: {"name":"myplugin"} and options: {"watchFactory":"myplugin"}
84+
Require:: Module myplugin created with config: {"init":"initialConfig","name":"myplugin"} and options: {"watchFactory":"myplugin"}
8585
Custom watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin"}
8686
Info 13 [00:00:36.000] Config: /user/username/projects/myproject/tsconfig.json : {
8787
"rootNames": [

tests/baselines/reference/tsserver/watchEnvironment/watchFactory-in-config-as-well-as-configuration-of-host-with-pluginOverride-allowLocalPluginLoads-object.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Info 13 [00:00:36.000] For info: /user/username/projects/myproject/a.ts :: Con
106106
Info 14 [00:00:37.000] Creating configuration project /user/username/projects/myproject/tsconfig.json
107107
Info 15 [00:00:38.000] FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin2","myconfig":"somethingelse"}} Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
108108
CustomRequire:: Resolving myplugin2 from /a/pluginprobe1/node_modules
109-
Require:: Module myplugin2 created with config: {"name":"myplugin2","myconfig":"somethingelse"} and options: {"watchFactory":{"name":"myplugin2","myconfig":"somethingelse"}}
109+
Require:: Module myplugin2 created with config: {"init2":"initialConfig2","name":"myplugin2"} and options: {"watchFactory":{"name":"myplugin2","myconfig":"somethingelse"}}
110110
Custom myplugin2watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin2","myconfig":"somethingelse"}}
111111
Info 16 [00:00:39.000] Config: /user/username/projects/myproject/tsconfig.json : {
112112
"rootNames": [
@@ -127,7 +127,7 @@ Info 17 [00:00:40.000] FileWatcher:: Close:: WatchInfo: /user/username/project
127127
Info 18 [00:00:41.000] FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}} Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
128128
Info 19 [00:00:42.000] Local plugin loading enabled; adding /user/username/projects/myproject to search paths
129129
CustomRequire:: Resolving myplugin from /user/username/projects/myproject/node_modules
130-
Require:: Module myplugin created with config: {"name":"myplugin","myconfig":"somethingelse"} and options: {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
130+
Require:: Module myplugin created with config: {"init":"initialConfig","name":"myplugin"} and options: {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
131131
Custom watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
132132
Info 20 [00:00:43.000] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject 1 {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}} Config: /user/username/projects/myproject/tsconfig.json WatchType: Wild card directory
133133
Custom watchDirectory: /user/username/projects/myproject true {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}

tests/baselines/reference/tsserver/watchEnvironment/watchFactory-in-config-as-well-as-configuration-of-host-with-pluginOverride-allowLocalPluginLoads.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Info 13 [00:00:36.000] For info: /user/username/projects/myproject/a.ts :: Con
103103
Info 14 [00:00:37.000] Creating configuration project /user/username/projects/myproject/tsconfig.json
104104
Info 15 [00:00:38.000] FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin2"} Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
105105
CustomRequire:: Resolving myplugin2 from /a/pluginprobe1/node_modules
106-
Require:: Module myplugin2 created with config: {"name":"myplugin2"} and options: {"watchFactory":"myplugin2"}
106+
Require:: Module myplugin2 created with config: {"init2":"initialConfig2","name":"myplugin2"} and options: {"watchFactory":"myplugin2"}
107107
Custom myplugin2watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin2"}
108108
Info 16 [00:00:39.000] Config: /user/username/projects/myproject/tsconfig.json : {
109109
"rootNames": [
@@ -121,7 +121,7 @@ Info 17 [00:00:40.000] FileWatcher:: Close:: WatchInfo: /user/username/project
121121
Info 18 [00:00:41.000] FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin"} Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
122122
Info 19 [00:00:42.000] Local plugin loading enabled; adding /user/username/projects/myproject to search paths
123123
CustomRequire:: Resolving myplugin from /user/username/projects/myproject/node_modules
124-
Require:: Module myplugin created with config: {"name":"myplugin"} and options: {"watchFactory":"myplugin"}
124+
Require:: Module myplugin created with config: {"init":"initialConfig","name":"myplugin"} and options: {"watchFactory":"myplugin"}
125125
Custom watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin"}
126126
Info 20 [00:00:43.000] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject 1 {"watchFactory":"myplugin"} Config: /user/username/projects/myproject/tsconfig.json WatchType: Wild card directory
127127
Custom watchDirectory: /user/username/projects/myproject true {"watchFactory":"myplugin"}

tests/baselines/reference/tsserver/watchEnvironment/watchFactory-in-config-as-well-as-configuration-of-host-with-pluginOverride-object.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Info 13 [00:00:36.000] For info: /user/username/projects/myproject/a.ts :: Con
106106
Info 14 [00:00:37.000] Creating configuration project /user/username/projects/myproject/tsconfig.json
107107
Info 15 [00:00:38.000] FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin2","myconfig":"somethingelse"}} Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
108108
CustomRequire:: Resolving myplugin2 from /a/pluginprobe1/node_modules
109-
Require:: Module myplugin2 created with config: {"name":"myplugin2","myconfig":"somethingelse"} and options: {"watchFactory":{"name":"myplugin2","myconfig":"somethingelse"}}
109+
Require:: Module myplugin2 created with config: {"init2":"initialConfig2","name":"myplugin2"} and options: {"watchFactory":{"name":"myplugin2","myconfig":"somethingelse"}}
110110
Custom myplugin2watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin2","myconfig":"somethingelse"}}
111111
Info 16 [00:00:39.000] Config: /user/username/projects/myproject/tsconfig.json : {
112112
"rootNames": [
@@ -126,7 +126,7 @@ Info 16 [00:00:39.000] Config: /user/username/projects/myproject/tsconfig.json
126126
Info 17 [00:00:40.000] FileWatcher:: Close:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin2","myconfig":"somethingelse"}} Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
127127
Info 18 [00:00:41.000] FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}} Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
128128
CustomRequire:: Resolving myplugin from /a/pluginprobe1/node_modules
129-
Require:: Module myplugin created with config: {"name":"myplugin","myconfig":"somethingelse"} and options: {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
129+
Require:: Module myplugin created with config: {"init":"initialConfig","name":"myplugin"} and options: {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
130130
Custom watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
131131
Info 19 [00:00:42.000] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject 1 {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}} Config: /user/username/projects/myproject/tsconfig.json WatchType: Wild card directory
132132
Custom watchDirectory: /user/username/projects/myproject true {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}

tests/baselines/reference/tsserver/watchEnvironment/watchFactory-in-config-as-well-as-configuration-of-host-with-pluginOverride.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Info 13 [00:00:36.000] For info: /user/username/projects/myproject/a.ts :: Con
103103
Info 14 [00:00:37.000] Creating configuration project /user/username/projects/myproject/tsconfig.json
104104
Info 15 [00:00:38.000] FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin2"} Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
105105
CustomRequire:: Resolving myplugin2 from /a/pluginprobe1/node_modules
106-
Require:: Module myplugin2 created with config: {"name":"myplugin2"} and options: {"watchFactory":"myplugin2"}
106+
Require:: Module myplugin2 created with config: {"init2":"initialConfig2","name":"myplugin2"} and options: {"watchFactory":"myplugin2"}
107107
Custom myplugin2watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin2"}
108108
Info 16 [00:00:39.000] Config: /user/username/projects/myproject/tsconfig.json : {
109109
"rootNames": [
@@ -120,7 +120,7 @@ Info 16 [00:00:39.000] Config: /user/username/projects/myproject/tsconfig.json
120120
Info 17 [00:00:40.000] FileWatcher:: Close:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin2"} Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
121121
Info 18 [00:00:41.000] FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin"} Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
122122
CustomRequire:: Resolving myplugin from /a/pluginprobe1/node_modules
123-
Require:: Module myplugin created with config: {"name":"myplugin"} and options: {"watchFactory":"myplugin"}
123+
Require:: Module myplugin created with config: {"init":"initialConfig","name":"myplugin"} and options: {"watchFactory":"myplugin"}
124124
Custom watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":"myplugin"}
125125
Info 19 [00:00:42.000] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject 1 {"watchFactory":"myplugin"} Config: /user/username/projects/myproject/tsconfig.json WatchType: Wild card directory
126126
Custom watchDirectory: /user/username/projects/myproject true {"watchFactory":"myplugin"}

tests/baselines/reference/tsserver/watchEnvironment/watchFactory-in-config-file-with-pluginOverride-allowLocalPluginLoads-object.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Info 10 [00:00:33.000] FileWatcher:: Close:: WatchInfo: /user/username/project
7777
Info 11 [00:00:34.000] FileWatcher:: Added:: WatchInfo: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}} Project: /user/username/projects/myproject/tsconfig.json WatchType: Config file
7878
Info 12 [00:00:35.000] Local plugin loading enabled; adding /user/username/projects/myproject to search paths
7979
CustomRequire:: Resolving myplugin from /user/username/projects/myproject/node_modules
80-
Require:: Module myplugin created with config: {"name":"myplugin","myconfig":"somethingelse"} and options: {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
80+
Require:: Module myplugin created with config: {"init":"initialConfig","name":"myplugin"} and options: {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
8181
Custom watchFile: /user/username/projects/myproject/tsconfig.json 2000 {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}
8282
Info 13 [00:00:36.000] DirectoryWatcher:: Added:: WatchInfo: /user/username/projects/myproject 1 {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}} Config: /user/username/projects/myproject/tsconfig.json WatchType: Wild card directory
8383
Custom watchDirectory: /user/username/projects/myproject true {"watchFactory":{"name":"myplugin","myconfig":"somethingelse"}}

0 commit comments

Comments
 (0)