Skip to content

Commit ca6c532

Browse files
authored
Merge pull request #3634 from matthewhughes934/support-broader-go-versions
Update syntax for version in Go mod file directive
2 parents aa99723 + f98a2ed commit ca6c532

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

autoload/go/highlight_test.vim

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,50 @@ function! Test_gomodToolchainVersion_invalid_highlight() abort
784784
endtry
785785
endfunc
786786

787+
function! Test_gomodGoVersion() abort
788+
try
789+
syntax on
790+
791+
let g:go_gopls_enabled = 0
792+
let l:wd = getcwd()
793+
let l:dir = gotest#write_file('gomodtest/go.mod', [
794+
\ 'module github.com/fatih/vim-go',
795+
\ '',
796+
\ 'go 1.20',
797+
\ 'go 1.21',
798+
\ 'go 1.21rc2',
799+
\ 'go 1.21.1',
800+
\ ''])
801+
802+
let l:lineno = 3
803+
let l:lineclose = line('$')
804+
while l:lineno < l:lineclose
805+
let l:line = getline(l:lineno)
806+
let l:split_idx = stridx(l:line, ' ')
807+
let l:idx = len(l:line) - 1
808+
let l:col = col([l:lineno, '$']) - 1
809+
810+
while l:idx > l:split_idx
811+
call cursor(l:lineno, l:col)
812+
let l:synname = synIDattr(synID(l:lineno, l:col, 1), 'name')
813+
let l:errlen = len(v:errors)
814+
815+
call assert_equal('gomodGoVersion', l:synname, 'version on line ' . l:lineno . ' and col ' . l:col)
816+
if l:errlen < len(v:errors)
817+
break
818+
endif
819+
820+
let l:col -= 1
821+
let l:idx -= 1
822+
endwhile
823+
let l:lineno += 1
824+
endwhile
825+
826+
finally
827+
call go#util#Chdir(l:wd)
828+
call delete(l:dir, 'rf')
829+
endtry
830+
endfunc
787831

788832
" restore Vi compatibility settings
789833
let &cpo = s:cpo_save

syntax/gomod.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ syntax match gomodToolchainVersion "go1\(.\d\+\)\{,2\}\(rc\d\+\)\?\([ \t-].*\)\?
6161
highlight default link gomodToolchainVersion Identifier
6262

6363
" match go versions
64-
syntax match gomodGoVersion "1\.\d\+" contained
64+
syntax match gomodGoVersion "\(1.\d\+\)\(\(.\d\+\)\|\(rc\d\+\)\)\?" contained
6565
highlight default link gomodGoVersion Identifier
6666

6767
" highlight versions:

0 commit comments

Comments
 (0)