Go
Go support is built in. It covers .go files and go.mod and go.work files.
| Feature | Provided by |
|---|---|
| Language server | gopls |
| Formatting | gopls. Format on save and organize imports are on by default. |
| Debugging | Delve |
Set up
Install Go from go.dev or with Homebrew (brew install go). Tyrn uses gopls from your PATH if there is one. Otherwise it installs gopls with go install the first time you open a Go file, so go must be on your PATH.
If gopls is not found after you install it yourself, add Go’s bin folder to your path, for example export PATH="$PATH:$HOME/go/bin" in ~/.zshrc.
By default Go files use tab indentation and run organize imports on format:
{ "languages": { "Go": { "format_on_save": "on", "hard_tabs": true, "code_actions_on_format": { "source.organizeImports": true } } }}Inlay hints
Turn hints on with inlay_hints.enabled, then choose which ones gopls sends:
{ "inlay_hints": { "enabled": true }, "lsp": { "gopls": { "initialization_options": { "hints": { "assignVariableTypes": true, "compositeLiteralFields": true, "compositeLiteralTypes": true, "constantValues": true, "functionTypeParameters": true, "parameterNames": true, "rangeVariableTypes": true } } } }}Code lens
Tyrn asks gopls for the test code lens, which adds run test and run benchmark links above test functions. Show code lenses with "code_lens": "on". To turn on more of them:
{ "code_lens": "on", "lsp": { "gopls": { "initialization_options": { "codelenses": { "test": true, "generate": true, "tidy": true, "upgrade_dependency": true, "vendor": true } } } }}Debugging
Press f4 to pick a Delve configuration, or add your own to .tyrn/debug.json. mode is "debug" for a package, "test" for tests and "exec" for a prebuilt binary.
[ { "label": "Run server", "adapter": "Delve", "request": "launch", "mode": "debug", "program": "./cmd/server" }, { "label": "Run integration tests", "adapter": "Delve", "request": "launch", "mode": "test", "program": ".", "buildFlags": ["-tags", "integration"] }]See Debugger.