Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support $ref in additionalItems #433

Merged
merged 1 commit into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/languageservice/services/yamlCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1016,14 +1016,18 @@ export class YAMLCompletion extends JSONCompletion {
document.getText().substr(lineOffset[linePos + 1] || document.getText().length);

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

if (newText.length === 0) {
newText = document.getText();
}

return {
newText: newText,
newPosition: textDocumentPosition,
Expand Down
1 change: 1 addition & 0 deletions src/languageservice/services/yamlSchemaService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ export class YAMLSchemaService extends JSONSchemaService {

collectEntries(
<JSONSchema>next.items,
next.additionalItems,
<JSONSchema>next.additionalProperties,
next.not,
next.contains,
Expand Down
64 changes: 64 additions & 0 deletions test/autoCompletion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1840,6 +1840,70 @@ describe('Auto Completion Tests', () => {
createExpectedCompletion('kind', 'kind', 0, 0, 0, 2, 10, InsertTextFormat.Snippet, { documentation: '' })
);
});

it('should follow $ref in additionalItems', async () => {
languageService.addSchema(SCHEMA_ID, {
type: 'object',
properties: {
test: {
$ref: '#/definitions/Recur',
},
},
definitions: {
Recur: {
type: 'array',
items: [
{
type: 'string',
enum: ['and'],
},
],
additionalItems: {
$ref: '#/definitions/Recur',
},
},
},
});

const content = 'test:\n - and\n - - ';
const completion = await parseSetup(content, 19);
expect(completion.items).lengthOf(1);
expect(completion.items[0]).eql(
createExpectedCompletion('and', 'and', 2, 4, 2, 5, 12, InsertTextFormat.Snippet, { documentation: undefined })
);
});

it('should follow $ref in additionalItems for flow style array', async () => {
languageService.addSchema(SCHEMA_ID, {
type: 'object',
properties: {
test: {
$ref: '#/definitions/Recur',
},
},
definitions: {
Recur: {
type: 'array',
items: [
{
type: 'string',
enum: ['and'],
},
],
additionalItems: {
$ref: '#/definitions/Recur',
},
},
},
});

const content = 'test:\n - and\n - []';
const completion = await parseSetup(content, 18);
expect(completion.items).lengthOf(1);
expect(completion.items[0]).eql(
createExpectedCompletion('and', 'and', 2, 4, 2, 4, 12, InsertTextFormat.Snippet, { documentation: undefined })
);
});
});
describe('Array completion', () => {
it('Simple array object completion with "-" without any item', async () => {
Expand Down