Skip to content

Commit f4260d8

Browse files
squash! Add syntax support for toolchain directive
Update Re following https://pkg.go.dev/golang.org/x/[email protected]/modfile#ToolchainRE
1 parent 92af479 commit f4260d8

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

autoload/go/highlight_test.vim

+9-5
Original file line numberDiff line numberDiff line change
@@ -680,11 +680,14 @@ function! Test_gomodToolchainVersion_highlight() abort
680680
let l:dir = gotest#write_file('gomodtest/go.mod', [
681681
\ 'module github.com/fatih/vim-go',
682682
\ '',
683+
\ 'toolchain default',
684+
\ 'toolchain go1',
685+
\ 'toolchain go1',
683686
\ 'toolchain go1.21',
684687
\ 'toolchain go1.21rc3',
685688
\ 'toolchain go1.21',
686689
\ 'toolchain go1.21.3-somesuffix',
687-
\ 'toolchain go1.21rc4-somesuffix more suffix',
690+
\ 'toolchain go1.21rc2-somesuffix',
688691
\ ''])
689692

690693
let l:lineno = 3
@@ -734,11 +737,12 @@ function! Test_gomodToolchainVersion_invalid_highlight() abort
734737
let l:dir = gotest#write_file('gomodtest/go.mod', [
735738
\ 'module github.com/fatih/vim-go',
736739
\ '',
737-
\ 'toolchain go1.21.1rc2',
738-
\ 'toolchain go1.21abc',
740+
\ 'toolchain go2',
741+
\ 'toolchain go1.21.1.4',
742+
\ 'toolchain go1.21.1blah',
739743
\ 'toolchain go1.21!some-suffix',
740-
\ 'toolchain 1.21rc2',
741-
\ 'toolchain 1.21.3',
744+
\ 'toolchain go1.21 some-suffix',
745+
\ 'toolchain something-else',
742746
\ ''])
743747

744748
let l:lineno = 3

syntax/gomod.vim

+8-6
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,23 @@ syntax region gomodComment start="//" end="$" contains=@Spell
4141
highlight default link gomodComment Comment
4242

4343
" make sure quoted import paths are higlighted
44-
syntax region gomodString start=+"+ skip=+\\\\\|\\"+ end=+"+
45-
highlight default link gomodString String
44+
syntax region gomodString start=+"+ skip=+\\\\\|\\"+ end=+"+
45+
highlight default link gomodString String
4646

4747
" replace operator is in the form of '=>'
4848
syntax match gomodReplaceOperator "\v\=\>"
4949
highlight default link gomodReplaceOperator Operator
5050

51-
" match toolchain versions, per https://go.dev/doc/toolchain#version, e.g.
52-
"
51+
" match toolchain versions, based on https://go.dev/doc/toolchain#version,
52+
" and https://pkg.go.dev/golang.org/x/[email protected]/modfile#ToolchainRE
53+
syntax match gomodToolchainVersion "default$" contained
54+
syntax match gomodToolchainVersion "go1$" contained
5355
" * go1.X.Y
5456
" * go1.X
5557
" * go1.XrcN
58+
" * go1.XrcN-somesuffix
5659
" * go1.X.Y-somesuffix
57-
" * go1.XrcN-somesuffix more stuff
58-
syntax match gomodToolchainVersion "go1\.\d\+\(\(.\d\+\)\|\(rc\d\+\)\)\?\([ \t-].*\)\?" contained
60+
syntax match gomodToolchainVersion "go1\(\.\d\+\)\{,2\}\(rc\d\+\)\?\(-\([a-zA-Z0-9]\+\)\)\?" contained
5961
highlight default link gomodToolchainVersion Identifier
6062

6163
" match go versions

0 commit comments

Comments
 (0)