diff --git a/README.md b/README.md index 9cafb44..7b6725c 100644 --- a/README.md +++ b/README.md @@ -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 < 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() diff --git a/lua/go/format.lua b/lua/go/format.lua index 14e322d..7f3ebf0 100644 --- a/lua/go/format.lua +++ b/lua/go/format.lua @@ -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 diff --git a/lua/go/project.lua b/lua/go/project.lua index a076416..cf897e7 100644 --- a/lua/go/project.lua +++ b/lua/go/project.lua @@ -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,