RRethy / vim-illuminate

illuminate.vim - (Neo)Vim plugin for automatically highlighting other uses of the word under the cursor using either LSP, Tree-sitter, or regex matching.
2.12k stars 44 forks source link

fix: check the buffer is valid or not #126

Closed XXiaoA closed 1 year ago

XXiaoA commented 1 year ago

Sometimes I use "Shatur/neovim-session-manager" to load a session, it will throw the errors because the buffer isn't valid

XXiaoA commented 1 year ago

This should live at the top of the callback we pass to vim.lsp.buf_request_all(.

like this:?

function M.initiate_request(bufnr, winid)
    local id = 1
    if vim.api.nvim_buf_is_valid(bufnr) and bufs[bufnr] then
        local prev_id, cancel_fn, _ = unpack(bufs[bufnr])
        pcall(cancel_fn)
        id = prev_id + 1
    end

    local cancel_fn = vim.lsp.buf_request_all(
        bufnr,
        ......
RRethy commented 1 year ago

No like this:

    local cancel_fn = vim.lsp.buf_request_all(
        bufnr,
        'textDocument/documentHighlight',
        vim.lsp.util.make_position_params(winid),
        function(client_results)
            if bufs[bufnr][1] ~= id then
                return
            end
            if not vim.api.nvim_buf_is_valid(bufnr) then
                bufs[bufnr][3] = {}
                return
            end
XXiaoA commented 1 year ago

OKay, done