VSCode extension for Go struct field tags: syntax highlighting, sorting, and alignment.
Tags are colored using your current theme - no hardcoded colors, no background overrides that would break selection highlighting.
Each part of a tag gets a distinct color from the active theme:
- Key (
json,yaml,db, …) - attribute color - Value (
"my_field") - string color - Option (
omitempty,required,min=1) - constant color - Separator (
,) - punctuation color
Three inline actions appear above every struct that has tagged fields:
Sort & Align Tags | Sort Tags | Align Tags
type UserProfile struct {Reorders tag keys across all fields of a struct to a consistent canonical order.
first-field mode (default) - order is derived from the first field:
keys present there come first,
the rest follow in the order they are first encountered across the struct.
Before:
type User struct {
ID int `json:"id" yaml:"id"`
Name string `yaml:"name" json:"name" db:"name"`
Email string `db:"email" json:"email"`
}After (sortPriority: ["json", "yaml"]):
type User struct {
ID int `json:"id" yaml:"id"`
Name string `json:"name" yaml:"name" db:"name"`
Email string `json:"email" db:"email"`
}alphabetical mode - all keys sorted A->Z (after applying sortPriority).
Pads tag columns with spaces so values line up vertically. Only applied to consecutive fields - groups separated by blank lines are aligned independently.
Before:
type Address struct {
Street string `json:"street" yaml:"street" db:"street"`
City string `json:"city" yaml:"city" db:"city"`
Country string `json:"country" yaml:"country" db:"country"`
ZipCode string `json:"zip_code" yaml:"zip_code" db:"zip_code"`
}After:
type Address struct {
Street string `json:"street" yaml:"street" db:"street"`
City string `json:"city" yaml:"city" db:"city"`
Country string `json:"country" yaml:"country" db:"country"`
ZipCode string `json:"zip_code" yaml:"zip_code" db:"zip_code"`
}Fields separated by blank lines or comments are treated as separate groups and aligned independently.
Both Sort and Align automatically normalize tags:
strip extra spaces inside the backtick string
and ensure a single space between each key:"value" pair.
// Before
Field string ` json:"id" yaml:"id" `
// After
Field string `json:"id" yaml:"id"`All commands are available in the Command Palette
(Ctrl+Shift+P / Cmd+Shift+P) under the Go Struct Tags Manager category.
- Sort Struct Field Tags - sort tags in the struct at cursor
- Align Struct Field Tags - align tags in the struct at cursor
- Sort & Align Struct Field Tags - sort then align in the struct at cursor
- Sort Struct Field Tags in File - apply sort to all structs in the file
- Align Struct Field Tags in File - apply alignment to all structs in the file
- Sort & Align Struct Field Tags in File - apply sort & align to all structs in the file
goStructTags.autoSortOnSaveboolean- automatically sort tags on file save.
Default:false.goStructTags.autoAlignOnSaveboolean- automatically align tags on file save.
Default:false.goStructTags.sortMode"first-field" | "alphabetical"- how to determine canonical key order when sorting.
Default:"first-field".goStructTags.sortPrioritystring[]- tag keys that always come first, in the specified order, regardless ofsortMode.
Default:[].goStructTags.colors.keystring- override color for tag keys (e.g.json,yaml).
Leave empty to use theme color.goStructTags.colors.valuestring- override color for tag values.
Leave empty to use theme color.goStructTags.colors.optionstring- override color for tag options (after=).
Leave empty to use theme color.goStructTags.colors.separatorstring- override color for tag separators (,).
Leave empty to use theme color.
{
// Always put json and yaml first, then sort the rest alphabetically
"goStructTags.sortMode": "alphabetical",
"goStructTags.sortPriority": ["json", "yaml"],
// Auto-sort and align on every save
"goStructTags.autoSortOnSave": true,
"goStructTags.autoAlignOnSave": true
}Color overrides accept any CSS color value (#rrggbb, rgba(...),
theme token color, etc.).
Syntax highlighting works via TextMate grammar injection into Go raw string literals. Colors depend entirely on how your active theme maps the underlying token scopes - the extension does not hardcode any colors by default.
Scope mapping used:
- Key (
json,yaml, …) ->entity.name.tag - Value (quoted string content) ->
string.quoted.double - Option key (before
=) ->variable.other =operator ->keyword.operator- Option value (after
=) ->constant.numeric - Separator (
,) ->comment
Themes known to color all parts well: Monokai, One Dark Pro, Dracula, Tokyo Night, Catppuccin.
Themes with partial support (keys and values visible, options highlighted): Default Dark+, Default Light+.
If your theme shows missing or incorrect colors — for example all parts blending into the surrounding string color — configure overrides directly. The colors below match the Default Dark+ palette:
{
"goStructTags.colors.key": "#4EC9B0",
"goStructTags.colors.value": "#CE9178",
"goStructTags.colors.option": "#B5CEA8",
"goStructTags.colors.separator": "#6A9955"
}For Default Light+:
{
"goStructTags.colors.key": "#267F99",
"goStructTags.colors.value": "#A31515",
"goStructTags.colors.option": "#098658",
"goStructTags.colors.separator": "#008000"
}
