make gofumpt default formatter (replacing golines)

pull/429/merge
ray-x 2 months ago
parent 3c497f6e5e
commit 9ac3e6faa3

@ -780,7 +780,7 @@ require('go').setup({
go='go', -- go command, can be go[default] or go1.18beta1
goimport='gopls', -- goimport command, can be gopls[default] or either goimport or golines if need to split long lines
gofmt = 'gofumpt', --gofmt cmd,
max_line_len = 128, -- max line length in golines format, Target maximum line length for golines
max_line_len = 0, -- max line length in golines format, Target maximum line length for golines
tag_transform = false, -- can be transform option("snakecase", "camelcase", etc) check gomodifytags for details and more options
tag_options = 'json=omitempty', -- sets options sent to gomodifytags, i.e., json=omitempty
gotests_template = "", -- sets gotests -template parameter (check gotests for details)
@ -909,7 +909,6 @@ return {
go = "go", -- set to go1.18beta1 if necessary
goimport = "gopls", -- if set to 'gopls' will use gopls format, also goimport
gofmt = "gofumpt", -- if set to gopls will use gopls format
max_line_len = 120
null_ls_document_formatting_disable = true
}
```
@ -1274,7 +1273,6 @@ lua <<EOF
require 'go'.setup({
goimport = 'gopls', -- if set to 'gopls' will use golsp format
gofmt = 'gopls', -- if set to gopls will use golsp format
max_line_len = 120,
tag_transform = false,
test_dir = '',
comment_placeholder = '  ',

@ -10,7 +10,7 @@ _GO_NVIM_CFG = {
goimport = 'gopls', -- if set to 'gopls' will use gopls format, also goimport
fillstruct = 'gopls',
gofmt = 'gofumpt', -- if set to gopls will use gopls format
max_line_len = 128,
max_line_len = 0,
tag_transform = false,
tag_options = 'json=omitempty',
@ -158,9 +158,6 @@ function go.setup(cfg)
vim.notify('go.nvim master branch requires nvim 0.9', vim.log.levels.WARN)
end
cfg = cfg or {}
if cfg.max_len then
vim.notify('go.nvim max_len renamed to max_line_len', vim.log.levels.WARN)
end
if cfg.lsp_diag_hdlr ~= nil then
vim.notify('go.nvim lsp_diag_hdlr deprecated, use diagnostic.hdlr', vim.log.levels.WARN)
end
@ -191,6 +188,10 @@ function go.setup(cfg)
end
_GO_NVIM_CFG = vim.tbl_deep_extend('force', _GO_NVIM_CFG, cfg)
if _GO_NVIM_CFG.max_line_len > 0 and _GO_NVIM_CFG.gofmt ~= 'golines' then
vim.notify('go.nvim max_line_len only effective when gofmt is golines', vim.log.levels.WARN)
end
require('go.commands').add_cmds()
vim.defer_fn(function()
require('go.project').load_project()

@ -1,9 +1,7 @@
-- golines A golang formatter that fixes long lines
-- golines + goimport
local api = vim.api
local utils = require('go.utils')
local log = utils.log
local max_len = _GO_NVIM_CFG.max_line_len or 120
local max_len = _GO_NVIM_CFG.max_line_len or 128
local gofmt = _GO_NVIM_CFG.gofmt or 'gofumpt'
local vfn = vim.fn
local write_delay = 10
@ -13,10 +11,11 @@ end
local install = require('go.install').install
local gofmt_args = _GO_NVIM_CFG.gofmt_args
or {
or gofmt == 'golines' and {
'--max-len=' .. tostring(max_len),
'--base-formatter=' .. gofmt,
'--base-formatter=gofumpt',
}
or {}
local goimport_args = _GO_NVIM_CFG.goimport_args
or {
@ -88,7 +87,7 @@ local run = function(fmtargs, bufnr, cmd)
on_exit = function(_, data, _) -- id, data, event
-- log(vim.inspect(data) .. "exit")
if data ~= 0 then
return vim.notify('golines failed ' .. tostring(data), vim.log.levels.ERROR)
return vim.notify(cmd .. ' failed ' .. tostring(data), vim.log.levels.ERROR)
end
old_lines = nil
vim.defer_fn(function()
@ -127,10 +126,6 @@ M.gofmt = function(...)
utils.warn('installing ' .. gofmt .. ' please retry after installation')
return
end
if not install('golines') then
utils.warn('installing golines , please rerun format after install finished')
return
end
local a = {}
utils.copy_array(gofmt_args, a)
local fmtcmd

@ -5,7 +5,6 @@ return {
go = "go", -- set to go1.18beta1 if necessary
goimport = "gopls", -- if set to 'gopls' will use gopls format, also goimport
gofmt = "gofumpt", -- if set to gopls will use gopls format
max_line_len = 120,
tag_transform = false,
test_dir = "",
sign_priority = 5,

Loading…
Cancel
Save