Skip to content

Commit

Permalink
Merge pull request #3634 from matthewhughes934/support-broader-go-ver…
Browse files Browse the repository at this point in the history
…sions

Update syntax for version in Go mod file directive
  • Loading branch information
bhcleek authored Jan 22, 2024
2 parents aa99723 + f98a2ed commit ca6c532
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
44 changes: 44 additions & 0 deletions autoload/go/highlight_test.vim
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,50 @@ function! Test_gomodToolchainVersion_invalid_highlight() abort
endtry
endfunc

function! Test_gomodGoVersion() abort
try
syntax on

let g:go_gopls_enabled = 0
let l:wd = getcwd()
let l:dir = gotest#write_file('gomodtest/go.mod', [
\ 'module github.com/fatih/vim-go',
\ '',
\ 'go 1.20',
\ 'go 1.21',
\ 'go 1.21rc2',
\ 'go 1.21.1',
\ ''])

let l:lineno = 3
let l:lineclose = line('$')
while l:lineno < l:lineclose
let l:line = getline(l:lineno)
let l:split_idx = stridx(l:line, ' ')
let l:idx = len(l:line) - 1
let l:col = col([l:lineno, '$']) - 1

while l:idx > l:split_idx
call cursor(l:lineno, l:col)
let l:synname = synIDattr(synID(l:lineno, l:col, 1), 'name')
let l:errlen = len(v:errors)

call assert_equal('gomodGoVersion', l:synname, 'version on line ' . l:lineno . ' and col ' . l:col)
if l:errlen < len(v:errors)
break
endif

let l:col -= 1
let l:idx -= 1
endwhile
let l:lineno += 1
endwhile

finally
call go#util#Chdir(l:wd)
call delete(l:dir, 'rf')
endtry
endfunc

" restore Vi compatibility settings
let &cpo = s:cpo_save
Expand Down
2 changes: 1 addition & 1 deletion syntax/gomod.vim
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ syntax match gomodToolchainVersion "go1\(.\d\+\)\{,2\}\(rc\d\+\)\?\([ \t-].*\)\?
highlight default link gomodToolchainVersion Identifier

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

" highlight versions:
Expand Down

0 comments on commit ca6c532

Please sign in to comment.