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

fix: doNotSuggest for property and value completion #911

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
10 changes: 9 additions & 1 deletion src/languageservice/services/yamlCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,10 @@ export class YamlCompletion {
});
}
for (const schema of matchingSchemas) {
if (schema.schema.doNotSuggest) {
continue;
}

if (
((schema.node.internalNode === node && !matchOriginal) ||
(schema.node.internalNode === originalNode && !hasColon) ||
Expand All @@ -716,7 +720,7 @@ export class YamlCompletion {
if (Object.prototype.hasOwnProperty.call(schemaProperties, key)) {
const propertySchema = schemaProperties[key];

if (typeof propertySchema === 'object' && !propertySchema.deprecationMessage && !propertySchema['doNotSuggest']) {
if (typeof propertySchema === 'object' && !propertySchema.deprecationMessage && !propertySchema.doNotSuggest) {
let identCompensation = '';
if (nodeParent && isSeq(nodeParent) && node.items.length <= 1 && !hasOnlyWhitespace) {
// because there is a slash '-' to prevent the properties generated to have the correct
Expand Down Expand Up @@ -1309,6 +1313,10 @@ export class YamlCompletion {
isArray?: boolean
): void {
if (typeof schema === 'object') {
if (schema.doNotSuggest) {
return;
}

this.addEnumValueCompletions(schema, separatorAfter, collector, isArray);
this.addDefaultValueCompletions(schema, separatorAfter, collector);
this.collectTypes(schema, types);
Expand Down
66 changes: 66 additions & 0 deletions test/autoCompletionFix.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1329,4 +1329,70 @@ test1:
expect(completion.items[0].insertText).to.be.equal('${1:property}: ');
expect(completion.items[0].documentation).to.be.equal('Property Description');
});

describe('doNotSuggest schema', () => {
it('should not autocomplete schema with doNotSuggest - property completion', async () => {
const schema: JSONSchema = {
properties: {
prop1: { type: 'string' },
},
doNotSuggest: true,
};
schemaProvider.addSchema(SCHEMA_ID, schema);
const content = '';
const completion = await parseSetup(content, 0, 1);

expect(completion.items.length).equal(0);
});
it('should not autocomplete schema with doNotSuggest - value completion', async () => {
const schema: JSONSchema = {
properties: {
prop1: {
anyOf: [
{
type: 'string',
default: 'value_default',
doNotSuggest: true,
},
{
type: 'object',
defaultSnippets: [
{
label: 'snippet',
body: {
value1: 'value_snippet',
},
},
],
doNotSuggest: true,
},
],
},
},
};
schemaProvider.addSchema(SCHEMA_ID, schema);
const content = 'prop1: ';
const completion = await parseSetup(content, 0, content.length);

expect(completion.items.length).equal(0);
});
it('should autocomplete inside schema in doNotSuggest', async () => {
const schema: JSONSchema = {
properties: {
obj1: {
properties: {
item1: { type: 'string' },
},
},
},
doNotSuggest: true,
};
schemaProvider.addSchema(SCHEMA_ID, schema);
const content = 'obj1:\n | |';
const completion = await parseCaret(content);

expect(completion.items.length).equal(1);
expect(completion.items[0].label).equal('item1');
});
});
});
Loading