jose-elias-alvarez / null-ls.nvim

Use Neovim as a language server to inject LSP diagnostics, code actions, and more via Lua.
Other
3.64k stars 788 forks source link

[code action] Invalid `range["end"]` for `visual line` mode #1394

Open antosha417 opened 1 year ago

antosha417 commented 1 year ago

FAQ

Issues

Neovim Version

NVIM v0.8.1

Dev Version?

Operating System

MacOs

Minimal Config

-- this template is borrowed from nvim-lspconfig
local on_windows = vim.loop.os_uname().version:match("Windows")

local function join_paths(...)
  local path_sep = on_windows and "\\" or "/"
  local result = table.concat({ ... }, path_sep)
  return result
end

vim.g.loaded_remote_plugins = ""
vim.cmd([[set runtimepath=$VIMRUNTIME]])

local temp_dir = vim.loop.os_getenv("TEMP") or "/tmp"

vim.cmd("set packpath=" .. join_paths(temp_dir, "nvim", "site"))

local package_root = join_paths(temp_dir, "nvim", "site", "pack")
local install_path = join_paths(package_root, "packer", "start", "packer.nvim")
local compile_path = join_paths(install_path, "plugin", "packer_compiled.lua")

local null_ls_config = function()
  local null_ls = require("null-ls")
  -- add only what you need to reproduce your issue
  null_ls.setup({
      sources = {
          {
              name = "test_source",
              method = require("null-ls").methods.CODE_ACTION,
              filetypes = {},
              generator = {
                  fn = function(params)
                    return {
                        {
                            title = "print range code action params",
                            action = function()
                              print(vim.inspect(params))
                            end,
                        },
                    }
                  end,
              }
          }
      },
      debug = true,
  })
end

local function load_plugins()
  -- only add other plugins if they are necessary to reproduce the issue
  require("packer").startup({
      {
          "wbthomason/packer.nvim",
          {
              "jose-elias-alvarez/null-ls.nvim",
              requires = { "nvim-lua/plenary.nvim" },
              config = null_ls_config,
          },
      },
      config = {
          package_root = package_root,
          compile_path = compile_path,
      },
  })
end

if vim.fn.isdirectory(install_path) == 0 then
  vim.fn.system({ "git", "clone", "https://github.com/wbthomason/packer.nvim", install_path })
  load_plugins()
  require("packer").sync()
else
  load_plugins()
  require("packer").sync()
end

vim.keymap.set({ 'n', 'v' }, '<space>ca', vim.lsp.buf.code_action)

Steps to Reproduce

Reproducibility Check

Expected Behavior

lsp_params.range would include all selected text

Actual Behavior

lsp_params.range includes only text up until the cursor

Debug Log

[TRACE Sat Feb 11 15:24:23 2023] ...te/pack/packer/start/null-ls.nvim/lua/null-ls/client.lua:97: starting null-ls client
[TRACE Sat Feb 11 15:24:23 2023] .../site/pack/packer/start/null-ls.nvim/lua/null-ls/rpc.lua:102: received LSP request for method initialize
[DEBUG Sat Feb 11 15:24:23 2023] ...te/pack/packer/start/null-ls.nvim/lua/null-ls/client.lua:152: unable to notify client for method textDocument/didOpen (client not active): {
  textDocument = {
    uri = "file:///private/tmp/nullls/test.lua"
  }
}
[TRACE Sat Feb 11 15:24:23 2023] .../site/pack/packer/start/null-ls.nvim/lua/null-ls/rpc.lua:127: received LSP notification for method initialized
[TRACE Sat Feb 11 15:24:23 2023] .../site/pack/packer/start/null-ls.nvim/lua/null-ls/rpc.lua:127: received LSP notification for method textDocument/didOpen
[TRACE Sat Feb 11 15:24:23 2023] ...ack/packer/start/null-ls.nvim/lua/null-ls/generators.lua:21: running generators for method NULL_LS_DIAGNOSTICS_ON_OPEN
[DEBUG Sat Feb 11 15:24:23 2023] ...ack/packer/start/null-ls.nvim/lua/null-ls/generators.lua:24: no generators available
[TRACE Sat Feb 11 15:24:33 2023] .../site/pack/packer/start/null-ls.nvim/lua/null-ls/rpc.lua:102: received LSP request for method textDocument/codeAction
[TRACE Sat Feb 11 15:24:33 2023] ...ack/packer/start/null-ls.nvim/lua/null-ls/generators.lua:21: running generators for method NULL_LS_CODE_ACTION
[TRACE Sat Feb 11 15:24:33 2023] ...k/packer/start/null-ls.nvim/lua/null-ls/code-actions.lua:35: received code actions from generators
[TRACE Sat Feb 11 15:24:33 2023] ...k/packer/start/null-ls.nvim/lua/null-ls/code-actions.lua:36: { {
    arguments = {
      title = "print range code action params"
    },
    command = "NULL_LS_CODE_ACTION",
    title = "print range code action params"
  } }
[TRACE Sat Feb 11 15:24:35 2023] .../site/pack/packer/start/null-ls.nvim/lua/null-ls/rpc.lua:102: received LSP request for method workspace/executeCommand

Help

Yes, but I don't know how to start. I would need guidance

Implementation Help

I'm not sure it is the issue with null-ls. I think it might be neovim behaviour for all language servers.

Requirements

jose-elias-alvarez commented 1 year ago

If params.lsp_params.range is wrong, then this is likely an issue with Neovim itself, since we don't modify those at all. Can you check Neovim's LSP log to see whether this issue is specific to null-ls? It should be possible to reproduce with other language servers.

antosha417 commented 1 year ago

@jose-elias-alvarez I was able to reproduce it with rust-analyzer. So it happens on neovim side. Not sure if it is a bug or a feature.