Also allow to read the SDK version from `go.work` (#4555)
**What type of PR is this?**
Feature
**What does this PR do? Why is it needed?**
Extends `go_sdk.from_file` (#4305) to accept a `go_work` attribute
alongside the existing `go_mod` attribute. This allows modules to read
their SDK version from a `go.work` file, providing better integration
for workspace-based Go projects and maintaining consistency with the
existing `go.mod` support.
Version extraction follows the same rules as `go.mod`: the `toolchain`
directive takes precedence over the `go` directive.
**Which issues(s) does this PR fix?**
Fixes #4554.
**Other notes for review**
When the go line is omitted, `go.mod` has an implicit `go 1.16` line
while `go.work` has an implicit `go 1.18` line, as per the Go toolchain
documentation at https://go.dev/doc/toolchain#config.
The implementation reuses the existing parser by extracting common logic
into a shared `_version_from_go_file` function that both
`version_from_go_mod` and the new `version_from_go_work` call with
different default versions.
Tests follow the same pattern as `from_go_mod_file_test`, covering
toolchain precedence, minor version support, go-only directive, and
missing directives.
7 files changed