@@ -119,6 +119,7 @@ export function activate(context: ExtensionContext) {
119119 toDispose . push ( schemaResolutionErrorStatusBarItem ) ;
120120
121121 const fileSchemaErrors = new Map < string , string > ( ) ;
122+ let schemaDownloadEnabled = true ;
122123
123124 // Options to control the language client
124125 const clientOptions : LanguageClientOptions = {
@@ -139,7 +140,7 @@ export function activate(context: ExtensionContext) {
139140 didChangeConfiguration : ( ) => client . sendNotification ( DidChangeConfigurationNotification . type , { settings : getSettings ( ) } )
140141 } ,
141142 handleDiagnostics : ( uri : Uri , diagnostics : Diagnostic [ ] , next : HandleDiagnosticsSignature ) => {
142- const schemaErrorIndex = diagnostics . findIndex ( candidate => candidate . code === /* SchemaResolveError */ 0x300 ) ;
143+ const schemaErrorIndex = diagnostics . findIndex ( isSchemaResolveError ) ;
143144
144145 if ( schemaErrorIndex === - 1 ) {
145146 fileSchemaErrors . delete ( uri . toString ( ) ) ;
@@ -149,6 +150,10 @@ export function activate(context: ExtensionContext) {
149150 const schemaResolveDiagnostic = diagnostics [ schemaErrorIndex ] ;
150151 fileSchemaErrors . set ( uri . toString ( ) , schemaResolveDiagnostic . message ) ;
151152
153+ if ( ! schemaDownloadEnabled ) {
154+ diagnostics = diagnostics . filter ( d => ! isSchemaResolveError ( d ) ) ;
155+ }
156+
152157 if ( window . activeTextEditor && window . activeTextEditor . document . uri . toString ( ) === uri . toString ( ) ) {
153158 schemaResolutionErrorStatusBarItem . show ( ) ;
154159 }
@@ -204,20 +209,19 @@ export function activate(context: ExtensionContext) {
204209 toDispose . push ( disposable ) ;
205210 client . onReady ( ) . then ( ( ) => {
206211 const schemaDocuments : { [ uri : string ] : boolean } = { } ;
207- let schemaDownloadEnabled = true ;
208212
209213 // handle content request
210214 client . onRequest ( VSCodeContentRequest . type , ( uriPath : string ) => {
211215 const uri = Uri . parse ( uriPath ) ;
212216 if ( uri . scheme === 'untitled' ) {
213- return Promise . reject ( new Error ( localize ( 'untitled.schema' , 'Unable to load {0}' , uri . toString ( ) ) ) ) ;
217+ return Promise . reject ( new ResponseError ( 3 , localize ( 'untitled.schema' , 'Unable to load {0}' , uri . toString ( ) ) ) ) ;
214218 }
215219 if ( uri . scheme !== 'http' && uri . scheme !== 'https' ) {
216220 return workspace . openTextDocument ( uri ) . then ( doc => {
217221 schemaDocuments [ uri . toString ( ) ] = true ;
218222 return doc . getText ( ) ;
219223 } , error => {
220- return Promise . reject ( error ) ;
224+ return Promise . reject ( new ResponseError ( 2 , error . toString ( ) ) ) ;
221225 } ) ;
222226 } else if ( schemaDownloadEnabled ) {
223227 if ( telemetryReporter && uri . authority === 'schema.management.azure.com' ) {
@@ -239,7 +243,7 @@ export function activate(context: ExtensionContext) {
239243 return Promise . reject ( new ResponseError ( error . status , getErrorStatusDescription ( error . status ) + '\n' + extraInfo ) ) ;
240244 } ) ;
241245 } else {
242- return Promise . reject ( localize ( 'schemaDownloadDisabled' , 'Downloading schemas is disabled through setting \'{0}\'' , SettingIds . enableSchemaDownload ) ) ;
246+ return Promise . reject ( new ResponseError ( 1 , localize ( 'schemaDownloadDisabled' , 'Downloading schemas is disabled through setting \'{0}\'' , SettingIds . enableSchemaDownload ) ) ) ;
243247 }
244248 } ) ;
245249
@@ -280,7 +284,7 @@ export function activate(context: ExtensionContext) {
280284 schemaResolutionErrorStatusBarItem . text = '$(watch)' ;
281285 const activeDocUri = window . activeTextEditor . document . uri . toString ( ) ;
282286 client . sendRequest ( ForceValidateRequest . type , activeDocUri ) . then ( ( diagnostics ) => {
283- const schemaErrorIndex = diagnostics . findIndex ( candidate => candidate . code === /* SchemaResolveError */ 0x300 ) ;
287+ const schemaErrorIndex = diagnostics . findIndex ( isSchemaResolveError ) ;
284288 if ( schemaErrorIndex !== - 1 ) {
285289 // Show schema resolution errors in status bar only; ref: #51032
286290 const schemaResolveDiagnostic = diagnostics [ schemaErrorIndex ] ;
@@ -546,3 +550,7 @@ function updateMarkdownString(h: MarkdownString): MarkdownString {
546550 n . isTrusted = h . isTrusted ;
547551 return n ;
548552}
553+
554+ function isSchemaResolveError ( d : Diagnostic ) {
555+ return d . code === /* SchemaResolveError */ 0x300 ;
556+ }
0 commit comments