@@ -19,6 +19,7 @@ export const updateConfigFileDiagnostics = (
19
19
20
20
checkSchemaCompatibility ( documentNode , devProxyInstall , diagnostics ) ;
21
21
checkPlugins ( pluginsNode , diagnostics , documentNode ) ;
22
+ checkConfigSection ( documentNode , diagnostics ) ;
22
23
23
24
collection . set ( document . uri , diagnostics ) ;
24
25
} ;
@@ -41,6 +42,40 @@ export const updateFileDiagnostics = (
41
42
collection . set ( document . uri , diagnostics ) ;
42
43
} ;
43
44
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
+
44
79
const checkSchemaCompatibility = ( documentNode : parse . ObjectNode , devProxyInstall : DevProxyInstall , diagnostics : vscode . Diagnostic [ ] ) => {
45
80
const schemaNode = getASTNode ( documentNode . children , 'Identifier' , '$schema' ) ;
46
81
if ( schemaNode ) {
0 commit comments