99import * as path from 'path' ;
1010
1111import { workspace , ExtensionContext , extensions } from 'vscode' ;
12- import { LanguageClient , LanguageClientOptions , ServerOptions , TransportKind , NotificationType } from 'vscode-languageclient' ;
12+ import {
13+ LanguageClient ,
14+ LanguageClientOptions ,
15+ ServerOptions ,
16+ TransportKind ,
17+ NotificationType ,
18+ RequestType ,
19+ } from 'vscode-languageclient' ;
1320import { CUSTOM_SCHEMA_REQUEST , CUSTOM_CONTENT_REQUEST , SchemaExtensionAPI } from './schema-extension-api' ;
1421import { joinPath } from './paths' ;
22+ import { xhr , configure as configureHttpRequests , getErrorStatusDescription , XHRResponse } from 'request-light' ;
1523
1624export interface ISchemaAssociations {
1725 [ pattern : string ] : string [ ] ;
@@ -30,6 +38,18 @@ namespace SchemaAssociationNotification {
3038 ) ;
3139}
3240
41+ // eslint-disable-next-line @typescript-eslint/no-namespace
42+ namespace VSCodeContentRequestRegistration {
43+ // eslint-disable-next-line @typescript-eslint/ban-types
44+ export const type : NotificationType < { } , { } > = new NotificationType ( 'yaml/registerVSCodeContentRequest' ) ;
45+ }
46+
47+ // eslint-disable-next-line @typescript-eslint/no-namespace
48+ namespace VSCodeContentRequest {
49+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
50+ export const type : RequestType < string , string , any , any > = new RequestType ( 'vscode/content' ) ;
51+ }
52+
3353// eslint-disable-next-line @typescript-eslint/no-namespace
3454namespace DynamicCustomSchemaRequestRegistration {
3555 // eslint-disable-next-line @typescript-eslint/ban-types
@@ -86,13 +106,29 @@ export function activate(context: ExtensionContext): SchemaExtensionAPI {
86106 } ) ;
87107 // Tell the server that the client is ready to provide custom schema content
88108 client . sendNotification ( DynamicCustomSchemaRequestRegistration . type ) ;
109+ // Tell the server that the client supports schema requests sent directly to it
110+ client . sendNotification ( VSCodeContentRequestRegistration . type ) ;
89111 // If the server asks for custom schema content, get it and send it back
90112 client . onRequest ( CUSTOM_SCHEMA_REQUEST , ( resource : string ) => {
91113 return schemaExtensionAPI . requestCustomSchema ( resource ) ;
92114 } ) ;
93115 client . onRequest ( CUSTOM_CONTENT_REQUEST , ( uri : string ) => {
94116 return schemaExtensionAPI . requestCustomSchemaContent ( uri ) ;
95117 } ) ;
118+ client . onRequest ( VSCodeContentRequest . type , ( uri : string ) => {
119+ const httpSettings = workspace . getConfiguration ( 'http' ) ;
120+ configureHttpRequests ( httpSettings . http && httpSettings . http . proxy , httpSettings . http && httpSettings . http . proxyStrictSSL ) ;
121+
122+ const headers = { 'Accept-Encoding' : 'gzip, deflate' } ;
123+ return xhr ( { url : uri , followRedirects : 5 , headers } ) . then (
124+ ( response ) => {
125+ return response . responseText ;
126+ } ,
127+ ( error : XHRResponse ) => {
128+ return Promise . reject ( error . responseText || getErrorStatusDescription ( error . status ) || error . toString ( ) ) ;
129+ }
130+ ) ;
131+ } ) ;
96132 } ) ;
97133
98134 return schemaExtensionAPI ;
0 commit comments