Skip to content

Commit 17edd7c

Browse files
committed
#408 support $ref in additionalItems
1 parent c0bee52 commit 17edd7c

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

src/languageservice/services/yamlCompletion.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -1016,14 +1016,18 @@ export class YAMLCompletion extends JSONCompletion {
10161016
document.getText().substr(lineOffset[linePos + 1] || document.getText().length);
10171017

10181018
// For when missing semi colon case
1019-
} else {
1019+
} else if (trimmedText.indexOf('[') === -1) {
10201020
// Add a semicolon to the end of the current line so we can validate the node
10211021
newText =
10221022
document.getText().substring(0, start + textLine.length) +
10231023
':\r\n' +
10241024
document.getText().substr(lineOffset[linePos + 1] || document.getText().length);
10251025
}
10261026

1027+
if (newText.length === 0) {
1028+
newText = document.getText();
1029+
}
1030+
10271031
return {
10281032
newText: newText,
10291033
newPosition: textDocumentPosition,

src/languageservice/services/yamlSchemaService.ts

+1
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ export class YAMLSchemaService extends JSONSchemaService {
244244

245245
collectEntries(
246246
<JSONSchema>next.items,
247+
next.additionalItems,
247248
<JSONSchema>next.additionalProperties,
248249
next.not,
249250
next.contains,

test/autoCompletion.test.ts

+64
Original file line numberDiff line numberDiff line change
@@ -1840,6 +1840,70 @@ describe('Auto Completion Tests', () => {
18401840
createExpectedCompletion('kind', 'kind', 0, 0, 0, 2, 10, InsertTextFormat.Snippet, { documentation: '' })
18411841
);
18421842
});
1843+
1844+
it('should follow $ref in additionalItems', async () => {
1845+
languageService.addSchema(SCHEMA_ID, {
1846+
type: 'object',
1847+
properties: {
1848+
test: {
1849+
$ref: '#/definitions/Recur',
1850+
},
1851+
},
1852+
definitions: {
1853+
Recur: {
1854+
type: 'array',
1855+
items: [
1856+
{
1857+
type: 'string',
1858+
enum: ['and'],
1859+
},
1860+
],
1861+
additionalItems: {
1862+
$ref: '#/definitions/Recur',
1863+
},
1864+
},
1865+
},
1866+
});
1867+
1868+
const content = 'test:\n - and\n - - ';
1869+
const completion = await parseSetup(content, 19);
1870+
expect(completion.items).lengthOf(1);
1871+
expect(completion.items[0]).eql(
1872+
createExpectedCompletion('and', 'and', 2, 4, 2, 5, 12, InsertTextFormat.Snippet, { documentation: undefined })
1873+
);
1874+
});
1875+
1876+
it('should follow $ref in additionalItems for flow style array', async () => {
1877+
languageService.addSchema(SCHEMA_ID, {
1878+
type: 'object',
1879+
properties: {
1880+
test: {
1881+
$ref: '#/definitions/Recur',
1882+
},
1883+
},
1884+
definitions: {
1885+
Recur: {
1886+
type: 'array',
1887+
items: [
1888+
{
1889+
type: 'string',
1890+
enum: ['and'],
1891+
},
1892+
],
1893+
additionalItems: {
1894+
$ref: '#/definitions/Recur',
1895+
},
1896+
},
1897+
},
1898+
});
1899+
1900+
const content = 'test:\n - and\n - []';
1901+
const completion = await parseSetup(content, 18);
1902+
expect(completion.items).lengthOf(1);
1903+
expect(completion.items[0]).eql(
1904+
createExpectedCompletion('and', 'and', 2, 4, 2, 4, 12, InsertTextFormat.Snippet, { documentation: undefined })
1905+
);
1906+
});
18431907
});
18441908
describe('Array completion', () => {
18451909
it('Simple array object completion with "-" without any item', async () => {

0 commit comments

Comments
 (0)