@@ -4,7 +4,7 @@ import { pluginSnippets } from "./constants";
44import { getASTNode , getRangeFromASTNode } from "./helpers" ;
55import { DevProxyInstall } from './types' ;
66
7- export const updateDiagnostics = (
7+ export const updateConfigDiagnostics = (
88 context : vscode . ExtensionContext ,
99 document : vscode . TextDocument ,
1010 collection : vscode . DiagnosticCollection ,
@@ -17,20 +17,7 @@ export const updateDiagnostics = (
1717 const documentNode = parse ( document . getText ( ) ) as parse . ObjectNode ;
1818
1919 // 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 ) ;
3421
3522 // check validity of plugins
3623 const pluginsNode = getASTNode (
@@ -163,4 +150,40 @@ export const updateDiagnostics = (
163150 }
164151
165152 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