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

Add snake_case to transform grammar in snippets #233798

Open
joeriddles opened this issue Nov 13, 2024 · 3 comments · May be fixed by #237110
Open

Add snake_case to transform grammar in snippets #233798

joeriddles opened this issue Nov 13, 2024 · 3 comments · May be fixed by #237110
Assignees
Labels
feature-request Request for new features or functionality snippets
Milestone

Comments

@joeriddles
Copy link

joeriddles commented Nov 13, 2024

VS Code snippet transform syntax supports converting capture groups to a variety of formats, including lowercase, camelCase, and PascalCase. Support for snake_case would be awesome.

See https://code.visualstudio.com/docs/editor/userdefinedsnippets#_grammar


This feature would be helpful when trying to define a snippet that automatically adds a json struct tag to Go fields, for example:

type Person struct {
    FirstName `json:"first_name"`
}

This is the snippet definition I'm using right now, though it's buggy:

"property with JSON and YAML": {
	"prefix": "prop",
	"body": [
		"${1:name} ${2:string} `yaml:\"${1/([A-Z]?[a-z]+)([A-Z])/${1:/downcase}_${2:/downcase}/g}\" json:\"${1/([A-Z]?[a-z]+)([A-Z])/${1:/downcase}_${2:/downcase}/g}\"`"
	],
},
@jrieken jrieken added feature-request Request for new features or functionality snippets labels Nov 14, 2024
@vs-code-engineering vs-code-engineering bot added this to the Backlog Candidates milestone Nov 14, 2024
Copy link

This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

@RedCMD
Copy link
Contributor

RedCMD commented Dec 16, 2024

relevant file section:

resolve(value?: string): string {
if (this.shorthandName === 'upcase') {
return !value ? '' : value.toLocaleUpperCase();
} else if (this.shorthandName === 'downcase') {
return !value ? '' : value.toLocaleLowerCase();
} else if (this.shorthandName === 'capitalize') {
return !value ? '' : (value[0].toLocaleUpperCase() + value.substr(1));
} else if (this.shorthandName === 'pascalcase') {
return !value ? '' : this._toPascalCase(value);
} else if (this.shorthandName === 'camelcase') {
return !value ? '' : this._toCamelCase(value);
} else if (Boolean(value) && typeof this.ifValue === 'string') {
return this.ifValue;
} else if (!Boolean(value) && typeof this.elseValue === 'string') {
return this.elseValue;
} else {
return value || '';
}
}

Copy link

🙂 This feature request received a sufficient number of community upvotes and we moved it to our backlog. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

@joeriddles joeriddles linked a pull request Dec 31, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality snippets
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants