@@ -7,8 +7,8 @@ import * as Json from 'jsonc-parser';
77import { JSONSchema , JSONSchemaMap , JSONSchemaRef } from '../jsonSchema' ;
88import { URI } from 'vscode-uri' ;
99import * as Strings from '../utils/strings' ;
10- import * as Parser from '../parser/jsonParser' ;
11- import { SchemaRequestService , WorkspaceContextService , PromiseConstructor , MatchingSchema , TextDocument , SchemaConfiguration } from '../jsonLanguageTypes' ;
10+ import { asSchema , getSchemaDraftFromId , JSONDocument , normalizeId } from '../parser/jsonParser' ;
11+ import { SchemaRequestService , WorkspaceContextService , PromiseConstructor , MatchingSchema , TextDocument , SchemaConfiguration , SchemaDraft } from '../jsonLanguageTypes' ;
1212
1313import * as l10n from '@vscode/l10n' ;
1414import { createRegex } from '../utils/glob' ;
@@ -34,7 +34,7 @@ export interface IJSONSchemaService {
3434 /**
3535 * Looks up the appropriate schema for the given URI
3636 */
37- getSchemaForResource ( resource : string , document ?: Parser . JSONDocument ) : PromiseLike < ResolvedSchema | undefined > ;
37+ getSchemaForResource ( resource : string , document ?: JSONDocument ) : PromiseLike < ResolvedSchema | undefined > ;
3838
3939 /**
4040 * Returns all registered schema ids
@@ -193,9 +193,9 @@ export class ResolvedSchema {
193193 public readonly schema : JSONSchema ;
194194 public readonly errors : string [ ] ;
195195 public readonly warnings : string [ ] ;
196- public readonly schemaDraft : string | undefined ;
196+ public readonly schemaDraft : SchemaDraft | undefined ;
197197
198- constructor ( schema : JSONSchema , errors : string [ ] = [ ] , warnings : string [ ] = [ ] , schemaDraft : string | undefined ) {
198+ constructor ( schema : JSONSchema , errors : string [ ] = [ ] , warnings : string [ ] = [ ] , schemaDraft : SchemaDraft | undefined ) {
199199 this . schema = schema ;
200200 this . errors = errors ;
201201 this . warnings = warnings ;
@@ -205,7 +205,7 @@ export class ResolvedSchema {
205205 public getSection ( path : string [ ] ) : JSONSchema | undefined {
206206 const schemaRef = this . getSectionRecursive ( path , this . schema ) ;
207207 if ( schemaRef ) {
208- return Parser . asSchema ( schemaRef ) ;
208+ return asSchema ( schemaRef ) ;
209209 }
210210 return undefined ;
211211 }
@@ -390,9 +390,6 @@ export class JSONSchemaService implements IJSONSchemaService {
390390 const errorMessage = l10n . t ( 'Unable to load schema from \'{0}\'. No schema request service available' , toDisplayString ( url ) ) ;
391391 return this . promise . resolve ( new UnresolvedSchema ( < JSONSchema > { } , [ errorMessage ] ) ) ;
392392 }
393- if ( url . startsWith ( 'http://json-schema.org/' ) ) {
394- url = 'https' + url . substring ( 4 ) ; // always access json-schema.org with https. See https://github.com/microsoft/vscode/issues/195189
395- }
396393 return this . requestService ( url ) . then (
397394 content => {
398395 if ( ! content ) {
@@ -433,8 +430,8 @@ export class JSONSchemaService implements IJSONSchemaService {
433430 const resolveErrors : string [ ] = schemaToResolve . errors . slice ( 0 ) ;
434431 const schema = schemaToResolve . schema ;
435432
436- let schemaDraft = schema . $schema ? normalizeId ( schema . $schema ) : undefined ;
437- if ( schemaDraft === 'http://json-schema.org/draft-03/schema' ) {
433+ const schemaDraft = schema . $schema ? getSchemaDraftFromId ( schema . $schema ) : undefined ;
434+ if ( schemaDraft === SchemaDraft . v3 ) {
438435 return this . promise . resolve ( new ResolvedSchema ( { } , [ l10n . t ( "Draft-03 schemas are not supported." ) ] , [ ] , schemaDraft ) ) ;
439436 }
440437
@@ -634,7 +631,7 @@ export class JSONSchemaService implements IJSONSchemaService {
634631 }
635632 } ;
636633
637- private getSchemaFromProperty ( resource : string , document : Parser . JSONDocument ) : string | undefined {
634+ private getSchemaFromProperty ( resource : string , document : JSONDocument ) : string | undefined {
638635 if ( document . root ?. type === 'object' ) {
639636 for ( const p of document . root . properties ) {
640637 if ( p . keyNode . value === '$schema' && p . valueNode ?. type === 'string' ) {
@@ -666,15 +663,15 @@ export class JSONSchemaService implements IJSONSchemaService {
666663 return schemas ;
667664 }
668665
669- public getSchemaURIsForResource ( resource : string , document ?: Parser . JSONDocument ) : string [ ] {
666+ public getSchemaURIsForResource ( resource : string , document ?: JSONDocument ) : string [ ] {
670667 let schemeId = document && this . getSchemaFromProperty ( resource , document ) ;
671668 if ( schemeId ) {
672669 return [ schemeId ] ;
673670 }
674671 return this . getAssociatedSchemas ( resource ) ;
675672 }
676673
677- public getSchemaForResource ( resource : string , document ?: Parser . JSONDocument ) : PromiseLike < ResolvedSchema | undefined > {
674+ public getSchemaForResource ( resource : string , document ?: JSONDocument ) : PromiseLike < ResolvedSchema | undefined > {
678675 if ( document ) {
679676 // first use $schema if present
680677 let schemeId = this . getSchemaFromProperty ( resource , document ) ;
@@ -704,7 +701,7 @@ export class JSONSchemaService implements IJSONSchemaService {
704701 }
705702 }
706703
707- public getMatchingSchemas ( document : TextDocument , jsonDocument : Parser . JSONDocument , schema ?: JSONSchema ) : PromiseLike < MatchingSchema [ ] > {
704+ public getMatchingSchemas ( document : TextDocument , jsonDocument : JSONDocument , schema ?: JSONSchema ) : PromiseLike < MatchingSchema [ ] > {
708705 if ( schema ) {
709706 const id = schema . id || ( 'schemaservice://untitled/matchingSchemas/' + idCounter ++ ) ;
710707 const handle = this . addSchemaHandle ( id , schema ) ;
@@ -724,16 +721,6 @@ export class JSONSchemaService implements IJSONSchemaService {
724721
725722let idCounter = 0 ;
726723
727- function normalizeId ( id : string ) : string {
728- // remove trailing '#', normalize drive capitalization
729- try {
730- return URI . parse ( id ) . toString ( true ) ;
731- } catch ( e ) {
732- return id ;
733- }
734-
735- }
736-
737724function normalizeResourceForMatching ( resource : string ) : string {
738725 // remove queries and fragments, normalize drive capitalization
739726 try {
0 commit comments