neovim/lua/lsp/go.lua

53 lines
1.8 KiB
Lua
Raw Normal View History

2023-05-05 17:10:35 +00:00
require("go").setup({
lsp_cfg = false,
})
2023-02-26 12:50:20 +00:00
local has_words_before = function()
2023-02-26 13:29:03 +00:00
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
2023-02-26 12:50:20 +00:00
end
local feedkey = function(key, mode)
2023-02-26 13:29:03 +00:00
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
2023-02-26 12:50:20 +00:00
end
local cmp = require("cmp")
cmp.setup({
2023-02-26 13:29:03 +00:00
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
end,
},
mapping = {
["<CR>"] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif vim.fn["vsnip#available"](1) == 1 then
feedkey("<Plug>(vsnip-expand-or-jump)", "")
elseif has_words_before() then
cmp.complete()
else
fallback() -- The fallback function sends a already mapped key. In this case, it's probably `<Tab>`.
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function()
if cmp.visible() then
cmp.select_prev_item()
elseif vim.fn["vsnip#jumpable"](-1) == 1 then
feedkey("<Plug>(vsnip-jump-prev)", "")
end
end, { "i", "s" }),
},
sources = cmp.config.sources({
{ name = "nvim_lsp" },
{ name = "vsnip" }, -- For vsnip users.
}, {
{ name = "buffer" },
}),
2023-02-26 12:50:20 +00:00
})
2023-05-05 17:10:35 +00:00
local cfg = require("go.lsp").config() -- config() return the go.nvim gopls setup
require("lspconfig").gopls.setup(cfg)