@@ -590,6 +590,8 @@ describe('JSON Schema', () => {
590590 // eslint-disable-next-line @typescript-eslint/no-var-requires
591591 const schemaModelineSample = path . join ( __dirname , './fixtures/sample-modeline.json' ) ;
592592 // 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
593595 const schemaDefaultSnippetSample = require ( path . join ( __dirname , './fixtures/defaultSnippets-const-if-else.json' ) ) ;
594596 const languageSettingsSetup = new ServiceSetup ( ) . withCompletion ( ) ;
595597
@@ -615,12 +617,42 @@ describe('JSON Schema', () => {
615617 } ) ;
616618 languageService . configure ( languageSettingsSetup . languageSettings ) ;
617619 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+ ) ;
619623 const result = await languageService . doComplete ( testTextDocument , Position . create ( 1 , 0 ) , false ) ;
620624 assert . strictEqual ( result . items . length , 1 ) ;
621625 assert . strictEqual ( result . items [ 0 ] . label , 'modeline' ) ;
622626 } ) ;
623627
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+
624656 it ( 'Manually setting schema takes precendence over all other lower priority schemas' , async ( ) => {
625657 languageSettingsSetup
626658 . withSchemaFileMatch ( {
0 commit comments