@@ -1588,6 +1588,52 @@ describe('Auto Completion Tests', () => {
15881588 } ) ;
15891589 assert . strictEqual ( result . items . length , 3 , `Expecting 3 items in completion but found ${ result . items . length } ` ) ;
15901590 } ) ;
1591+
1592+ const inlineSchemaLabel = 'Inline schema' ;
1593+
1594+ it ( 'should provide modeline completion on first character with no schema associated and no modeline yet' , async ( ) => {
1595+ const testTextDocument = setupSchemaIDTextDocument ( '' , path . join ( __dirname , 'test.yaml' ) ) ;
1596+ yamlSettings . documents = new TextDocumentTestManager ( ) ;
1597+ ( yamlSettings . documents as TextDocumentTestManager ) . set ( testTextDocument ) ;
1598+ const result = await languageHandler . completionHandler ( {
1599+ position : testTextDocument . positionAt ( 0 ) ,
1600+ textDocument : testTextDocument ,
1601+ } ) ;
1602+ assert . strictEqual ( result . items . length , 1 , `Expecting 1 item in completion but found ${ result . items . length } ` ) ;
1603+ assert . strictEqual ( result . items [ 0 ] . label , inlineSchemaLabel ) ;
1604+ } ) ;
1605+
1606+ it ( 'should not provide modeline completion on first character when schema is associated' , async ( ) => {
1607+ const specificSchemaId = path . join ( __dirname , 'test.yaml' ) ;
1608+ const testTextDocument = setupSchemaIDTextDocument ( '' , specificSchemaId ) ;
1609+ languageService . addSchema ( specificSchemaId , {
1610+ type : 'object' ,
1611+ properties : {
1612+ name : {
1613+ type : 'string' ,
1614+ } ,
1615+ } ,
1616+ } ) ;
1617+ yamlSettings . documents = new TextDocumentTestManager ( ) ;
1618+ ( yamlSettings . documents as TextDocumentTestManager ) . set ( testTextDocument ) ;
1619+ const result = await languageHandler . completionHandler ( {
1620+ position : testTextDocument . positionAt ( 0 ) ,
1621+ textDocument : testTextDocument ,
1622+ } ) ;
1623+ assert . strictEqual ( result . items . length , 1 , `Expecting 1 item in completion but found ${ result . items . length } ` ) ;
1624+ assert . notStrictEqual ( result . items [ 0 ] . label , inlineSchemaLabel ) ;
1625+ } ) ;
1626+
1627+ it ( 'should not provide modeline completion on first character when modeline already present' , async ( ) => {
1628+ const testTextDocument = setupSchemaIDTextDocument ( '# yaml-language-server' , path . join ( __dirname , 'test.yaml' ) ) ;
1629+ yamlSettings . documents = new TextDocumentTestManager ( ) ;
1630+ ( yamlSettings . documents as TextDocumentTestManager ) . set ( testTextDocument ) ;
1631+ const result = await languageHandler . completionHandler ( {
1632+ position : testTextDocument . positionAt ( 0 ) ,
1633+ textDocument : testTextDocument ,
1634+ } ) ;
1635+ assert . strictEqual ( result . items . length , 0 , `Expecting 0 item in completion but found ${ result . items . length } ` ) ;
1636+ } ) ;
15911637 } ) ;
15921638
15931639 describe ( 'Configuration based indentation' , ( ) => {
0 commit comments