Skip to content

Add snake_case to transform grammar in snippets #233798

@joeriddles

Description

@joeriddles

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}\"`"
	],
},

Metadata

Metadata

Assignees

Labels

feature-requestRequest for new features or functionalityinsiders-releasedPatch has been released in VS Code Insiderson-release-notesIssue/pull request mentioned in release notessnippetsverification-neededVerification of issue is requestedverifiedVerification succeeded

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions