Skip to content

feat: property snippets#36

Closed
p-spacek wants to merge 17 commits into
mainfrom
feat/property-snippets
Closed

feat: property snippets#36
p-spacek wants to merge 17 commits into
mainfrom
feat/property-snippets

Conversation

@p-spacek
Copy link
Copy Markdown
Collaborator

@p-spacek p-spacek commented Mar 12, 2025

What does this PR do?

the main purpose of this PR is to support property snippets
intellisense
image
will insert the value from the snippet
image

but this PR also unifies related changes from PRs:
redhat-developer#755
redhat-developer#901
and include some other snippet fixes

What issues does this PR fix or reference?

no ref

Is it tested? How?

existing and a few new unit tests
tested by QA in our separate branch

return `${resultText}\n${indent}- ${
this.getInsertTextForArray(propertySchema.items, separatorAfter, 1, indent).insertText
}`;
let insertText = this.getInsertTextForArray(propertySchema.items, separatorAfter, collector, 1, indent).insertText;
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix a few existing issues with snippet indentation

insertIndex = 1
): InsertText {
let insertText = '';
if (Array.isArray(schema.defaultSnippets) && schema.defaultSnippets.length === 1) {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the main change of this PR is to add snippets to the object

}
arrayTemplate = arrayInsertLines.join('\n');
}
const arrayInsertResult = this.getInsertTextForArray(
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactor and fix indentation
use new addIndentationToMultilineString function

continue;
}

if ((arrayDepth === 0 && type === 'array') || isArray) {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactor, uses a new collector.context concept to distinguish between different scenarios
It wasn't possible to detect if a hyphen was missing or if the cursor was after the colon

for (let i = 0; i < obj.length; i++) {
let pseudoObj = obj[i];
if (typeof obj[i] !== 'object') {
if (typeof obj[i] !== 'object' || obj[i] === null) {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix the null issue when the snippet contains null as a value

return offset;
}

export function addIndentationToMultilineString(text: string, firstIndent: string, nextIndent: string): string {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unified function to indent multiline strings, this logic was written multiple times before

… yaml

 - because it's properties from the parent object
@p-spacek
Copy link
Copy Markdown
Collaborator Author

PR to original repo was created, so it's possible to cancel this

@p-spacek p-spacek closed this Mar 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants