2021-08-24 10:57:24 -07:00
|
|
|
local lspconfig = require "lspconfig"
|
2021-06-21 19:57:46 -05:00
|
|
|
lspconfig.gopls.setup {
|
2021-06-30 21:56:31 -05:00
|
|
|
on_attach = function(client, bufnr)
|
|
|
|
|
require "lsp_signature".on_attach({
|
2021-12-01 21:26:29 -08:00
|
|
|
bind = true,
|
2021-06-30 21:56:31 -05:00
|
|
|
-- floating_window = true,
|
|
|
|
|
--hint_enable = true,
|
|
|
|
|
fix_pos = true,
|
|
|
|
|
use_lspsaga = true,
|
2021-12-01 21:26:29 -08:00
|
|
|
handler_opts = {
|
|
|
|
|
border = "rounded" -- double, single, shadow, none
|
|
|
|
|
},
|
2021-06-30 21:56:31 -05:00
|
|
|
})
|
|
|
|
|
end,
|
2021-06-21 19:57:46 -05:00
|
|
|
cmd = {"gopls", "serve"},
|
|
|
|
|
settings = {
|
2021-08-24 10:57:24 -07:00
|
|
|
autostart = true,
|
2021-06-21 19:57:46 -05:00
|
|
|
gopls = {
|
|
|
|
|
analyses = {
|
|
|
|
|
unusedparams = true,
|
|
|
|
|
},
|
|
|
|
|
staticcheck = true,
|
|
|
|
|
},
|
|
|
|
|
},
|
2021-08-24 10:57:24 -07:00
|
|
|
autostart = true,
|
2021-06-21 19:57:46 -05:00
|
|
|
root_dir = lspconfig.util.root_pattern(".git","go.mod"),
|
|
|
|
|
init_options = {usePlaceholders = true, completeUnimported = true},
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-30 21:57:18 -05:00
|
|
|
|
2021-07-14 14:48:05 -05:00
|
|
|
------ Configre vim-go
|
2021-06-30 21:57:18 -05:00
|
|
|
-- Disable autocomplete since we already have it with native lsp.
|
|
|
|
|
vim.g.go_code_completion_enabled = 0
|
|
|
|
|
-- Disable gopls for the same reasons as above.
|
|
|
|
|
vim.g.go_gopls_enabled = 0
|
|
|
|
|
|
2022-01-09 13:58:55 -08:00
|
|
|
-- Simplify code when formatting.
|
|
|
|
|
vim.g.go_fmt_command = 'gofmt'
|
|
|
|
|
vim.g.go_fmt_options = {
|
|
|
|
|
gofmt = '-s',
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-30 21:57:18 -05:00
|
|
|
vim.g.go_imports_mode = 'goimports'
|
|
|
|
|
|
|
|
|
|
-- Could confilg with lsp saga, should experiment.
|
|
|
|
|
vim.g.go_doc_keywordprg_enabled = 0
|
|
|
|
|
|
|
|
|
|
-- Use my own universal mappings for lsp.
|
|
|
|
|
vim.g.go_def_mapping_enabled = 0
|
|
|
|
|
|
|
|
|
|
-- Use globally installed binaries first. (gopls) installed through brew.
|
|
|
|
|
vim.g.go_search_bin_path_first = 0
|
|
|
|
|
|
2021-07-14 14:48:05 -05:00
|
|
|
-- When auto-creating a template file, use the package rather than a file.
|
|
|
|
|
vim.g.go_template_use_pkg = 1
|
2021-06-30 21:57:18 -05:00
|
|
|
|
2021-07-14 14:48:05 -05:00
|
|
|
-- Configure folding.
|
|
|
|
|
-- vim.cmd("autocmd FileType go setlocal foldmethod=syntax")
|
|
|
|
|
-- vim.g.go_fmt_experimental = 1
|
2021-06-30 21:57:18 -05:00
|
|
|
|
2021-07-29 15:23:55 -05:00
|
|
|
-- Use a ruler for go files.
|
|
|
|
|
vim.cmd("autocmd FileType go setlocal colorcolumn=80")
|
2022-01-14 19:19:10 -08:00
|
|
|
-- Automatically add comment symbol on next line and wrap it.
|
|
|
|
|
vim.cmd("autocmd FileType go setlocal fo+=c fo+=r")
|
2021-07-29 15:23:55 -05:00
|
|
|
|
2021-07-14 14:48:05 -05:00
|
|
|
-- Highlights.
|
|
|
|
|
vim.g.go_highlight_operators = 1
|
|
|
|
|
vim.g.go_highlight_types = 1
|
|
|
|
|
vim.g.go_highlight_extra_types = 1
|
|
|
|
|
vim.g.go_highlight_functions = 1
|
|
|
|
|
vim.g.go_highlight_function_calls = 1
|