rcarriga / nvim-notify

A fancy, configurable, notification manager for NeoVim
MIT License
3.03k stars 81 forks source link

`E565: Not allowed to change text or change window` when triggering omnicompletion with a language server that doesn't support completion #205

Open heygarrett opened 1 year ago

heygarrett commented 1 year ago

When triggering omnicompletion with a language server that doesn't support completion a helpful message is displayed:

method textDocument/completion is not supported by any of the servers registered for the current buffer

But when nvim-notify is installed it causes an error instead:

E5108: Error executing lua ....repro/plugins/nvim-notify/lua/notify/render/default.lua:18: E565: Not allowed to change text or change window
stack traceback:
        [C]: in function 'nvim_buf_set_lines'
        ....repro/plugins/nvim-notify/lua/notify/render/default.lua:18: in function 'render'
        ...o/plugins/nvim-notify/lua/notify/service/buffer/init.lua:107: in function 'render'
        ...g/.repro/plugins/nvim-notify/lua/notify/service/init.lua:53: in function 'push'
        ...onfig/.repro/plugins/nvim-notify/lua/notify/instance.lua:77: in function 'notify'
        ...w/Cellar/neovim/0.9.1/share/nvim/runtime/lua/vim/lsp.lua:1963: in function 'buf_request'
        ...w/Cellar/neovim/0.9.1/share/nvim/runtime/lua/vim/lsp.lua:2140: in function <...w/Cellar/neovim/0.9.1/share/nvim/runtime/lua/vim/lsp.lua:2113>

Minimal repro.lua config:

local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "cache" }) do
    vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({
        "git",
        "clone",
        "--filter=blob:none",
        "https://github.com/folke/lazy.nvim.git",
        lazypath,
    })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
    "folke/tokyonight.nvim",
    -- add any other plugins here
    "https://github.com/nvim-lua/plenary.nvim",
    {
        "https://github.com/jose-elias-alvarez/null-ls.nvim",
        config = function()
            local null_ls = require("null-ls")
            null_ls.setup({
                sources = {
                    null_ls.builtins.diagnostics.fish,
                },
            })
        end,
    },
    {
        "https://github.com/rcarriga/nvim-notify",
        config = function() vim.notify = require("notify") end,
    },
}
require("lazy").setup(plugins, {
    root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here
vim.o.number = true

Steps to reproduce:

  1. The config needs a language server that doesn't support completion. I chose null-ls with the fish diagnostics source.
  2. nvim -u repro.lua config.fish (I'm using a fish file)
  3. Enter insert mode, type some text and then <c-x><c-o>

Expected behavior:

The helpful LSP message would be displayed

Actual behavior:

Error

Additional info:

NVIM v0.9.1 Build type: Release LuaJIT 2.1.0-beta3

system vimrc file: "$VIM/sysinit.vim" fall-back for $VIM: "/opt/homebrew/Cellar/neovim/0.9.1/share/nvim"

Run :checkhealth for more info

wookayin commented 12 months ago

I think nvim-notify's default implementation should be improved in a way that if vim is in [the fast event](https://neovim.io/doc/user/lua.html#vim.in_fast_event()), it should defer the execution.

A workaround would be:

-vim.notify = require("notify")
+vim.notify = vim.schedule_wrap(require("notify"))

BTW it may have some unwanted consequence, e.g., the ordering of async events can be slightly different than the invocation was made, due to vim.schedule.