#187 vim.lsp.buf.format missing in some version of neovim

pull/196/head
ray-x 2 years ago
parent 06c27c1cf5
commit bedc73166a

@ -18,6 +18,12 @@ local goimport_args = _GO_NVIM_CFG.goimport_args or {
"--base-formatter=goimports",
}
if vim.lsp.buf.format == nil then
vim.notify('the go.lsp.buf.format is not available, some feature is missing if you are running old version of neovim (<0.7.0)', vim.lsp.log_levels.WARN)
-- neovim < 0.7 only
require('go.lsp') -- this set default value of format
end
local run = function(fmtargs, bufnr, cmd)
log(fmtargs, bufnr, cmd)
bufnr = bufnr or 0

@ -9,13 +9,13 @@ end
if vim.lsp.buf.format == nil then
-- neovim < 0.7 only
vim.lsp.buf.format = function(options)
if options.async then
vim.lsp.buf.formatting()
else
vim.lsp.buf.formatting_sync()
if options.async then
vim.lsp.buf.formatting()
else
vim.lsp.buf.formatting_sync()
end
end
end
end
local codelens_enabled = false

@ -25,9 +25,7 @@ local function insert_result(result)
vim.cmd("write")
-- format(#inserts, curpos)
vfn.setpos(".", curpos)
vim.defer_fn(function()
vim.lsp.buf.format({ async = _GO_NVIM_CFG.lsp_fmt_async })
end, 300)
require('go.format').gofmt()
end
-- can only be fillstruct and fillswitch

Loading…
Cancel
Save