Skip to content
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
11 changes: 10 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

156 changes: 69 additions & 87 deletions src/languageservice/services/yamlCompletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@
if (!schema || schema.errors.length) {
return result;
}

let currentProperty: YamlNode = null;

if (!node) {
Expand Down Expand Up @@ -800,19 +799,8 @@
(isScalar(originalNode) && originalNode.value === null) ||
(isMap(originalNode) && originalNode.items.length === 0);
const existsParentCompletion = schema.schema.required?.length > 0;
if (!this.parentSkeletonSelectedFirst || !isNodeNull || !existsParentCompletion) {
collector.add(
{
kind: CompletionItemKind.Property,
label: key,
insertText,
insertTextFormat: InsertTextFormat.Snippet,
documentation: this.fromMarkup(propertySchema.markdownDescription) || propertySchema.description || '',
},
didOneOfSchemaMatches
);
}
// if the prop is required add it also to parent suggestion

// If the property is required, add it also to the parent suggestion.
if (schema.schema.required?.includes(key)) {
collector.add({
label: key,
Expand All @@ -831,86 +819,86 @@
},
});
}

if (!this.parentSkeletonSelectedFirst || !isNodeNull || !existsParentCompletion) {
collector.add(
{
kind: CompletionItemKind.Property,
label: key,
insertText,
insertTextFormat: InsertTextFormat.Snippet,
documentation: this.fromMarkup(propertySchema.markdownDescription) || propertySchema.description || '',
},
didOneOfSchemaMatches
);
}
}
}
}
}
}
// Error fix
// If this is a array of string/boolean/number
// test:
// - item1
// it will treated as a property key since `:` has been appended
if (nodeParent && isSeq(nodeParent) && isPrimitiveType(schema.schema)) {
this.addSchemaValueCompletions(schema.schema, separatorAfter, collector, {}, ignoreScalars);
}
}
// Error fix
// If this is a array of string/boolean/number
// test:
// - item1
// it will treated as a property key since `:` has been appended
if (nodeParent && isSeq(nodeParent) && isPrimitiveType(schema.schema)) {
this.addSchemaValueCompletions(schema.schema, separatorAfter, collector, {}, ignoreScalars);
}

if (schema.schema.type === 'object' && schema.schema.propertyNames && schema.schema.additionalProperties !== false) {
const propertyNameSchema = asSchema(schema.schema.propertyNames);
if (!propertyNameSchema.deprecationMessage && !propertyNameSchema.doNotSuggest) {
const doc = this.fromMarkup(
(propertyNameSchema.markdownDescription || propertyNameSchema.description || '') +
(propertyNameSchema.pattern ? `\n\n**Pattern:** \`${propertyNameSchema.pattern}\`` : '')
);
const { candidates, impossible } = this.getPropertyNamesCandidates(propertyNameSchema);
if (impossible) {
// suggest nothing
} else if (candidates.length) {
for (const key of candidates) {
collector.add({
kind: CompletionItemKind.Property,
label: key,
insertText: `${key}: `,
insertTextFormat: InsertTextFormat.PlainText,
documentation: doc,
});
}
} else {
const label = propertyNameSchema.title || 'property';
if (schema.schema.type === 'object' && schema.schema.propertyNames && schema.schema.additionalProperties !== false) {
const propertyNameSchema = asSchema(schema.schema.propertyNames);
if (!propertyNameSchema.deprecationMessage && !propertyNameSchema.doNotSuggest) {
const doc = this.fromMarkup(
(propertyNameSchema.markdownDescription || propertyNameSchema.description || '') +
(propertyNameSchema.pattern ? `\n\n**Pattern:** \`${propertyNameSchema.pattern}\`` : '')
);
const { candidates, impossible } = this.getPropertyNamesCandidates(propertyNameSchema);
if (impossible) {
// suggest nothing
} else if (candidates.length) {
for (const key of candidates) {
collector.add({
kind: CompletionItemKind.Property,
label,
insertText: '$' + `{1:${label}}: `,
insertTextFormat: InsertTextFormat.Snippet,
label: key,
insertText: `${key}: `,
insertTextFormat: InsertTextFormat.PlainText,
documentation: doc,
});
}
} else {
const label = propertyNameSchema.title || 'property';
collector.add({
kind: CompletionItemKind.Property,
label,
insertText: '$' + `{1:${label}}: `,
insertTextFormat: InsertTextFormat.Snippet,
documentation: doc,
});
}
}
}
}

if (nodeParent && schema.node.internalNode === nodeParent && schema.schema.defaultSnippets) {
// For some reason the first item in the array needs to be treated differently, otherwise
// the indentation will not be correct
if (node.items.length === 1) {
this.collectDefaultSnippets(
schema.schema,
separatorAfter,
collector,
{
newLineFirst: false,
indentFirstObject: false,
shouldIndentWithTab: true,
},
1
);
} else {
this.collectDefaultSnippets(
schema.schema,
separatorAfter,
collector,
{
newLineFirst: false,
indentFirstObject: true,
shouldIndentWithTab: false,
},
1
);
}
if (nodeParent && schema.node.internalNode === nodeParent && schema.schema.defaultSnippets) {
// For some reason the first item in the array needs to be treated differently, otherwise
// the indentation will not be correct
if (node.items.length === 1) {
this.collectDefaultSnippets(schema.schema, separatorAfter, collector, {
newLineFirst: false,
indentFirstObject: false,
shouldIndentWithTab: true,
});
} else {
this.collectDefaultSnippets(schema.schema, separatorAfter, collector, {
newLineFirst: false,
indentFirstObject: true,
shouldIndentWithTab: false,
});
}
}
}

private getValueCompletions(
schema: ResolvedSchema,
doc: SingleYAMLDocument,
Expand Down Expand Up @@ -1046,17 +1034,11 @@
if (propertySchema.defaultSnippets.length === 1) {
const body = propertySchema.defaultSnippets[0].body;
if (isDefined(body)) {
value = this.getInsertTextForSnippetValue(
body,
'',
{
newLineFirst: true,
indentFirstObject: false,
shouldIndentWithTab: false,
},
[],
1
);
value = this.getInsertTextForSnippetValue(body, '', {

Check failure on line 1037 in src/languageservice/services/yamlCompletion.ts

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Expected 4-5 arguments, but got 3.
newLineFirst: true,
indentFirstObject: false,
shouldIndentWithTab: false,
});
// add space before default snippet value
if (!value.startsWith(' ') && !value.startsWith('\n')) {
value = ' ' + value;
Expand Down
6 changes: 2 additions & 4 deletions src/languageservice/services/yamlHover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,8 @@ function ensureLineBreak(content: string): string {
if (content.length === 0) {
return content;
}
if (!content.endsWith('\n')) {
content += '\n';
}
return content + '\n';

return content.replace(/\n+$/g, '') + '\n\n';
}

function getSchemaName(schema: JSONSchema): string {
Expand Down
Loading