Added the custom function for gofile

Signed-off-by: Marcin Woźniak <y0rune@aol.com>
This commit is contained in:
Marcin Woźniak 2022-09-21 20:30:34 +02:00
parent 7647860a5a
commit 2505fa3a54
Signed by: y0rune
GPG Key ID: F204C385F57EB348

View File

@ -533,6 +533,26 @@ map <F4> :setlocal spell! spelllang=pl<CR>
:command! Q q
:command! Wq wq
""""""""""""""""""""""""""""""""
" Custom functions
""""""""""""""""""""""""""""""""
lua <<EOF
function go_org_imports(wait_ms)
local params = vim.lsp.util.make_range_params()
params.context = {only = {"source.organizeImports"}}
local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params, wait_ms)
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
end
EOF
""""""""""""""""""""""""""""""""
" Files
""""""""""""""""""""""""""""""""
@ -575,6 +595,7 @@ autocmd BufRead,BufNewFile *.yaml let g:indentLine_char = '⦙'
" Go
autocmd BufRead *.go set noexpandtab
autocmd BufWritePre *.go lua go_org_imports()
" Conf
au BufNewFile,BufRead *.conf setfiletype conf