Skip to content

Commit de75537

Browse files
committed
Highlight more struct tag errors
1 parent a5550b6 commit de75537

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

syntax/go.vim

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ endif
6565

6666
" go:generate; see go help generate
6767
syn match goGenerateKW display contained /go:generate/
68-
syn match goGenerateVars contained /\v\$(GOARCH|GOOS|GOFILE|GOLINE|GOPACKAGE|DOLLAR)/
68+
syn match goGenerateVars contained /\v\$(GOARCH|GOOS|GOFILE|GOLINE|GOPACKAGE|GOROOT|DOLLAR|PATH)/
6969
syn region goGenerate excludenl contained matchgroup=goGenerateKW start="^//go:generate" end=/$/ contains=goGenerateVars,goGenerateKW
7070

7171
" go:build
@@ -83,13 +83,14 @@ syn match goCompilerDir excludenl display contained "\v^//go:%(nointer
8383
" Adding a space between the // and go: is an error.
8484
syn match goDirectiveError excludenl contained "^// go:.\+$"
8585

86-
" Build tags; standard build tags from cmd/dist/build.go and go doc go/build.
86+
" Build tags:
87+
" go tool dist list | sed 's!/!\n!' | sort -u | tr '\n' ' '
8788
syn match goOldBuildTag display contained "^// +build.*"
88-
syn keyword goStdBuildTags contained
89-
\ 386 amd64 amd64p32 arm arm64 mips mipsle mips64 mips64le ppc ppc64 ppc64le
90-
\ riscv64 s390x wasm darwin dragonfly hurd js linux android solaris
91-
\ freebsd nacl netbsd openbsd plan9 windows gc gccgo cgo race
9289
syn match goVersionBuildTags contained /\v<go1\.[0-9]{1,2}>[^.]/
90+
syn keyword goStdBuildTags contained
91+
\ gc gccgo cgo race
92+
\ 386 aix amd64 android arm arm64 darwin dragonfly freebsd illumos ios js linux loong64 mips mips64
93+
\ mips64le mipsle netbsd openbsd plan9 ppc64 ppc64le riscv64 s390x solaris wasip1 wasm windows
9394

9495
" cgo
9596
syn match goCgoError contained containedin=goComment "^\%(\/\/\)\?\s*#cgo .*"
@@ -100,7 +101,7 @@ syn match goCgo contained containedin=goComment /^\%(\/\/\)\?\s*#\s*include [<"]
100101
syn match goCgo contained containedin=goComment /\v^%(\/\/)?\s*#\s*%(ifdef \w+|ifndef \w+|else|endif)/
101102
syn match goCgo contained containedin=goComment /\v^%(\/\/)?\s*#cgo pkg-config:%( \f+)+/
102103
syn match goCgo contained containedin=goComment /\v^%(\/\/)?\s*#cgo
103-
\ %(!?%(386|amd64|amd64p32|arm|arm64|mips|mipsle|mips64|mips64le|ppc|ppc64|ppc64le|riscv64|s390x|wasm|darwin|dragonfly|hurd|js|linux|android|solaris|freebsd|nacl|netbsd|openbsd|plan9|windows|gc|gccgo)[, ]*)*
104+
\ %(!?%(386|aix|amd64|android|arm|arm64|darwin|dragonfly|freebsd|illumos|ios|js|linux|loong64|mips|mips64|mips64le|mipsle|netbsd|openbsd|plan9|ppc64|ppc64le|riscv64|s390x|solaris|wasip1|wasm|windows|gc|gccgo)[, ]*)*
104105
\%(CFLAGS|CPPFLAGS|CXXFLAGS|FFLAGS|LDFLAGS):.+/
105106

106107
" String escapes.
@@ -122,15 +123,16 @@ else
122123
endif
123124

124125
" Structs and struct tags.
125-
" TODO: also highlight lack of quote, and attr space error: `json:foo, omitempty`
126126
syn region goStruct start=/struct \?{/ end=/}/ transparent containedin=goBlock contains=ALLBUT,goParen,goBlock,goStructTagOpt
127127
syn match goStructTag / `.*`\%(\s\|$\)/ contained containedin=goStruct
128-
syn match goStructTagError /\w\{-1,} *: *"/he=e-2 contained containedin=goStructTag
128+
syn match goStructTagError /\w\{-1,} *: *"/he=e-2 contained containedin=goStructTag " Space before/after :
129129
syn match goStructTagName /\w\{-1,}:\ze"/ contained containedin=goStruct,goStructTag
130+
syn match goStructTagError /\w\{-1,}:[^" ]\+/ contained containedin=goStructTag " Missing start quote
131+
syn match goStructTagError /\w\{-1,}:"[^" ]\+ / contained containedin=goStructTag " Missing end quote
130132
syn match goStructTagOpt /,\zs[^,"]\+/ contained containedin=goStructTag
131133

132134
if s:has('string-fmt')
133-
" TODO: this is a bit slow, but can't seem ot make it faster. Not sure if it's
135+
" This is a bit slow, but can't seem ot make it faster. Not sure if it's
134136
" possible.
135137
"
136138
" % not preceded by a %, followed by any of [-#0+ ]

0 commit comments

Comments
 (0)