@@ -19,6 +19,7 @@ export const updateConfigFileDiagnostics = (
1919
2020 checkSchemaCompatibility ( documentNode , devProxyInstall , diagnostics ) ;
2121 checkPlugins ( pluginsNode , diagnostics , documentNode ) ;
22+ checkConfigSection ( documentNode , diagnostics ) ;
2223
2324 collection . set ( document . uri , diagnostics ) ;
2425} ;
@@ -41,6 +42,40 @@ export const updateFileDiagnostics = (
4142 collection . set ( document . uri , diagnostics ) ;
4243} ;
4344
45+ const checkConfigSection = ( documentNode : parse . ObjectNode , diagnostics : vscode . Diagnostic [ ] ) => {
46+ const objects = documentNode . children . filter ( ( node ) => node . type === 'Property' && ( node as parse . PropertyNode ) . value . type === 'Object' ) ;
47+
48+ objects . forEach ( ( object ) => {
49+ const objectNode = object as parse . PropertyNode ;
50+ const objectName = objectNode . key . value as string ;
51+ const pluginNodes = getPluginsNode ( documentNode ) ;
52+
53+ if ( pluginNodes && pluginNodes . value . type === 'Array' ) {
54+ const plugins = ( pluginNodes . value as parse . ArrayNode ) . children as parse . ObjectNode [ ] ;
55+ const matchFound = plugins . some ( ( plugin ) => {
56+ const configSectionNode = getASTNode (
57+ plugin . children ,
58+ 'Identifier' ,
59+ 'configSection'
60+ ) ;
61+ return configSectionNode && ( configSectionNode . value as parse . LiteralNode ) . value === objectName ;
62+ } ) ;
63+
64+ if ( matchFound ) {
65+ return ;
66+ }
67+ }
68+
69+ const diagnostic = new vscode . Diagnostic (
70+ getRangeFromASTNode ( objectNode ) ,
71+ `Config section '${ objectName } ' does not correspond to any plugin. Remove it or add a plugin with a matching configSection.` ,
72+ vscode . DiagnosticSeverity . Warning
73+ ) ;
74+ diagnostic . code = 'invalidConfigSection' ;
75+ diagnostics . push ( diagnostic ) ;
76+ } ) ;
77+ } ;
78+
4479const checkSchemaCompatibility = ( documentNode : parse . ObjectNode , devProxyInstall : DevProxyInstall , diagnostics : vscode . Diagnostic [ ] ) => {
4580 const schemaNode = getASTNode ( documentNode . children , 'Identifier' , '$schema' ) ;
4681 if ( schemaNode ) {
0 commit comments