ray-x / go.nvim

G'day Nvimer, Joyful Gopher: Discover the Feature-Rich Go Plugin for Neovim
MIT License
2.05k stars 123 forks source link

'Buffer file://<filepath> newer than edits.' when importing things on neovim nightly (0.11.0) #473

Closed meinside closed 2 months ago

meinside commented 3 months ago

Hi, I'm not sure if it is a duplicated or known issue, but I'm facing this error message on neovim nightly:

Buffer file://<filepath> newer than edits.

when importing missing packages by saving the go file, or by running :GoImports manually.

The error goes away after re-opening the file.

Here is the (not so) minimal neovim config file to reproduce the problem:

local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim'
if not vim.uv.fs_stat(lazypath) then
  vim.fn.system({
    'git',
    'clone',
    '--filter=blob:none',
    'https://github.com/folke/lazy.nvim.git',
    '--branch=stable',
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)

require'lazy'.setup({
  {
    'ray-x/go.nvim', config = function()
      require'go'.setup {
        gofmt = 'gopls',
        lsp_inlay_hints = { enable = false },
      }

      vim.api.nvim_create_autocmd('BufWritePre', {
        pattern = '*.go',
        callback = function() require'go.format'.goimports() end,
        group = vim.api.nvim_create_augroup('GoFormat', {}),
      })
    end,
    event = { 'CmdlineEnter' },
    ft = { 'go', 'gomod' },
    build = ':lua require("go.install").update_all_sync()',
    dependencies = {
      'ray-x/guihua.lua',
      'neovim/nvim-lspconfig',
      'nvim-treesitter/nvim-treesitter',
    },
  },
}, {})

-- lspconfig
local lspconfig = require'lspconfig'
lspconfig['gopls'].setup {
  on_attach = function(client, bufnr)
    vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')

    if client.server_capabilities.document_formatting then
      vim.api.nvim_create_autocmd('BufWritePre', {
        callback = function() vim.lsp.buf.format { async = false } end,
      })
    end
  end,
}

Of course, it is working as expected in the stable version of neovim.

My neovim version: NVIM v0.11.0-dev-168+ge20c5fba2 Build type: RelWithDebInfo LuaJIT 2.1.1716656478

ray-x commented 2 months ago

I failed to reproduce this with your config. I have a feeling this is caused by format plugins you installed What happens if you removes

    if client.server_capabilities.document_formatting then
      vim.api.nvim_create_autocmd('BufWritePre', {
        callback = function() vim.lsp.buf.format { async = false } end,
      })
    end
meinside commented 2 months ago

Oh, I cannot reproduce this with the current nightly(v0.11.0-dev-483+gf93ecd276).

Maybe it was due to the bug of neovim itself.