[goimport->goimports] Enduring the frustration of a longstanding typo, I've finally resolved to correct it. The change updates "goimport" to "goimport," including all related documentation and tests.
Additionally, I've set gopls as the default tool for both gofmt and goimports. This integration will be quicker than executing a separate command in the background and analyzing its output.
@ -10,28 +11,31 @@ The plugin covers most features required for a gopher.
- Perproject setup. Allows you setup plugin behavior per project based on project files(launch.json, .gonvim)
- Perproject setup. Allows you setup plugin behavior per project based on project files(launch.json, .gonvim)
- Async jobs with libuv
- Async jobs with libuv
- Syntax highlight & Texobject: Native treesitter support is faster and more accurate. All you need is a theme support treesitter, try
- Syntax highlight & Texobject: Native treesitter support is faster and more accurate. All you need is a theme support
[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)
- 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
there are quite a few listed in [awesome-neovim](https://github.com/rockerBOO/awesome-neovim)
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)
- 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 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 [Dap UI](https://github.com/rcarriga/nvim-dap-ui). Go adapter included, zero config for your debug setup.
- 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.
- 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 suppress golint
- Comments: Add autodocument for your package/function/struct/interface. This feature is unique and can help you
errors...
suppress golint 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
for more info go.nvim support launch debuger from vscode-go .vscode/launch.json configurations If launch.json is valid,
go.nvim support launch debuger from vscode-go .vscode/launch.json configurations
run `GoDebug` will launch from the launch.json configuration.
If launch.json is valid, run `GoDebug` will launch from the launch.json configuration.
### Inlay hints
### Inlay hints
@ -638,22 +622,18 @@ 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!
- ["x]GoJson2Struct! Visual select the json and run `GoJson2Struct youStructName` -bang will put result to register `a`
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}
- GoEnv {filename} By default load .env file in current directory, if you want to load other file, use {filename} option
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
create return value for current function e.g. if we have
e.g. if we have
```go
```go
func Foo() (int, error) {
func Foo() (int, error) {
@ -678,28 +658,23 @@ if err != nil {
### Rename modules
### Rename modules
- Gomvp
- Gomvp Rename module name in under cursor e.g. Gomvp Gomvp old_mod_name Gomvp old_mod_name new_mod_name
Rename module name in under cursor
e.g.
Gomvp
Gomvp old_mod_name
Gomvp old_mod_name new_mod_name
### govulncheck
### govulncheck
- GoVulnCheck {arguments}
- GoVulnCheck {arguments} Run govulncheck on current project
Run govulncheck on current project
### goenum
### goenum
- Goenum {arguments}
- Goenum {arguments} Run goenum on current project
Run goenum on current project
### gonew
### gonew
- GoNew {filename}
- GoNew {filename} Create new go file. It will use template file. e.g. `GoNew ./pkg/string.go` will create string.go
Create new go file. It will use template file. e.g. `GoNew ./pkg/string.go` will create string.go with template file
with template file GoNew also support using `gonew` command to create new file with template file
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 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
### ginkgo
### ginkgo
@ -745,11 +720,10 @@ 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
@ -778,8 +752,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
goimport='gopls', -- goimport command, can be gopls[default] or either goimport or golines if need to split long lines
goimports ='gopls', -- goimports command, can be gopls[default] or either goimports or golines if need to split long lines
gofmt = 'gofumpt', --gofmt cmd,
gofmt = 'gopls', -- gofmt through gopls: alternative is gofumpt, goimports, golines, gofmt, etc
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
@ -792,7 +766,8 @@ 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 = false, -- true: set default gofmt in gopls format to gofumpt
lsp_gofumpt = true, -- 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
@ -887,12 +862,11 @@ require('go').setup({
})
})
```
```
You will need to add keybind yourself:
You will need to add keybind yourself: e.g
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
@ -907,7 +881,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
goimport = "gopls", -- if set to 'gopls' will use gopls format, also goimport
goimports = "gopls", -- if set to 'gopls' will use gopls format, also goimports
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
}
}
@ -917,8 +891,7 @@ 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.
I did not provide textobject support in the plugin. Please use treesitter textobject plugin. My treesitter config:
My treesitter config:
```lua
```lua
require "nvim-treesitter.configs".setup {
require "nvim-treesitter.configs".setup {
@ -1015,26 +988,33 @@ My treesitter config:
}
}
}
}
```
```
</details>
</details>
## LuaSnip supports
## LuaSnip supports
go.nvim provides a better snippet support for go.
go.nvim provides a better snippet support for go. Please check
Please check [snippets for all languages](https://github.com/ray-x/go.nvim/blob/master/lua/snips/all.lua)
[snippets for all languages](https://github.com/ray-x/go.nvim/blob/master/lua/snips/all.lua) and
and [snippets for go](https://github.com/ray-x/go.nvim/blob/master/lua/snips/go.lua)
[snippets for go](https://github.com/ray-x/go.nvim/blob/master/lua/snips/go.lua)
For a video demo, please check this:
For a video demo, please check this: [go.nvim new features work through](https://www.youtube.com/watch?v=tsLnEfYTgcM)
[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) and [TJ's Introduction to LuaSnip](https://www.youtube.com/watch?v=Dn800rlPIho)
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)
## 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 [navigator.lua](https://github.com/ray-x/navigator.lua) which can auto setup all lsp clients and provides a better GUI.
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.
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.
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>