Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update syntax for version in Go mod file directive #3634

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions autoload/go/highlight_test.vim
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion syntax/gomod.vim
Original file line number Diff line number Diff line change
@@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is clearer with magic: \v(1.\d+)((.\d+)|(rc\d+))?. I think I've seen this used elsewhere in these syntax files so maybe a worthwhile change?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok without the magic.

highlight default link gomodGoVersion Identifier

" highlight versions: