fatih / vim-go

Go development plugin for Vim
https://www.patreon.com/bhcleek
Other
15.98k stars 1.45k forks source link

Add syntax support for toolchain directive #3633

Closed matthewhughes934 closed 8 months ago

matthewhughes934 commented 8 months ago

This directive was added to go.mod with Go 1.21[1] So that this directive can be highlighted in go.mod.

It's not entirely clear exactly what the fully supported syntax is. The docs[1] suggests any Go release version, e.g.

golang.org/x/mod gives a much more relaxed definition, requiring just that things match against the regex ^default$|^go1($|\.)[2]

Finally there's FromToolchain from the stdlib's internals for processing versions[3] which is broader than that from[1] but more limited than that from[2], supporting arbitrary suffixes (after any of " \t-") appended to the version, e.g.

The approach taken for the syntax matching here is closest to this final condition, and will not include some toolchain verison's that would be supported by the modfile regex, e.g.

Since these would be rejected by the go tool itself with an error like

go: invalid toolchain "go1.21.1blah" in go.mod

matthewhughes934 commented 8 months ago

can you add tests for this to autoload/go/highlight_test.vim? The first test in that file, Test_gomodVersion_highlight, is a good template to follow.

Oh, that's really nice to have some tests for the highlighting. I've added some new ones: 92af479

In addition to the comments I made inline

:thinking: I don't see any comments from you besides this one