A GoLang deep-completion
source for nvim-cmp / blink.cmp, that works alongside cmp-nvim-lsp / blink.cmp's LSP source and provides completion suggestions for "UNIMPORTED LOCAL, INTERNAL, AND VENDORED PACKAGES ONLY".
At the time of writing, the GoLang Language Server (gopls@v0.18.1
) doesn't seem to support deep completions for unimported pacakges. For example, with deep completion enabled, typing 'cha'
could suggest 'rand.NewChaCha8()'
as a possible completion option - but that is not the case no matter how high the completion budget is set for gopls
.
Query gopls's
workspace/symbol
endpoint, cache the results using sqlite
, convert the resulting SymbolInformation
into completionItemKinds
, filter the results to only include the ones that are unimported, then finally feed them back into nvim-cmp
/ blink.cmp
- Note: Due to how gopls indexes packages, completions for standard library packages are not available until at least one of them is manually imported.
{
"hrsh7th/nvim-cmp",
dependencies = {
{ "samiulsami/cmp-go-deep", dependencies = { "kkharji/sqlite.lua" } },
},
...
require("cmp").setup({
sources = {{
name = "go_deep",
---@module "cmp_go_deep"
---@type cmp_go_deep.Options
option = {
-- See below for configuration options
},
}},
})
}
{
"saghen/blink.cmp",
dependencies = {
{ "samiulsami/cmp-go-deep", dependencies = { "kkharji/sqlite.lua" } },
{ "saghen/blink.compat" },
},
opts = {
sources = {
default = {
"go_deep",
},
providers = {
go_deep = {
name = "go_deep",
module = "blink.compat.source",
---@module "cmp_go_deep"
---@type cmp_go_deep.Options
opts = {
-- See below for configuration options
},
},
},
},
},
}
{
-- Enable/disable timeout notifications.
timeout_notifications = true,
-- How to get documentation for Go symbols.
-- options:
-- "hover" - LSP 'textDocument/hover'. Prettier.
-- "regex" - faster and simpler.
get_documentation_implementation = "hover",
-- How to get the package names.
-- options:
-- "treesitter" - accurate but slower.
-- "regex" - faster but can fail in edge cases.
get_package_name_implementation = "regex",
-- Whether to exclude vendored packages from completions.
exclude_vendored_packages = false,
-- Timeout in milliseconds for fetching documentation.
-- Controls how long to wait for documentation to load.
documentation_wait_timeout_ms = 100,
-- Maximum time (in milliseconds) to wait before "locking-in" the current request and sending it to gopls.
debounce_gopls_requests_ms = 100
-- Maximum time (in milliseconds) to wait before "locking-in" the current request and loading data from cache.
debounce_cache_requests_ms = 250
-- Path to store the SQLite database
-- Default: "~/.local/share/nvim/cmp_go_deep.sqlite3"
db_path = vim.fn.stdpath("data") .. "/cmp_go_deep.sqlite3",
-- Maximum size for the SQLite database in bytes.
db_size_limit_bytes = 200 * 1024 * 1024, -- 200MB
}
- Cache results for faster completions.
- Cross-project cache sharing for internal packages
- Better memory usage
- Remove the indirect dependency on
cmp-nvim-lsp
orblink.cmp's
LSP source.