@@ -29,6 +29,7 @@ import { SchemaVersions } from '../yamlTypes';
29
29
30
30
import Ajv , { DefinedError } from 'ajv' ;
31
31
import { getSchemaTitle } from '../utils/schemaUtils' ;
32
+ import { getDollarSchema } from './dollarUitls' ;
32
33
33
34
const localize = nls . loadMessageBundle ( ) ;
34
35
@@ -343,33 +344,46 @@ export class YAMLSchemaService extends JSONSchemaService {
343
344
}
344
345
345
346
public getSchemaForResource ( resource : string , doc : JSONDocument ) : Promise < ResolvedSchema > {
347
+ const normalizeSchemaRef = ( schemaRef : string ) : string | undefined => {
348
+ if ( ! schemaRef . startsWith ( 'file:' ) && ! schemaRef . startsWith ( 'http' ) ) {
349
+ // If path contains a fragment and it is left intact, "#" will be
350
+ // considered part of the filename and converted to "%23" by
351
+ // path.resolve() -> take it out and add back after path.resolve
352
+ let appendix = '' ;
353
+ if ( schemaRef . indexOf ( '#' ) > 0 ) {
354
+ const segments = schemaRef . split ( '#' , 2 ) ;
355
+ schemaRef = segments [ 0 ] ;
356
+ appendix = segments [ 1 ] ;
357
+ }
358
+ if ( ! path . isAbsolute ( schemaRef ) ) {
359
+ const resUri = URI . parse ( resource ) ;
360
+ schemaRef = URI . file ( path . resolve ( path . parse ( resUri . fsPath ) . dir , schemaRef ) ) . toString ( ) ;
361
+ } else {
362
+ schemaRef = URI . file ( schemaRef ) . toString ( ) ;
363
+ }
364
+ if ( appendix . length > 0 ) {
365
+ schemaRef += '#' + appendix ;
366
+ }
367
+ }
368
+ return schemaRef ;
369
+ } ;
370
+
346
371
const resolveModelineSchema = ( ) : string | undefined => {
347
372
let schemaFromModeline = getSchemaFromModeline ( doc ) ;
348
373
if ( schemaFromModeline !== undefined ) {
349
- if ( ! schemaFromModeline . startsWith ( 'file:' ) && ! schemaFromModeline . startsWith ( 'http' ) ) {
350
- // If path contains a fragment and it is left intact, "#" will be
351
- // considered part of the filename and converted to "%23" by
352
- // path.resolve() -> take it out and add back after path.resolve
353
- let appendix = '' ;
354
- if ( schemaFromModeline . indexOf ( '#' ) > 0 ) {
355
- const segments = schemaFromModeline . split ( '#' , 2 ) ;
356
- schemaFromModeline = segments [ 0 ] ;
357
- appendix = segments [ 1 ] ;
358
- }
359
- if ( ! path . isAbsolute ( schemaFromModeline ) ) {
360
- const resUri = URI . parse ( resource ) ;
361
- schemaFromModeline = URI . file ( path . resolve ( path . parse ( resUri . fsPath ) . dir , schemaFromModeline ) ) . toString ( ) ;
362
- } else {
363
- schemaFromModeline = URI . file ( schemaFromModeline ) . toString ( ) ;
364
- }
365
- if ( appendix . length > 0 ) {
366
- schemaFromModeline += '#' + appendix ;
367
- }
368
- }
374
+ schemaFromModeline = normalizeSchemaRef ( schemaFromModeline ) ;
369
375
return schemaFromModeline ;
370
376
}
371
377
} ;
372
378
379
+ const resolveDollarSchema = ( ) : string | undefined => {
380
+ let dollarSchema = getDollarSchema ( doc ) ;
381
+ if ( dollarSchema !== undefined ) {
382
+ dollarSchema = normalizeSchemaRef ( dollarSchema ) ;
383
+ return dollarSchema ;
384
+ }
385
+ } ;
386
+
373
387
const resolveSchemaForResource = ( schemas : string [ ] ) : Promise < ResolvedSchema > => {
374
388
const schemaHandle = super . createCombinedSchema ( resource , schemas ) ;
375
389
return schemaHandle . getResolvedSchema ( ) . then ( ( schema ) => {
@@ -416,6 +430,10 @@ export class YAMLSchemaService extends JSONSchemaService {
416
430
if ( modelineSchema ) {
417
431
return resolveSchemaForResource ( [ modelineSchema ] ) ;
418
432
}
433
+ const dollarSchema = resolveDollarSchema ( ) ;
434
+ if ( dollarSchema ) {
435
+ return resolveSchemaForResource ( [ dollarSchema ] ) ;
436
+ }
419
437
if ( this . customSchemaProvider ) {
420
438
return this . customSchemaProvider ( resource )
421
439
. then ( ( schemaUri ) => {
0 commit comments