@@ -17,10 +17,11 @@ import {
1717 NotificationType ,
1818 RequestType ,
1919 RevealOutputChannelOn ,
20- } from 'vscode-languageclient' ;
20+ } from 'vscode-languageclient/node ' ;
2121import { CUSTOM_SCHEMA_REQUEST , CUSTOM_CONTENT_REQUEST , SchemaExtensionAPI } from './schema-extension-api' ;
2222import { joinPath } from './paths' ;
23- import { xhr , configure as configureHttpRequests , getErrorStatusDescription , XHRResponse } from 'request-light' ;
23+ import { getJsonSchemaContent , JSONSchemaDocumentContentProvider } from './json-schema-content-provider' ;
24+ import { JSONSchemaCache } from './json-schema-cache' ;
2425
2526export interface ISchemaAssociations {
2627 [ pattern : string ] : string [ ] ;
@@ -34,27 +35,27 @@ export interface ISchemaAssociation {
3435// eslint-disable-next-line @typescript-eslint/no-namespace
3536namespace SchemaAssociationNotification {
3637 // eslint-disable-next-line @typescript-eslint/no-explicit-any
37- export const type : NotificationType < ISchemaAssociations | ISchemaAssociation [ ] , any > = new NotificationType (
38+ export const type : NotificationType < ISchemaAssociations | ISchemaAssociation [ ] > = new NotificationType (
3839 'json/schemaAssociations'
3940 ) ;
4041}
4142
4243// eslint-disable-next-line @typescript-eslint/no-namespace
4344namespace VSCodeContentRequestRegistration {
4445 // eslint-disable-next-line @typescript-eslint/ban-types
45- export const type : NotificationType < { } , { } > = new NotificationType ( 'yaml/registerVSCodeContentRequest ' ) ;
46+ export const type : NotificationType < { } > = new NotificationType ( 'yaml/registerContentRequest ' ) ;
4647}
4748
4849// eslint-disable-next-line @typescript-eslint/no-namespace
4950namespace VSCodeContentRequest {
5051 // eslint-disable-next-line @typescript-eslint/no-explicit-any
51- export const type : RequestType < string , string , any , any > = new RequestType ( 'vscode/content' ) ;
52+ export const type : RequestType < string , string , any > = new RequestType ( 'vscode/content' ) ;
5253}
5354
5455// eslint-disable-next-line @typescript-eslint/no-namespace
5556namespace DynamicCustomSchemaRequestRegistration {
5657 // eslint-disable-next-line @typescript-eslint/ban-types
57- export const type : NotificationType < { } , { } > = new NotificationType ( 'yaml/registerCustomSchemaRequest' ) ;
58+ export const type : NotificationType < { } > = new NotificationType ( 'yaml/registerCustomSchemaRequest' ) ;
5859}
5960
6061let client : LanguageClient ;
@@ -88,6 +89,8 @@ export function activate(context: ExtensionContext): SchemaExtensionAPI {
8889 revealOutputChannelOn : RevealOutputChannelOn . Never ,
8990 } ;
9091
92+ const schemaCache = new JSONSchemaCache ( context . globalStoragePath , context . globalState ) ;
93+
9194 // Create the language client and start it
9295 client = new LanguageClient ( 'yaml' , 'YAML Support' , serverOptions , clientOptions ) ;
9396 const disposable = client . start ( ) ;
@@ -97,6 +100,9 @@ export function activate(context: ExtensionContext): SchemaExtensionAPI {
97100 // Push the disposable to the context's subscriptions so that the
98101 // client can be deactivated on extension deactivation
99102 context . subscriptions . push ( disposable ) ;
103+ context . subscriptions . push (
104+ workspace . registerTextDocumentContentProvider ( 'json-schema' , new JSONSchemaDocumentContentProvider ( schemaCache ) )
105+ ) ;
100106
101107 client . onReady ( ) . then ( ( ) => {
102108 // Send a notification to the server with any YAML schema associations in all extensions
@@ -118,18 +124,7 @@ export function activate(context: ExtensionContext): SchemaExtensionAPI {
118124 return schemaExtensionAPI . requestCustomSchemaContent ( uri ) ;
119125 } ) ;
120126 client . onRequest ( VSCodeContentRequest . type , ( uri : string ) => {
121- const httpSettings = workspace . getConfiguration ( 'http' ) ;
122- configureHttpRequests ( httpSettings . http && httpSettings . http . proxy , httpSettings . http && httpSettings . http . proxyStrictSSL ) ;
123-
124- const headers = { 'Accept-Encoding' : 'gzip, deflate' } ;
125- return xhr ( { url : uri , followRedirects : 5 , headers } ) . then (
126- ( response ) => {
127- return response . responseText ;
128- } ,
129- ( error : XHRResponse ) => {
130- return Promise . reject ( error . responseText || getErrorStatusDescription ( error . status ) || error . toString ( ) ) ;
131- }
132- ) ;
127+ return getJsonSchemaContent ( uri , schemaCache ) ;
133128 } ) ;
134129 } ) ;
135130
0 commit comments