From 4b91dd31840131bec685b065e9a0c2f6814ae1e8 Mon Sep 17 00:00:00 2001
From: Petr Spacek
Date: Tue, 28 May 2024 13:59:46 +0200
Subject: [PATCH 1/2] feat: unify string insert text for array and property
(#934)
---
src/languageservice/services/yamlCompletion.ts | 2 +-
test/autoCompletion.test.ts | 2 +-
test/autoCompletionFix.test.ts | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/languageservice/services/yamlCompletion.ts b/src/languageservice/services/yamlCompletion.ts
index 99e061f0..0ef71bab 100644
--- a/src/languageservice/services/yamlCompletion.ts
+++ b/src/languageservice/services/yamlCompletion.ts
@@ -1205,7 +1205,7 @@ export class YamlCompletion {
insertText = `\${${insertIndex++}:0}`;
break;
case 'string':
- insertText = `\${${insertIndex++}:""}`;
+ insertText = `\${${insertIndex++}}`;
break;
case 'object':
{
diff --git a/test/autoCompletion.test.ts b/test/autoCompletion.test.ts
index 78b14996..dd5abe0c 100644
--- a/test/autoCompletion.test.ts
+++ b/test/autoCompletion.test.ts
@@ -1047,7 +1047,7 @@ describe('Auto Completion Tests', () => {
const completion = parseSetup(content, content.lastIndexOf('Ba') + 2); // pos: 3+2
completion
.then(function (result) {
- assert.strictEqual('fooBar:\n - ${1:""}', result.items[0].insertText);
+ assert.strictEqual('fooBar:\n - ${1}', result.items[0].insertText);
})
.then(done, done);
});
diff --git a/test/autoCompletionFix.test.ts b/test/autoCompletionFix.test.ts
index 81053315..f81c68aa 100644
--- a/test/autoCompletionFix.test.ts
+++ b/test/autoCompletionFix.test.ts
@@ -482,7 +482,7 @@ objB:
expect(completion.items.length).equal(1);
expect(completion.items[0]).to.be.deep.equal(
- createExpectedCompletion('objectWithArray', 'objectWithArray:\n - ${1:""}', 1, 4, 1, 4, 10, 2, {
+ createExpectedCompletion('objectWithArray', 'objectWithArray:\n - ${1}', 1, 4, 1, 4, 10, 2, {
documentation: '',
})
);
From e5dcce044e27dd6b6da54107f5eff092649ca002 Mon Sep 17 00:00:00 2001
From: Petr Spacek
Date: Tue, 28 May 2024 14:07:20 +0200
Subject: [PATCH 2/2] fix: snippets in additionalProperties (#951)
Co-authored-by: Muthurajan Sivasubramanian <93245779+msivasubramaniaan@users.noreply.github.com>
---
.../services/yamlCompletion.ts | 3 ++-
test/autoCompletionFix.test.ts | 24 +++++++++++++++++++
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/src/languageservice/services/yamlCompletion.ts b/src/languageservice/services/yamlCompletion.ts
index 0ef71bab..be21a8bb 100644
--- a/src/languageservice/services/yamlCompletion.ts
+++ b/src/languageservice/services/yamlCompletion.ts
@@ -925,7 +925,8 @@ export class YamlCompletion {
if (propertySchema) {
this.addSchemaValueCompletions(propertySchema, separatorAfter, collector, types, 'value');
}
- } else if (s.schema.additionalProperties) {
+ }
+ if (s.schema.additionalProperties) {
this.addSchemaValueCompletions(s.schema.additionalProperties, separatorAfter, collector, types, 'value');
}
}
diff --git a/test/autoCompletionFix.test.ts b/test/autoCompletionFix.test.ts
index f81c68aa..c720ce76 100644
--- a/test/autoCompletionFix.test.ts
+++ b/test/autoCompletionFix.test.ts
@@ -1183,6 +1183,30 @@ objB:
expect(completion.items[0].insertText).to.be.equal('test1');
});
+ it('should suggest defaultSnippets from additionalProperties', async () => {
+ const schema: JSONSchema = {
+ type: 'object',
+ properties: {
+ id: {
+ type: 'string',
+ },
+ },
+ additionalProperties: {
+ anyOf: [
+ {
+ type: 'string',
+ defaultSnippets: [{ label: 'snippet', body: 'snippetBody' }],
+ },
+ ],
+ },
+ };
+ schemaProvider.addSchema(SCHEMA_ID, schema);
+ const content = 'value: |\n|';
+ const completion = await parseCaret(content);
+
+ expect(completion.items.map((i) => i.insertText)).to.be.deep.equal(['snippetBody']);
+ });
+
describe('should suggest prop of the object (based on not completed prop name)', () => {
const schema: JSONSchema = {
definitions: {