Skip to content

Commit 9bda8c0

Browse files
ShadiestGoatdatho7561
authored andcommitted
Fix ignoreScalar in value completion
1 parent b056846 commit 9bda8c0

File tree

2 files changed

+46
-7
lines changed

2 files changed

+46
-7
lines changed

src/languageservice/services/yamlCompletion.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,12 @@ export class YamlCompletion {
513513
}
514514
}
515515

516+
const ignoreScalars =
517+
textBuffer.getLineContent(overwriteRange.start.line).trim().length === 0 &&
518+
originalNode &&
519+
isScalar(originalNode) &&
520+
originalNode.value === null;
521+
516522
// completion for object keys
517523
if (node && isMap(node)) {
518524
// don't suggest properties that are already present
@@ -534,7 +540,8 @@ export class YamlCompletion {
534540
collector,
535541
textBuffer,
536542
overwriteRange,
537-
doComplete
543+
doComplete,
544+
ignoreScalars
538545
);
539546

540547
if (!schema && currentWord.length > 0 && text.charAt(offset - currentWord.length - 1) !== '"') {
@@ -549,7 +556,7 @@ export class YamlCompletion {
549556

550557
// proposals for values
551558
const types: { [type: string]: boolean } = {};
552-
this.getValueCompletions(schema, currentDoc, node, offset, document, collector, types, doComplete);
559+
this.getValueCompletions(schema, currentDoc, node, offset, document, collector, types, doComplete, ignoreScalars);
553560
} catch (err) {
554561
this.telemetry?.sendError('yaml.completion.error', err);
555562
}
@@ -689,7 +696,8 @@ export class YamlCompletion {
689696
collector: CompletionsCollector,
690697
textBuffer: TextBuffer,
691698
overwriteRange: Range,
692-
doComplete: boolean
699+
doComplete: boolean,
700+
ignoreScalars: boolean
693701
): void {
694702
const matchingSchemas = doc.getMatchingSchemas(schema.schema, -1, null, doComplete);
695703
const existingKey = textBuffer.getText(overwriteRange);
@@ -708,7 +716,6 @@ export class YamlCompletion {
708716
}
709717
});
710718
}
711-
const ignoreScalars = lineContent.trim() === '' && originalNode && isScalar(originalNode) && originalNode.value === null;
712719

713720
for (const schema of matchingSchemas) {
714721
if (
@@ -886,7 +893,8 @@ export class YamlCompletion {
886893
document: TextDocument,
887894
collector: CompletionsCollector,
888895
types: { [type: string]: boolean },
889-
doComplete: boolean
896+
doComplete: boolean,
897+
ignoreScalars: boolean
890898
): void {
891899
let parentKey: string = null;
892900

@@ -941,11 +949,11 @@ export class YamlCompletion {
941949
if (s.schema.properties) {
942950
const propertySchema = s.schema.properties[parentKey];
943951
if (propertySchema) {
944-
this.addSchemaValueCompletions(propertySchema, separatorAfter, collector, types, false);
952+
this.addSchemaValueCompletions(propertySchema, separatorAfter, collector, types, ignoreScalars);
945953
}
946954
}
947955
if (s.schema.additionalProperties) {
948-
this.addSchemaValueCompletions(s.schema.additionalProperties, separatorAfter, collector, types, false);
956+
this.addSchemaValueCompletions(s.schema.additionalProperties, separatorAfter, collector, types, ignoreScalars);
949957
}
950958
}
951959
}

test/autoCompletion.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,6 +1747,37 @@ describe('Auto Completion Tests', () => {
17471747
})
17481748
);
17491749
});
1750+
it('Next line const with : but array level completion', async () => {
1751+
const content = 'test:\n - constProp:\n ';
1752+
const result = await parseSetup(content, content.length);
1753+
expect(result.items.length).to.be.equal(0);
1754+
});
1755+
it('Next line const with : & |- but array level completion', async () => {
1756+
const content = 'test:\n - constProp: |-\n ';
1757+
const result = await parseSetup(content, content.length);
1758+
expect(result.items.length).to.be.equal(1);
1759+
expect(result.items[0]).contain;
1760+
// TODO: Ideally, this would not be a deep equal, it'd be does real contain expected
1761+
assert.deepEqual(
1762+
result.items[0],
1763+
createExpectedCompletion(
1764+
'- (array item) object',
1765+
'- ',
1766+
2,
1767+
2,
1768+
2,
1769+
2,
1770+
CompletionItemKind.Module,
1771+
InsertTextFormat.Snippet,
1772+
{
1773+
documentation: {
1774+
kind: 'markdown',
1775+
value: 'Create an item of an array type `object`\n ```\n- \n```',
1776+
},
1777+
}
1778+
)
1779+
);
1780+
});
17501781
});
17511782
});
17521783

0 commit comments

Comments
 (0)