nvim-cmp source providing the names of Go packages to import
https://github.com/user-attachments/assets/10058da8-d2b0-477e-bf15-ae14dbe6e11b
import
sectionInstall the plugin with your preferred package manager:
{
"hrsh7th/nvim-cmp",
dependencies = {
"Yu-Leo/cmp-go-pkgs",
},
config = function()
local cmp = require("cmp")
cmp.setup({
sources = {
{ name = "go_pkgs" },
},
})
end,
}
go
parser installed⚠️ Attention! The plugin won't work without it ⚠️
You need to add the following code next to other autocmds in your neovim config.
vim.api.nvim_create_autocmd({ "LspAttach" }, {
pattern = { "*.go" },
callback = function(args)
require("cmp_go_pkgs").init_items(args)
end,
})
This code defines the following behavior: at each LspAttach
event, the plugin will request a list of packages available for import from gopls
and save them to its cache. This is more efficient than sending requests to the LSP for each completion request. However, because of this, if you change or add new packages, they will be displayed in the previously opened buffer only if you reopen it or call :LspRestart
.
Like any other nvim-cmp source.
/
, it offers only those options that contain the incomplete line as a prefix/
, it offers all available optionsPRs and Issues are always welcome.
Author: @Yu-Leo
I took the code of this plugin as a basis and modified it to suit my needs.