Skip to content

Commit

Permalink
feat!: improve go development experience (#1226)
Browse files Browse the repository at this point in the history
* chore(go): replace vim-go with go.nvim.

Signed-off-by: ayamir <[email protected]>

* fix: install gopls by mason by default.

Signed-off-by: ayamir <[email protected]>

* feat(keymap): set `n|gi` to goto implementation.

Signed-off-by: ayamir <[email protected]>

* chore(keymap): use `gm` to jump to lsp implementations

Co-authored-by: 冷酔閑吟 <[email protected]>
Signed-off-by: Mohu <[email protected]>

* fixup: remove unused `map_cu`.

* chore: use gopls instead of null-ls to format.

Signed-off-by: ayamir <[email protected]>

* chore: add notes for config options.

Signed-off-by: ayamir <[email protected]>

* fixup: tidy settings for go.nvim and gopls.

* docs: update more notes for how to config go.nvim.

* chore: cleanup

Signed-off-by: Jint-lzxy <[email protected]>

* fix: enable only the options that are truly necessary

Signed-off-by: Jint-lzxy <[email protected]>

* fixup! chore: cleanup

* fix(gopls): invalid config entry

Signed-off-by: Jint-lzxy <[email protected]>

---------

Signed-off-by: ayamir <[email protected]>
Signed-off-by: Mohu <[email protected]>
Signed-off-by: Jint-lzxy <[email protected]>
Co-authored-by: 冷酔閑吟 <[email protected]>
Co-authored-by: neogtliu <[email protected]>
  • Loading branch information
3 people authored and CharlesChiuGit committed Apr 22, 2024
1 parent c0a47f9 commit d49179a
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lua/core/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ settings["lsp_deps"] = {
"jsonls",
"lua_ls",
"pylsp",
-- "gopls",
"gopls",
}

-- Set the general-purpose servers that will be installed during bootstrap here.
Expand Down
6 changes: 5 additions & 1 deletion lua/keymap/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local map_cmd = bind.map_cmd
local map_callback = bind.map_callback

local plug_map = {
["n|<A-f>"] = map_cmd("<Cmd>FormatToggle<CR>"):with_noremap():with_desc("Formater: Toggle format on save"),
["n|<A-f>"] = map_cmd("<Cmd>FormatToggle<CR>"):with_noremap():with_desc("formatter: Toggle format on save"),
}
bind.nvim_load_mapping(plug_map)

Expand Down Expand Up @@ -50,6 +50,10 @@ function mapping.lsp(buf)
["n|gd"] = map_cr("Glance definitions"):with_silent():with_buffer(buf):with_desc("lsp: Preview definition"),
["n|gD"] = map_cr("Lspsaga goto_definition"):with_silent():with_buffer(buf):with_desc("lsp: Goto definition"),
["n|gh"] = map_cr("Glance references"):with_silent():with_buffer(buf):with_desc("lsp: Show reference"),
["n|gm"] = map_cr("Glance implementations")
:with_silent()
:with_buffer(buf)
:with_desc("lsp: Show implementation"),
["n|gci"] = map_cr("Lspsaga incoming_calls")
:with_silent()
:with_buffer(buf)
Expand Down
2 changes: 1 addition & 1 deletion lua/modules/configs/completion/mason-lspconfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ M.setup = function()
min = severity_map[diagnostics_level],
},
} or false,
-- set update_in_insert to false bacause it was enabled by lspsaga
-- set update_in_insert to false because it was enabled by lspsaga
update_in_insert = false,
})

Expand Down
48 changes: 41 additions & 7 deletions lua/modules/configs/completion/servers/gopls.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,49 @@
-- https:/neovim/nvim-lspconfig/blob/master/lua/lspconfig/server_configurations/gopls.lua
return {
flags = { debounce_text_changes = 500 },
cmd = { "gopls", "-remote=auto" },
cmd = { "gopls", "-remote.debug=:0", "-remote=auto" },
filetypes = { "go", "gomod", "gosum", "gotmpl", "gohtmltmpl", "gotexttmpl" },
flags = { allow_incremental_sync = true, debounce_text_changes = 500 },
capabilities = {
textDocument = {
completion = {
contextSupport = true,
dynamicRegistration = true,
completionItem = {
commitCharactersSupport = true,
deprecatedSupport = true,
preselectSupport = true,
insertReplaceSupport = true,
labelDetailsSupport = true,
snippetSupport = true,
documentationFormat = { "markdown", "plaintext" },
resolveSupport = {
properties = {
"documentation",
"details",
"additionalTextEdits",
},
},
},
},
},
},
settings = {
gopls = {
staticcheck = true,
semanticTokens = true,
noSemanticString = true,
usePlaceholders = true,
analyses = {
nilness = true,
shadow = true,
unusedparams = true,
unusewrites = true,
completeUnimported = true,
symbolMatcher = "Fuzzy",
buildFlags = { "-tags", "integration" },
codelenses = {
generate = true,
gc_details = true,
test = true,
tidy = true,
vendor = true,
regenerate_cgo = true,
upgrade_dependency = true,
},
hints = {
assignVariableTypes = true,
Expand Down
21 changes: 21 additions & 0 deletions lua/modules/configs/lang/go.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
return function()
require("modules.utils").load_plugin("go", {
-- By default, we've turned off these options to prevent clashes with our gopls config
icons = false,
diagnostic = false,
lsp_cfg = false,
lsp_gofumpt = false,
lsp_keymaps = false,
lsp_codelens = false,
lsp_document_formatting = false,
lsp_inlay_hints = { enable = false },
-- DAP-related settings are also turned off here for the same reason
dap_debug = false,
dap_debug_keymap = false,
textobjects = false,
-- Miscellaneous options to seamlessly integrate with other plugins
trouble = true,
luasnip = false,
run_in_floaterm = false,
})
end

0 comments on commit d49179a

Please sign in to comment.