diff --git a/init.lua b/init.lua index 0eb8d2c4..f9b5b3c5 100644 --- a/init.lua +++ b/init.lua @@ -587,7 +587,17 @@ require('mason-lspconfig').setup() -- define the property 'filetypes' to the map in question. local servers = { -- clangd = {}, - -- gopls = {}, + gopls = { + gopls = { + completeUnimported = true, + usePlaceholders = true, + analyses = { + unusedparams = true, + showdown = true, + unusedvariable = true, + }, + }, + }, -- pyright = {}, -- rust_analyzer = {}, -- tsserver = {}, diff --git a/lua/custom/plugins/README.md b/lua/custom/plugins/README.md new file mode 100644 index 00000000..96b29002 --- /dev/null +++ b/lua/custom/plugins/README.md @@ -0,0 +1,10 @@ +### NULL-LS + +`goland`: + +```shell +go install github.com/incu6us/goimports-reviser/v3@latest +go install mvdan.cc/gofumpt@latest +go install github.com/segmentio/golines@latest +``` + diff --git a/lua/custom/plugins/gopher.lua b/lua/custom/plugins/gopher.lua new file mode 100644 index 00000000..b2a581dd --- /dev/null +++ b/lua/custom/plugins/gopher.lua @@ -0,0 +1,12 @@ +return { + 'olexsmir/gopher.nvim', + ft = 'go', + config = function(_, opts) + require('gopher').setup(opts) + + vim.keymap.set("n", "gsj", "GoTagAdd json", { desc = '[G]o add [S]truct [J]SON' }) + end, + build = function() + vim.cmd [[silent! GoInstallDeps]] + end, +} diff --git a/lua/custom/plugins/null_ls.lua b/lua/custom/plugins/null_ls.lua new file mode 100644 index 00000000..bb2bdad8 --- /dev/null +++ b/lua/custom/plugins/null_ls.lua @@ -0,0 +1,31 @@ +return { + 'jose-elias-alvarez/null-ls.nvim', + ft = 'go', + config = function() + local null_ls = require('null-ls') + local augroup = vim.api.nvim_create_augroup('LspFormatting', {}) + + null_ls.setup { + sources = { + null_ls.builtins.formatting.goimports_reviser, + null_ls.builtins.formatting.gofumpt, + null_ls.builtins.formatting.golines, + }, + on_attach = function(client, bufnr) + if client.supports_method('textDocument/formatting') then + vim.api.nvim_clear_autocmds({ + group = augroup, + buffer = bufnr, + }) + vim.api.nvim_create_autocmd("BufWritePre", { + group = augroup, + buffer = bufnr, + callback = function() + vim.lsp.buf.format({ bufnr = bufnr }) + end, + }) + end + end + } + end, +}