diff --git a/test/autoCompletionFix.test.ts b/test/autoCompletionFix.test.ts index 2486246a..535fd5e9 100644 --- a/test/autoCompletionFix.test.ts +++ b/test/autoCompletionFix.test.ts @@ -882,8 +882,8 @@ objB: }, }, }; - languageService.addSchema(SCHEMA_ID, schema); - const content = 'array:\n - na| | '; + schemaProvider.addSchema(SCHEMA_ID, schema); + const content = 'array:\n - obj| | '; const completion = await parseCaret(content); expect(completion.items.length).equal(1); @@ -1109,6 +1109,41 @@ objB: expect(result.items.length).to.be.equal(1); expect(result.items[0].insertText).to.be.equal('objA:\n itemA: '); }); + + it('array completion - should suggest correct indent when extra spaces after cursor followed by with different array item', async () => { + schemaProvider.addSchema(SCHEMA_ID, { + type: 'object', + properties: { + test: { + type: 'array', + items: { + type: 'object', + properties: { + objA: { + type: 'object', + required: ['itemA'], + properties: { + itemA: { + type: 'string', + }, + }, + }, + }, + }, + }, + }, + }); + const content = ` +test: + - | | + - objA: + itemA: test`; + const result = await parseCaret(content); + + expect(result.items.length).to.be.equal(1); + expect(result.items[0].insertText).to.be.equal('objA:\n itemA: '); + }); + it('array of arrays completion - should suggest correct indent when extra spaces after cursor', async () => { schemaProvider.addSchema(SCHEMA_ID, { type: 'object', @@ -1207,7 +1242,7 @@ objB: }, }; it('should get extra space compensation for the 1st prop in array object item', async () => { - languageService.addSchema(SCHEMA_ID, schema); + schemaProvider.addSchema(SCHEMA_ID, schema); const content = 'array1:\n - |\n| propB: test'; const result = await parseCaret(content); @@ -1215,19 +1250,10 @@ objB: expect(result.items[0].insertText).to.be.equal('objA:\n '); }); it('should get extra space compensation for the 1st prop in array object item - extra spaces', async () => { - languageService.addSchema(SCHEMA_ID, schema); + schemaProvider.addSchema(SCHEMA_ID, schema); const content = 'array1:\n - | | \n propB: test'; const result = await parseCaret(content); - expect(result.items.length).to.be.equal(1); - expect(result.items[0].insertText).to.be.equal('objA:\n '); - }); - // previous PR doesn't fix this - it.skip('should get extra space compensation for the 1st prop in array object item - extra lines', async () => { - languageService.addSchema(SCHEMA_ID, schema); - const content = 'array1:\n - \n |\n| propB: test'; - const result = await parseCaret(content); - expect(result.items.length).to.be.equal(1); expect(result.items[0].insertText).to.be.equal('objA:\n '); }); diff --git a/test/yaml-documents.test.ts b/test/yaml-documents.test.ts index d4c08618..a544ce18 100644 --- a/test/yaml-documents.test.ts +++ b/test/yaml-documents.test.ts @@ -212,6 +212,18 @@ objB: }); describe('Array', () => { + // Problem in `getNodeFromPosition` function. This method doesn't give proper results for arrays + // for example, this yaml return nodes: + // foo: + // - # foo object is returned (should be foo[0]) + // # foo object is returned (should be foo[0]) + // item1: aaaf + // # foo[0] object is returned (OK) + // - # foo object is returned (should be foo[1]) + // # foo[!!0!!] object is returned (should be foo[1]) + // item2: bbb + // # foo[1] object is returned (OK) + it('Find closes node: array', () => { const doc = setupTextDocument('foo:\n - bar: aaa\n '); const yamlDoc = documents.getYamlDocument(doc);