[aurora](https://github.com/ray-x/aurora), [starry.nvim](https://github.com/ray-x/starry.nvim). Also, there are quite a few listed in [awesome-neovim](https://github.com/rockerBOO/awesome-neovim)
there are quite a few listed in [awesome-neovim](https://github.com/rockerBOO/awesome-neovim)
- All the GoToXxx (E.g reference, implementation, definition, goto doc, peek code/doc etc) You need lspconfig setup. There are lots of posts on how to
- All the GoToXxx (E.g reference, implementation, definition, goto doc, peek code/doc etc) You need lspconfig setup.
set it up. You can also check my [navigator](https://github.com/ray-x/navigator.lua) gopls setup [lspconfig.lua](https://github.com/ray-x/navigator.lua/blob/master/lua/navigator/lspclient/clients.lua)
There are lots of posts on how to set it up. You can also check my [navigator](https://github.com/ray-x/navigator.lua)
- gopls commands: e.g. fillstruct, organize imports, list modules, list packages, gc_details, generate, change
- gopls commands: e.g. fillstruct, organize imports, list modules, list packages, gc_details, generate, change
signature, etc.
signature, etc.
- Runtime lint/vet/compile: Supported by LSP (once you set up your LSP client), GoLint with golangci-lint also supported
- Runtime lint/vet/compile: Supported by LSP (once you set up your LSP client), GoLint with golangci-lint also supported
- Build/Make/Test: Go.nvim provides support for these by an async job wrapper.
- Build/Make/Test: Go.nvim provides support for these by an async job wrapper.
- Test coverage: run test coverage and show coverage sign and function metrics
- Test coverage: run test coverage and show coverage sign and function metrics
- Dlv Debug: with [nvim-dap](https://github.com/mfussenegger/nvim-dap) and
- Dlv Debug: with [nvim-dap](https://github.com/mfussenegger/nvim-dap) and [Dap UI](https://github.com/rcarriga/nvim-dap-ui). Go adapter included, zero config for your debug setup.
[Dap UI](https://github.com/rcarriga/nvim-dap-ui). Go adapter included, zero config for your debug setup.
- Load vscode launch configuration
- Load vscode launch configuration
- Unit test: generate unit test framework with [gotests](https://github.com/cweill/gotests). Run test with
- Unit test: generate unit test framework with [gotests](https://github.com/cweill/gotests). Run test with
richgo/ginkgo/gotestsum/go test
richgo/ginkgo/gotestsum/go test
- Add and remove tag for struct with tag modify(gomodifytags)
- Add and remove tag for struct with tag modify(gomodifytags)
- Code format: Supports LSP format and GoFmt(with golines)
- Code format: Supports LSP format and GoFmt(with golines)
- CodeLens : gopls codelens and codelens action support
- CodeLens : gopls codelens and codelens action support
- Comments: Add autodocument for your package/function/struct/interface. This feature is unique and can help you
- Comments: Add autodocument for your package/function/struct/interface. This feature is unique and can help you suppress golint
suppress golint errors...
errors...
- Go to alternative go file (between test and source)
- Go to alternative go file (between test and source)
- Test with ginkgo, richgo inside floaterm (to enable floaterm, guihua.lua has to be installed)
- Test with ginkgo, richgo inside floaterm (to enable floaterm, guihua.lua has to be installed)
- Code refactor made easy: GoFixPlural, FixStruct, FixSwitch, Add comment, IfErr, ModTidy, GoGet, extract function/block with codeactions... Most of the tools are built on top of
with codeactions... Most of the tools are built on top of treesitter AST or go AST. Fast and accurate.
treesitter AST or go AST. Fast and accurate.
- GoCheat get go cheatsheet from [cheat.sh](https://cheat.sh/).
- GoCheat get go cheatsheet from [cheat.sh](https://cheat.sh/).
- Smart build tag detection when debug/run tests (e.g. `//go:build integration`)
- Smart build tag detection when debug/run tests (e.g. `//go:build integration`)
- Generate mocks with mockgen
- Generate mocks with mockgen
@ -49,9 +45,10 @@ The plugin covers most features required for a gopher.
## Installation
## Installation
Use your favorite package manager to install. The dependency `treesitter` (and optionally, treesitter-objects) should be
Use your favorite package manager to install. The dependency ` treesitter ` (and optionally, treesitter-objects)
installed the first time you use it. Also Run `TSInstall go` to install the go parser if not installed yet. `sed` is
should be installed the first time you use it.
recommended to run this plugin.
Also Run `TSInstall go` to install the go parser if not installed yet.
for more info go.nvim support launch debuger from vscode-go .vscode/launch.json configurations If launch.json is valid,
for more info
run `GoDebug` will launch from the launch.json configuration.
go.nvim support launch debuger from vscode-go .vscode/launch.json configurations
If launch.json is valid, run `GoDebug` will launch from the launch.json configuration.
### Inlay hints
### Inlay hints
@ -622,18 +638,22 @@ Here is a sample [launch.json](https://github.com/ray-x/go.nvim/blob/master/play
### Json to Go struct
### Json to Go struct
- ["x]GoJson2Struct! Visual select the json and run `GoJson2Struct youStructName` -bang will put result to register `a`
- ["x]GoJson2Struct!
Visual select the json and run `GoJson2Struct youStructName`
-bang will put result to register `a`
if ["x] specified, will put get json from clipboard
if ["x] specified, will put get json from clipboard
### Load Env file
### Load Env file
- GoEnv {filename} By default load .env file in current directory, if you want to load other file, use {filename} option
- GoEnv {filename}
By default load .env file in current directory, if you want to load other file, use {filename} option
### Generate return value
### Generate return value
- GoGenReturn
- GoGenReturn
create return value for current function e.g. if we have
create return value for current function
e.g. if we have
```go
```go
func Foo() (int, error) {
func Foo() (int, error) {
@ -658,23 +678,28 @@ if err != nil {
### Rename modules
### Rename modules
- Gomvp Rename module name in under cursor e.g. Gomvp Gomvp old_mod_name Gomvp old_mod_name new_mod_name
- Gomvp
Rename module name in under cursor
e.g.
Gomvp
Gomvp old_mod_name
Gomvp old_mod_name new_mod_name
### govulncheck
### govulncheck
- GoVulnCheck {arguments} Run govulncheck on current project
- GoVulnCheck {arguments}
Run govulncheck on current project
### goenum
### goenum
- Goenum {arguments} Run goenum on current project
- Goenum {arguments}
Run goenum on current project
### gonew
### gonew
- GoNew {filename} Create new go file. It will use template file. e.g. `GoNew ./pkg/string.go` will create string.go
- GoNew {filename}
with template file GoNew also support using `gonew` command to create new file with template file
Create new go file. It will use template file. e.g. `GoNew ./pkg/string.go` will create string.go with template file
[gonew cli](https://go.dev/blog/gonew), e.g `GoNew hello package_name/folder` is same as
GoNew also support using `gonew` command to create new file with template file [gonew cli](https://go.dev/blog/gonew), e.g `GoNew hello package_name/folder` is same as `gonew golang.org/x/example/hello package_name/folder` if package_name/folder not provided, a hello project will be created in current folder
`gonew golang.org/x/example/hello package_name/folder` if package_name/folder not provided, a hello project will be
created in current folder
### ginkgo
### ginkgo
@ -720,10 +745,11 @@ Also you can check telescope dap extension : nvim-telescope/telescope-dap.nvim
Sample vimrc for DAP
Sample vimrc for DAP
```viml
```viml
Plug 'mfussenegger/nvim-dap'
Plug 'mfussenegger/nvim-dap'
Plug 'rcarriga/nvim-dap-ui'
Plug 'rcarriga/nvim-dap-ui'
Plug 'theHamsta/nvim-dap-virtual-text'
Plug 'theHamsta/nvim-dap-virtual-text'
" Plug 'nvim-telescope/telescope-dap.nvim'
" Plug 'nvim-telescope/telescope-dap.nvim'
```
```
## Commands
## Commands
@ -752,8 +778,8 @@ require('go').setup({
disable_defaults = false, -- true|false when true set false to all boolean settings and replace all table
disable_defaults = false, -- true|false when true set false to all boolean settings and replace all table
-- settings with {}
-- settings with {}
go='go', -- go command, can be go[default] or go1.18beta1
go='go', -- go command, can be go[default] or go1.18beta1
goimports ='gopls', -- goimports command, can be gopls[default] or either goimports or golines if need to split long lines
goimport='gopls', -- goimport command, can be gopls[default] or either goimport or golines if need to split long lines
gofmt = 'gopls', -- gofmt through gopls: alternative is gofumpt, goimports, golines, gofmt, etc
gofmt = 'gofumpt', --gofmt cmd,
max_line_len = 0, -- max line length in golines format, Target maximum line length for golines
max_line_len = 0, -- max line length in golines format, Target maximum line length for golines
tag_transform = false, -- can be transform option("snakecase", "camelcase", etc) check gomodifytags for details and more options
tag_transform = false, -- can be transform option("snakecase", "camelcase", etc) check gomodifytags for details and more options
tag_options = 'json=omitempty', -- sets options sent to gomodifytags, i.e., json=omitempty
tag_options = 'json=omitempty', -- sets options sent to gomodifytags, i.e., json=omitempty
@ -766,8 +792,7 @@ require('go').setup({
-- false: do nothing
-- false: do nothing
-- if lsp_cfg is a table, merge table with with non-default gopls setup in go/lsp.lua, e.g.
-- if lsp_cfg is a table, merge table with with non-default gopls setup in go/lsp.lua, e.g.
lsp_gofumpt = true, -- true: set default gofmt in gopls format to gofumpt
lsp_gofumpt = false, -- true: set default gofmt in gopls format to gofumpt
-- false: do not set default gofmt in gopls format to gofumpt
lsp_on_attach = nil, -- nil: use on_attach function defined in go/lsp.lua,
lsp_on_attach = nil, -- nil: use on_attach function defined in go/lsp.lua,
-- when lsp_cfg is true
-- when lsp_cfg is true
-- if lsp_on_attach is a function: use this function as on_attach function for gopls
-- if lsp_on_attach is a function: use this function as on_attach function for gopls
@ -862,11 +887,12 @@ require('go').setup({
})
})
```
```
You will need to add keybind yourself: e.g
You will need to add keybind yourself:
e.g
```lua
```lua
vim.cmd("autocmd FileType go nmap <Leader><Leader>l GoLint")
vim.cmd("autocmd FileType go nmap <Leader><Leader>l GoLint")
vim.cmd("autocmd FileType go nmap <Leader>gc :lua require('go.comment').gen()")
vim.cmd("autocmd FileType go nmap <Leader>gc :lua require('go.comment').gen()")
```
```
## Project setup
## Project setup
@ -881,7 +907,7 @@ vim.g.null_ls_disable = true
return {
return {
go = "go", -- set to go1.18beta1 if necessary
go = "go", -- set to go1.18beta1 if necessary
goimports = "gopls", -- if set to 'gopls' will use gopls format, also goimports
goimport = "gopls", -- if set to 'gopls' will use gopls format, also goimport
gofmt = "gofumpt", -- if set to gopls will use gopls format
gofmt = "gofumpt", -- if set to gopls will use gopls format
null_ls_document_formatting_disable = true
null_ls_document_formatting_disable = true
}
}
@ -891,7 +917,8 @@ This will override your global `go.nvim` setup
## Text object
## Text object
I did not provide textobject support in the plugin. Please use treesitter textobject plugin. My treesitter config:
I did not provide textobject support in the plugin. Please use treesitter textobject plugin.
My treesitter config:
```lua
```lua
require "nvim-treesitter.configs".setup {
require "nvim-treesitter.configs".setup {
@ -988,38 +1015,26 @@ I did not provide textobject support in the plugin. Please use treesitter textob
}
}
}
}
```
```
</details>
</details>
## LuaSnip supports
## LuaSnip supports
go.nvim provides a better snippet support for go. Please check
go.nvim provides a better snippet support for go.
[snippets for all languages](https://github.com/ray-x/go.nvim/blob/master/lua/snips/all.lua) and
Please check [snippets for all languages](https://github.com/ray-x/go.nvim/blob/master/lua/snips/all.lua)
[snippets for go](https://github.com/ray-x/go.nvim/blob/master/lua/snips/go.lua)
and [snippets for go](https://github.com/ray-x/go.nvim/blob/master/lua/snips/go.lua)
For a video demo, please check this: [go.nvim new features work through](https://www.youtube.com/watch?v=tsLnEfYTgcM)
For a video demo, please check this:
[go.nvim new features work through](https://www.youtube.com/watch?v=tsLnEfYTgcM)
If you are not familiar with luasnip, please checkout [LuaSnip Tutorial](https://www.youtube.com/watch?v=ub0REXjhpmk)
If you are not familiar with luasnip, please checkout [LuaSnip Tutorial](https://www.youtube.com/watch?v=ub0REXjhpmk) and [TJ's Introduction to LuaSnip](https://www.youtube.com/watch?v=Dn800rlPIho)
and [TJ's Introduction to LuaSnip](https://www.youtube.com/watch?v=Dn800rlPIho)
## Nvim LSP setup
## Nvim LSP setup
go.nvim provided a better non-default setup for gopls (includes debounce, staticcheck, diagnosticsDelay etc)
go.nvim provided a better non-default setup for gopls (includes debounce, staticcheck, diagnosticsDelay etc)
This gopls setup provided by go.nvim works perfectly fine for most of the cases. You can also install
This gopls setup provided by go.nvim works perfectly fine for most of the cases. You can also install [navigator.lua](https://github.com/ray-x/navigator.lua) which can auto setup all lsp clients and provides a better GUI.
[navigator.lua](https://github.com/ray-x/navigator.lua) which can auto setup all lsp clients and provides a better GUI.
For diagnostic issue, you can use the default setup. There are also quite a few plugins that you can use to explore
issues, e.g. [navigator.lua](https://github.com/ray-x/navigator.lua),
[Nvim-tree](https://github.com/kyazdani42/nvim-tree.lua) and
[Bufferline](https://github.com/akinsho/nvim-bufferline.lua) also introduced lsp diagnostic hooks.
> [!IMPORTANT]
> I will integrate more gopls functions into go.nvim, please make sure you have the latest version installed
> Also, enable gopls experimental features if it is configure somewhere other than go.nvim
> Otherwise, set `lsp_cfg` to `true` in your go.nvim setup to enable gopls setup in go.nvim
For diagnostic issue, you can use the default setup. There are also quite a few plugins that you can use to explore issues, e.g. [navigator.lua](https://github.com/ray-x/navigator.lua), [folke/lsp-trouble.nvim](https://github.com/folke/lsp-trouble.nvim). [Nvim-tree](https://github.com/kyazdani42/nvim-tree.lua) and [Bufferline](https://github.com/akinsho/nvim-bufferline.lua) also introduced lsp diagnostic hooks.
<details>
<details>
<summary>Gopls default settings in go.nvim</summary>
<summary>Gopls default settings in go.nvim</summary>
@ -1106,9 +1121,6 @@ gopls = {
matcher = 'Fuzzy',
matcher = 'Fuzzy',
diagnosticsDelay = '500ms',
diagnosticsDelay = '500ms',
symbolMatcher = 'fuzzy',
symbolMatcher = 'fuzzy',
semanticTokens = true,
noSemanticTokens = true, -- disable semantic string tokens so we can use treesitter highlight injection
['local'] = get_current_gomod(),
['local'] = get_current_gomod(),
gofumpt = _GO_NVIM_CFG.lsp_gofumpt or false, -- true|false, -- turn on for new repos, gofmpt is good but also create code turmoils
gofumpt = _GO_NVIM_CFG.lsp_gofumpt or false, -- true|false, -- turn on for new repos, gofmpt is good but also create code turmoils
buildFlags = { '-tags', 'integration' },
buildFlags = { '-tags', 'integration' },
@ -1132,8 +1144,8 @@ gopls = {
end,
end,
},
},
}
}
```
```
</details>
</details>
## Integrate with mason-lspconfig
## Integrate with mason-lspconfig
@ -1142,13 +1154,16 @@ gopls = {
require("mason").setup()
require("mason").setup()
require("mason-lspconfig").setup()
require("mason-lspconfig").setup()
require('lspconfig').gopls.setup({
require('lspconfig').gopls.setup({
-- your gopls setup
gopls_cmd = {install_root_dir .. '/go/gopls'},
dap_debug = true,
dap_debug_gui = true
})
})
```
```
If you want to use gopls setup provided by go.nvim
If you want to use gopls setup provided by go.nvim
```lua
```lua
-- setup your go.nvim
-- setup your go.nvim
-- make sure lsp_cfg is disabled
-- make sure lsp_cfg is disabled
require("mason").setup()
require("mason").setup()
@ -1160,12 +1175,12 @@ require('go').setup{
local cfg = require'go.lsp'.config() -- config() return the go.nvim gopls setup
local cfg = require'go.lsp'.config() -- config() return the go.nvim gopls setup
require('lspconfig').gopls.setup(cfg)
require('lspconfig').gopls.setup(cfg)
```
```
## Highlighting for gomod, gosum, gohtmltmpl, gotmpl, gotexttmpl
## Highlighting for gomod, gosum, gohtmltmpl, gotmpl, gotexttmpl
You can install treesitter parser for gomod and gosum
You can install treesitter parser for gomod and gosum
```vim
```vim
:TSInstall gomod gosum
:TSInstall gomod gosum
```
```
@ -1195,6 +1210,7 @@ The plugin injects the tmpl to html syntax so you should see this: