@@ -18,6 +18,7 @@ import { AWS_SCHEME } from './constants'
18
18
import fs from '../shared/fs/fs'
19
19
import { normalizeVSCodeUri } from './utilities/vsCodeUtils'
20
20
import { telemetry } from './telemetry/telemetry'
21
+ import { JsonSchemasKey } from './globalState'
21
22
22
23
// Note: this file is currently 12+ MB. When requesting it, specify compression/gzip.
23
24
export const samAndCfnSchemaUrl =
@@ -150,7 +151,6 @@ export async function getDefaultSchemas(): Promise<Schemas | undefined> {
150
151
151
152
// Sam schema is a superset of Cfn schema, so we can use it for both
152
153
const samAndCfnSchemaDestinationUri = GlobalStorage . samAndCfnSchemaDestinationUri ( )
153
- const samAndCfnCacheKey = 'samAndCfnSchemaVersion'
154
154
155
155
const schemas : Schemas = { }
156
156
@@ -159,8 +159,7 @@ export async function getDefaultSchemas(): Promise<Schemas | undefined> {
159
159
destination : samAndCfnSchemaDestinationUri ,
160
160
eTag : undefined ,
161
161
url : samAndCfnSchemaUrl ,
162
- cacheKey : samAndCfnCacheKey ,
163
- extensionContext : globals . context ,
162
+ cacheKey : 'samAndCfnSchemaVersion' ,
164
163
title : schemaPrefix + 'cloudformation.schema.json' ,
165
164
} )
166
165
schemas [ 'cfn' ] = samAndCfnSchemaDestinationUri
@@ -173,8 +172,7 @@ export async function getDefaultSchemas(): Promise<Schemas | undefined> {
173
172
destination : samAndCfnSchemaDestinationUri ,
174
173
eTag : undefined ,
175
174
url : samAndCfnSchemaUrl ,
176
- cacheKey : samAndCfnCacheKey ,
177
- extensionContext : globals . context ,
175
+ cacheKey : 'samAndCfnSchemaVersion' ,
178
176
title : schemaPrefix + 'sam.schema.json' ,
179
177
} )
180
178
schemas [ 'sam' ] = samAndCfnSchemaDestinationUri
@@ -188,7 +186,6 @@ export async function getDefaultSchemas(): Promise<Schemas | undefined> {
188
186
version : devfileSchemaVersion ,
189
187
url : `https://raw.githubusercontent.com/devfile/api/${ devfileSchemaVersion } /schemas/latest/devfile.json` ,
190
188
cacheKey : 'devfileSchemaVersion' ,
191
- extensionContext : globals . context ,
192
189
title : schemaPrefix + 'devfile.schema.json' ,
193
190
} )
194
191
schemas [ 'devfile' ] = devfileSchemaUri
@@ -206,17 +203,15 @@ export async function getDefaultSchemas(): Promise<Schemas | undefined> {
206
203
* @param params.version Remote version
207
204
* @param params.url Url to fetch from
208
205
* @param params.cacheKey Cache key to check version against
209
- * @param params.extensionContext VSCode extension context
210
206
*/
211
207
export async function updateSchemaFromRemote ( params : {
212
208
destination : vscode . Uri
213
209
version ?: string
214
210
url : string
215
- cacheKey : string
216
- extensionContext : vscode . ExtensionContext
211
+ cacheKey : JsonSchemasKey
217
212
title : string
218
213
} ) : Promise < void > {
219
- const cachedVersion = params . extensionContext . globalState . get < string > ( params . cacheKey )
214
+ const cachedVersion = globals . globalState . get < string > ( params . cacheKey )
220
215
const outdated = params . version && params . version !== cachedVersion
221
216
222
217
// Check that the cached file actually can be fetched. Else we might
@@ -257,17 +252,15 @@ export async function updateSchemaFromRemote(params: {
257
252
* @param params.eTag E-Tag to send with fetch request. If this matches the url's it means we can use our cache.
258
253
* @param params.url Url to fetch from
259
254
* @param params.cacheKey Cache key to check version against
260
- * @param params.extensionContext VSCode extension context
261
255
*/
262
256
export async function updateSchemaFromRemoteETag ( params : {
263
257
destination : vscode . Uri
264
258
eTag ?: string
265
259
url : string
266
- cacheKey : string
267
- extensionContext : vscode . ExtensionContext
260
+ cacheKey : JsonSchemasKey
268
261
title : string
269
262
} ) : Promise < void > {
270
- const cachedETag = params . extensionContext . globalState . get < string > ( params . cacheKey )
263
+ const cachedETag = globals . globalState . get < string > ( params . cacheKey )
271
264
272
265
// Check that the cached file actually can be fetched. Else we might
273
266
// never update the cache.
@@ -320,18 +313,15 @@ async function doCacheContent(
320
313
destination : vscode . Uri
321
314
version ?: string
322
315
url : string
323
- cacheKey : string
324
- extensionContext : vscode . ExtensionContext
316
+ cacheKey : JsonSchemasKey
325
317
title : string
326
318
}
327
319
) : Promise < void > {
328
320
const parsedFile = { ...JSON . parse ( content ) , title : params . title }
329
321
const dir = vscode . Uri . joinPath ( params . destination , '..' )
330
322
await fs . mkdir ( dir )
331
323
await fs . writeFile ( params . destination . fsPath , JSON . stringify ( parsedFile ) )
332
- await params . extensionContext . globalState . update ( params . cacheKey , params . version ) . then ( undefined , ( err ) => {
333
- getLogger ( ) . warn ( `schemas: failed to update cache key for "${ params . title } ": ${ err ?. message } ` )
334
- } )
324
+ await globals . globalState . update ( params . cacheKey , params . version )
335
325
}
336
326
337
327
/**
0 commit comments