@@ -590,6 +590,8 @@ describe('JSON Schema', () => {
590
590
// eslint-disable-next-line @typescript-eslint/no-var-requires
591
591
const schemaModelineSample = path . join ( __dirname , './fixtures/sample-modeline.json' ) ;
592
592
// eslint-disable-next-line @typescript-eslint/no-var-requires
593
+ const schemaDollarSample = path . join ( __dirname , './fixtures/sample-dollar-schema.json' ) ;
594
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
593
595
const schemaDefaultSnippetSample = require ( path . join ( __dirname , './fixtures/defaultSnippets-const-if-else.json' ) ) ;
594
596
const languageSettingsSetup = new ServiceSetup ( ) . withCompletion ( ) ;
595
597
@@ -615,12 +617,42 @@ describe('JSON Schema', () => {
615
617
} ) ;
616
618
languageService . configure ( languageSettingsSetup . languageSettings ) ;
617
619
languageService . registerCustomSchemaProvider ( ( uri : string ) => Promise . resolve ( uri ) ) ;
618
- const testTextDocument = setupTextDocument ( `# yaml-language-server: $schema=${ schemaModelineSample } \n\n` ) ;
620
+ const testTextDocument = setupTextDocument (
621
+ `# yaml-language-server: $schema=${ schemaModelineSample } \n$schema: ${ schemaDollarSample } \n\n`
622
+ ) ;
619
623
const result = await languageService . doComplete ( testTextDocument , Position . create ( 1 , 0 ) , false ) ;
620
624
assert . strictEqual ( result . items . length , 1 ) ;
621
625
assert . strictEqual ( result . items [ 0 ] . label , 'modeline' ) ;
622
626
} ) ;
623
627
628
+ it ( 'Explicit $schema takes precedence over all other lower priority schemas' , async ( ) => {
629
+ languageSettingsSetup
630
+ . withSchemaFileMatch ( {
631
+ fileMatch : [ 'test.yaml' ] ,
632
+ uri : TEST_URI ,
633
+ priority : SchemaPriority . SchemaStore ,
634
+ schema : schemaStoreSample ,
635
+ } )
636
+ . withSchemaFileMatch ( {
637
+ fileMatch : [ 'test.yaml' ] ,
638
+ uri : TEST_URI ,
639
+ priority : SchemaPriority . SchemaAssociation ,
640
+ schema : schemaAssociationSample ,
641
+ } )
642
+ . withSchemaFileMatch ( {
643
+ fileMatch : [ 'test.yaml' ] ,
644
+ uri : TEST_URI ,
645
+ priority : SchemaPriority . Settings ,
646
+ schema : schemaSettingsSample ,
647
+ } ) ;
648
+ languageService . configure ( languageSettingsSetup . languageSettings ) ;
649
+ languageService . registerCustomSchemaProvider ( ( uri : string ) => Promise . resolve ( uri ) ) ;
650
+ const testTextDocument = setupTextDocument ( `$schema: ${ schemaDollarSample } \n\n` ) ;
651
+ const result = await languageService . doComplete ( testTextDocument , Position . create ( 1 , 0 ) , false ) ;
652
+ assert . strictEqual ( result . items . length , 1 ) ;
653
+ assert . strictEqual ( result . items [ 0 ] . label , 'dollar-schema' ) ;
654
+ } ) ;
655
+
624
656
it ( 'Manually setting schema takes precendence over all other lower priority schemas' , async ( ) => {
625
657
languageSettingsSetup
626
658
. withSchemaFileMatch ( {
0 commit comments