12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- local cmd, b, o = vim.cmd, vim.b, vim.o
- o.expandtab = false
- b.ale_linters = { "gopls", "govet", "staticcheck" }
- b.ale_fixers = {}
- b.ale_go_staticcheck_options = "-checks all"
- vim.api.nvim_create_autocmd("BufWritePre", {
- pattern = "*.go",
- callback = function()
- local params = vim.lsp.util.make_range_params()
- params.context = { only = { "source.organizeImports" } }
- local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params)
- for cid, res in pairs(result or {}) do
- for _, r in pairs(res.result or {}) do
- if r.edit then
- local enc = (vim.lsp.get_client_by_id(cid) or {}).offset_encoding or "utf-16"
- vim.lsp.util.apply_workspace_edit(r.edit, enc)
- end
- end
- end
- vim.lsp.buf.format({ async = false })
- end,
- })
- for _, x in ipairs({
-
-
- { "stru", [[<Esc>bitype <Esc>Astruct{<CR>}<Esc>O]] },
- { "iface", [[<Esc>bitype <Esc>Ainterface{<CR>}<Esc>O]] },
-
- { "func", [[<Esc>bifunc <Esc>A( xw ) {<CR>}<Esc>k$Txciw]] },
- { "fn", [[func(){ xw }<Esc>Txciw]] },
- { "enil", [[if err != nil {<CR>}<Esc>O]] },
- {
- "gomain",
- [[package main<CR><CR>import (<CR>"fmt"<CR>)<CR><CR>func main() {<CR>fmt.Println("Hello!")<CR>}<Esc>O]],
- },
- }) do
- cmd.inoreabbrev({ args = x })
- end
|