@@ -13,7 +13,6 @@ import { xhr, XHRResponse, configure as configureHttpRequests, getErrorStatusDes
1313import * as fs from 'fs' ;
1414import URI from 'vscode-uri' ;
1515import * as URL from 'url' ;
16- import { startsWith } from './utils/strings' ;
1716import { formatError , runSafe , runSafeAsync } from './utils/runner' ;
1817import { JSONDocument , JSONSchema , getLanguageService , DocumentLanguageSettings , SchemaConfiguration } from 'vscode-json-languageservice' ;
1918import { getLanguageModelCache } from './languageModelCache' ;
@@ -57,46 +56,51 @@ const workspaceContext = {
5756 return URL . resolve ( resource , relativePath ) ;
5857 }
5958} ;
60-
61- const schemaRequestService = ( uri : string ) : Thenable < string > => {
62- if ( startsWith ( uri , 'file://' ) ) {
63- const fsPath = URI . parse ( uri ) . fsPath ;
64- return new Promise < string > ( ( c , e ) => {
65- fs . readFile ( fsPath , 'UTF-8' , ( err , result ) => {
66- err ? e ( err . message || err . toString ( ) ) : c ( result . toString ( ) ) ;
67- } ) ;
68- } ) ;
69- } else if ( startsWith ( uri , 'vscode://' ) ) {
59+ function getSchemaRequestService ( handledSchemas : { [ schema : string ] : boolean } ) {
60+
61+ return ( uri : string ) : Thenable < string > => {
62+ const protocol = uri . substr ( 0 , uri . indexOf ( ':' ) ) ;
63+
64+ if ( ! handledSchemas || handledSchemas [ protocol ] ) {
65+ if ( protocol === 'file' ) {
66+ const fsPath = URI . parse ( uri ) . fsPath ;
67+ return new Promise < string > ( ( c , e ) => {
68+ fs . readFile ( fsPath , 'UTF-8' , ( err , result ) => {
69+ err ? e ( err . message || err . toString ( ) ) : c ( result . toString ( ) ) ;
70+ } ) ;
71+ } ) ;
72+ } else if ( protocol === 'http' || protocol === 'https' ) {
73+ if ( uri . indexOf ( '//schema.management.azure.com/' ) !== - 1 ) {
74+ /* __GDPR__
75+ "json.schema" : {
76+ "schemaURL" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
77+ }
78+ */
79+ connection . telemetry . logEvent ( {
80+ key : 'json.schema' ,
81+ value : {
82+ schemaURL : uri
83+ }
84+ } ) ;
85+ }
86+ const headers = { 'Accept-Encoding' : 'gzip, deflate' } ;
87+ return xhr ( { url : uri , followRedirects : 5 , headers } ) . then ( response => {
88+ return response . responseText ;
89+ } , ( error : XHRResponse ) => {
90+ return Promise . reject ( error . responseText || getErrorStatusDescription ( error . status ) || error . toString ( ) ) ;
91+ } ) ;
92+ }
93+ }
7094 return connection . sendRequest ( VSCodeContentRequest . type , uri ) . then ( responseText => {
7195 return responseText ;
7296 } , error => {
7397 return Promise . reject ( error . message ) ;
7498 } ) ;
75- }
76- if ( uri . indexOf ( '//schema.management.azure.com/' ) !== - 1 ) {
77- /* __GDPR__
78- "json.schema" : {
79- "schemaURL" : { "classification": "SystemMetaData", "purpose": "FeatureInsight" }
80- }
81- */
82- connection . telemetry . logEvent ( {
83- key : 'json.schema' ,
84- value : {
85- schemaURL : uri
86- }
87- } ) ;
88- }
89- const headers = { 'Accept-Encoding' : 'gzip, deflate' } ;
90- return xhr ( { url : uri , followRedirects : 5 , headers } ) . then ( response => {
91- return response . responseText ;
92- } , ( error : XHRResponse ) => {
93- return Promise . reject ( error . responseText || getErrorStatusDescription ( error . status ) || error . toString ( ) ) ;
94- } ) ;
95- } ;
99+ } ;
100+ }
96101
97102// create the JSON language service
98103let languageService = getLanguageService ( {
99- schemaRequestService,
100104 workspaceContext,
101105 contributions : [ ] ,
102106} ) ;
@@ -117,8 +121,10 @@ let hierarchicalDocumentSymbolSupport = false;
117121// in the passed params the rootPath of the workspace plus the client capabilities.
118122connection . onInitialize ( ( params : InitializeParams ) : InitializeResult => {
119123
124+ const handledProtocols = params . initializationOptions && params . initializationOptions [ 'handledSchemaProtocols' ] ;
125+
120126 languageService = getLanguageService ( {
121- schemaRequestService,
127+ schemaRequestService : getSchemaRequestService ( handledProtocols ) ,
122128 workspaceContext,
123129 contributions : [ ] ,
124130 clientCapabilities : params . capabilities
0 commit comments