@@ -72,6 +72,12 @@ namespace ts.server {
7272 export interface PluginModule {
7373 create ( createInfo : PluginCreateInfo ) : LanguageService ;
7474 getExternalFiles ?( proj : Project ) : string [ ] ;
75+ onConfigurationChanged ?( config : any ) : void ;
76+ }
77+
78+ export interface PluginModuleWithName {
79+ name : string ;
80+ module : PluginModule ;
7581 }
7682
7783 export type PluginModuleFactory = ( mod : { typescript : typeof ts } ) => PluginModule ;
@@ -92,7 +98,7 @@ namespace ts.server {
9298 private program : Program ;
9399 private externalFiles : SortedReadonlyArray < string > ;
94100 private missingFilesMap : Map < FileWatcher > ;
95- private plugins : PluginModule [ ] = [ ] ;
101+ private plugins : PluginModuleWithName [ ] = [ ] ;
96102
97103 /*@internal */
98104 /**
@@ -549,9 +555,9 @@ namespace ts.server {
549555
550556 getExternalFiles ( ) : SortedReadonlyArray < string > {
551557 return toSortedArray ( flatMapToMutable ( this . plugins , plugin => {
552- if ( typeof plugin . getExternalFiles !== "function" ) return ;
558+ if ( typeof plugin . module . getExternalFiles !== "function" ) return ;
553559 try {
554- return plugin . getExternalFiles ( this ) ;
560+ return plugin . module . getExternalFiles ( this ) ;
555561 }
556562 catch ( e ) {
557563 this . projectService . logger . info ( `A plugin threw an exception in getExternalFiles: ${ e } ` ) ;
@@ -1111,7 +1117,7 @@ namespace ts.server {
11111117 this . rootFilesMap . delete ( info . path ) ;
11121118 }
11131119
1114- protected enableGlobalPlugins ( options : CompilerOptions ) {
1120+ protected enableGlobalPlugins ( options : CompilerOptions , pluginConfigOverrides : Map < any > | undefined ) {
11151121 const host = this . projectService . host ;
11161122
11171123 if ( ! host . require ) {
@@ -1134,12 +1140,13 @@ namespace ts.server {
11341140
11351141 // Provide global: true so plugins can detect why they can't find their config
11361142 this . projectService . logger . info ( `Loading global plugin ${ globalPluginName } ` ) ;
1137- this . enablePlugin ( { name : globalPluginName , global : true } as PluginImport , searchPaths ) ;
1143+
1144+ this . enablePlugin ( { name : globalPluginName , global : true } as PluginImport , searchPaths , pluginConfigOverrides ) ;
11381145 }
11391146 }
11401147 }
11411148
1142- protected enablePlugin ( pluginConfigEntry : PluginImport , searchPaths : string [ ] ) {
1149+ protected enablePlugin ( pluginConfigEntry : PluginImport , searchPaths : string [ ] , pluginConfigOverrides : Map < any > | undefined ) {
11431150 this . projectService . logger . info ( `Enabling plugin ${ pluginConfigEntry . name } from candidate paths: ${ searchPaths . join ( "," ) } ` ) ;
11441151
11451152 const log = ( message : string ) => {
@@ -1149,18 +1156,21 @@ namespace ts.server {
11491156 const resolvedModule = firstDefined ( searchPaths , searchPath =>
11501157 < PluginModuleFactory | undefined > Project . resolveModule ( pluginConfigEntry . name , searchPath , this . projectService . host , log ) ) ;
11511158 if ( resolvedModule ) {
1159+ const configurationOverride = pluginConfigOverrides && pluginConfigOverrides . get ( pluginConfigEntry . name ) ;
1160+ if ( configurationOverride ) {
1161+ // Preserve the name property since it's immutable
1162+ const pluginName = pluginConfigEntry . name ;
1163+ pluginConfigEntry = configurationOverride ;
1164+ pluginConfigEntry . name = pluginName ;
1165+ }
1166+
11521167 this . enableProxy ( resolvedModule , pluginConfigEntry ) ;
11531168 }
11541169 else {
11551170 this . projectService . logger . info ( `Couldn't find ${ pluginConfigEntry . name } ` ) ;
11561171 }
11571172 }
11581173
1159- /** Starts a new check for diagnostics. Call this if some file has updated that would cause diagnostics to be changed. */
1160- refreshDiagnostics ( ) {
1161- this . projectService . sendProjectsUpdatedInBackgroundEvent ( ) ;
1162- }
1163-
11641174 private enableProxy ( pluginModuleFactory : PluginModuleFactory , configEntry : PluginImport ) {
11651175 try {
11661176 if ( typeof pluginModuleFactory !== "function" ) {
@@ -1186,12 +1196,26 @@ namespace ts.server {
11861196 }
11871197 this . projectService . logger . info ( `Plugin validation succeded` ) ;
11881198 this . languageService = newLS ;
1189- this . plugins . push ( pluginModule ) ;
1199+ this . plugins . push ( { name : configEntry . name , module : pluginModule } ) ;
11901200 }
11911201 catch ( e ) {
11921202 this . projectService . logger . info ( `Plugin activation failed: ${ e } ` ) ;
11931203 }
11941204 }
1205+
1206+ /*@internal */
1207+ onPluginConfigurationChanged ( pluginName : string , configuration : any ) {
1208+ this . plugins . filter ( plugin => plugin . name === pluginName ) . forEach ( plugin => {
1209+ if ( plugin . module . onConfigurationChanged ) {
1210+ plugin . module . onConfigurationChanged ( configuration ) ;
1211+ }
1212+ } ) ;
1213+ }
1214+
1215+ /** Starts a new check for diagnostics. Call this if some file has updated that would cause diagnostics to be changed. */
1216+ refreshDiagnostics ( ) {
1217+ this . projectService . sendProjectsUpdatedInBackgroundEvent ( ) ;
1218+ }
11951219 }
11961220
11971221 /**
@@ -1247,7 +1271,8 @@ namespace ts.server {
12471271 documentRegistry : DocumentRegistry ,
12481272 compilerOptions : CompilerOptions ,
12491273 projectRootPath : NormalizedPath | undefined ,
1250- currentDirectory : string | undefined ) {
1274+ currentDirectory : string | undefined ,
1275+ pluginConfigOverrides : Map < any > | undefined ) {
12511276 super ( InferredProject . newName ( ) ,
12521277 ProjectKind . Inferred ,
12531278 projectService ,
@@ -1263,7 +1288,7 @@ namespace ts.server {
12631288 if ( ! projectRootPath && ! projectService . useSingleInferredProject ) {
12641289 this . canonicalCurrentDirectory = projectService . toCanonicalFileName ( this . currentDirectory ) ;
12651290 }
1266- this . enableGlobalPlugins ( this . getCompilerOptions ( ) ) ;
1291+ this . enableGlobalPlugins ( this . getCompilerOptions ( ) , pluginConfigOverrides ) ;
12671292 }
12681293
12691294 addRoot ( info : ScriptInfo ) {
@@ -1419,12 +1444,8 @@ namespace ts.server {
14191444 return program && program . forEachResolvedProjectReference ( cb ) ;
14201445 }
14211446
1422- enablePlugins ( ) {
1423- this . enablePluginsWithOptions ( this . getCompilerOptions ( ) ) ;
1424- }
1425-
14261447 /*@internal */
1427- enablePluginsWithOptions ( options : CompilerOptions ) {
1448+ enablePluginsWithOptions ( options : CompilerOptions , pluginConfigOverrides : Map < any > | undefined ) {
14281449 const host = this . projectService . host ;
14291450
14301451 if ( ! host . require ) {
@@ -1445,11 +1466,11 @@ namespace ts.server {
14451466 // Enable tsconfig-specified plugins
14461467 if ( options . plugins ) {
14471468 for ( const pluginConfigEntry of options . plugins ) {
1448- this . enablePlugin ( pluginConfigEntry , searchPaths ) ;
1469+ this . enablePlugin ( pluginConfigEntry , searchPaths , pluginConfigOverrides ) ;
14491470 }
14501471 }
14511472
1452- this . enableGlobalPlugins ( options ) ;
1473+ this . enableGlobalPlugins ( options , pluginConfigOverrides ) ;
14531474 }
14541475
14551476 /**
0 commit comments