diff --git a/after/plugin/init.lua b/after/plugin/init.lua index 8abd1830..87817b88 100644 --- a/after/plugin/init.lua +++ b/after/plugin/init.lua @@ -35,3 +35,12 @@ vim.api.nvim_create_autocmd('FileType', { end end, }) + +local format_sync_grp = vim.api.nvim_create_augroup('GoFormat', {}) +vim.api.nvim_create_autocmd('BufWritePre', { + pattern = '*.go', + callback = function() + require('go.format').goimports() + end, + group = format_sync_grp, +}) diff --git a/init.lua b/init.lua index 033c0f4c..07ed46cd 100644 --- a/init.lua +++ b/init.lua @@ -548,7 +548,44 @@ require('lazy').setup { -- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/ local servers = { -- clangd = {}, - gopls = {}, + gopls = { + settings = { + gopls = { + gofumpt = true, + codelenses = { + gc_details = false, + generate = true, + regenerate_cgo = true, + run_govulncheck = true, + test = true, + tidy = true, + upgrade_dependency = true, + vendor = true, + }, + hints = { + assignVariableTypes = true, + compositeLiteralFields = true, + compositeLiteralTypes = true, + constantValues = true, + functionTypeParameters = true, + parameterNames = true, + rangeVariableTypes = true, + }, + analyses = { + fieldalignment = true, + nilness = true, + unusedparams = true, + unusedwrite = true, + useany = true, + }, + usePlaceholders = true, + completeUnimported = true, + staticcheck = true, + directoryFilters = { '-.git', '-.vscode', '-.idea', '-.vscode-test', '-node_modules' }, + semanticTokens = true, + }, + }, + }, pyright = {}, rust_analyzer = {}, docker_compose_language_service = {}, diff --git a/lazy-lock.json b/lazy-lock.json index 6d66f377..4e3a5a3d 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -8,6 +8,8 @@ "copilot.vim": { "branch": "release", "commit": "25f73977033c597d530c7ab0e211d99b60927d2d" }, "fidget.nvim": { "branch": "main", "commit": "c12f8a58ee472ce5983c3a3f3aad0ff6c49a6a83" }, "gitsigns.nvim": { "branch": "main", "commit": "e9c4187c3774a46df2d086a66cf3a7e6bea4c432" }, + "go.nvim": { "branch": "master", "commit": "cde0c7a110c0f65b9e4e6baf342654268efff371" }, + "guihua.lua": { "branch": "master", "commit": "225db770e36aae6a1e9e3a65578095c8eb4038d3" }, "harpoon": { "branch": "master", "commit": "ccae1b9bec717ae284906b0bf83d720e59d12b91" }, "hydra.nvim": { "branch": "master", "commit": "55de54543d673824435930ecf533256eea2e565b" }, "lazy.nvim": { "branch": "main", "commit": "1d451b4c2ce957da05e2123ce1a001804fc7ea96" }, diff --git a/lua/custom/plugins/go-nvim.lua b/lua/custom/plugins/go-nvim.lua new file mode 100644 index 00000000..9bdb5161 --- /dev/null +++ b/lua/custom/plugins/go-nvim.lua @@ -0,0 +1,14 @@ +return { + 'ray-x/go.nvim', + dependencies = { -- optional packages + 'ray-x/guihua.lua', + 'neovim/nvim-lspconfig', + 'nvim-treesitter/nvim-treesitter', + }, + config = function() + require('go').setup() + end, + event = { 'CmdlineEnter' }, + ft = { 'go', 'gomod' }, + build = ':lua require("go.install").update_all_sync()', -- if you need to install/update all binaries +}