@@ -4,7 +4,7 @@ import { pluginSnippets } from "./constants";
4
4
import { getASTNode , getRangeFromASTNode } from "./helpers" ;
5
5
import { DevProxyInstall } from './types' ;
6
6
7
- export const updateDiagnostics = (
7
+ export const updateConfigDiagnostics = (
8
8
context : vscode . ExtensionContext ,
9
9
document : vscode . TextDocument ,
10
10
collection : vscode . DiagnosticCollection ,
@@ -17,20 +17,7 @@ export const updateDiagnostics = (
17
17
const documentNode = parse ( document . getText ( ) ) as parse . ObjectNode ;
18
18
19
19
// check if schema version is compatible
20
- const schemaNode = getASTNode ( documentNode . children , 'Identifier' , '$schema' ) ;
21
- if ( schemaNode ) {
22
- const schemaValue = ( schemaNode . value as parse . LiteralNode ) . value as string ;
23
- const devProxyVersion = devProxyInstall . isBeta ? devProxyInstall . version . split ( '-' ) [ 0 ] : devProxyInstall . version ;
24
- if ( ! schemaValue . includes ( `${ devProxyVersion } ` ) ) {
25
- const diagnostic = new vscode . Diagnostic (
26
- getRangeFromASTNode ( schemaNode ) ,
27
- `Schema version is not compatible with the installed version of Dev Proxy. Expected v${ devProxyVersion } ` ,
28
- vscode . DiagnosticSeverity . Warning
29
- ) ;
30
- diagnostic . code = 'invalidSchema' ;
31
- diagnostics . push ( diagnostic ) ;
32
- }
33
- }
20
+ checkSchemaCompatibility ( documentNode , devProxyInstall , diagnostics ) ;
34
21
35
22
// check validity of plugins
36
23
const pluginsNode = getASTNode (
@@ -163,4 +150,40 @@ export const updateDiagnostics = (
163
150
}
164
151
165
152
collection . set ( document . uri , diagnostics ) ;
166
- } ;
153
+ } ;
154
+
155
+ export const updateDiagnostics = (
156
+ context : vscode . ExtensionContext ,
157
+ document : vscode . TextDocument ,
158
+ collection : vscode . DiagnosticCollection ,
159
+ ) : void => {
160
+ const devProxyInstall = context . globalState . get < DevProxyInstall > ( 'devProxyInstall' ) ;
161
+ if ( ! devProxyInstall ) {
162
+ return ;
163
+ }
164
+
165
+ const diagnostics : vscode . Diagnostic [ ] = [ ] ;
166
+ const documentNode = parse ( document . getText ( ) ) as parse . ObjectNode ;
167
+
168
+ // check if schema version is compatible
169
+ checkSchemaCompatibility ( documentNode , devProxyInstall , diagnostics ) ;
170
+
171
+ collection . set ( document . uri , diagnostics ) ;
172
+ } ;
173
+
174
+ export const checkSchemaCompatibility = ( documentNode : parse . ObjectNode , devProxyInstall : DevProxyInstall , diagnostics : vscode . Diagnostic [ ] ) => {
175
+ const schemaNode = getASTNode ( documentNode . children , 'Identifier' , '$schema' ) ;
176
+ if ( schemaNode ) {
177
+ const schemaValue = ( schemaNode . value as parse . LiteralNode ) . value as string ;
178
+ const devProxyVersion = devProxyInstall . isBeta ? devProxyInstall . version . split ( '-' ) [ 0 ] : devProxyInstall . version ;
179
+ if ( ! schemaValue . includes ( `${ devProxyVersion } ` ) ) {
180
+ const diagnostic = new vscode . Diagnostic (
181
+ getRangeFromASTNode ( schemaNode ) ,
182
+ `Schema version is not compatible with the installed version of Dev Proxy. Expected v${ devProxyVersion } ` ,
183
+ vscode . DiagnosticSeverity . Warning
184
+ ) ;
185
+ diagnostic . code = 'invalidSchema' ;
186
+ diagnostics . push ( diagnostic ) ;
187
+ }
188
+ }
189
+ } ;
0 commit comments