nvim-telescope / telescope.nvim

Find, Filter, Preview, Pick. All lua, all the time.
MIT License
15.8k stars 834 forks source link

lsp_range_code_actions does not work correctly in most cases #1760

Closed OleStrohm closed 2 years ago

OleStrohm commented 2 years ago

Description

I tried to get :Telescope lsp_range_code_actions to list all the code actions for a visual range, but it turns out this is quite buggy. This only cares about the start and end lines of the selection, which means it acts as though the selection is always a visual line selection. However since it always sets the start/end column to 0 it actually cuts off the last line when doing a visual line selection. As is apparent from the current implementation:

opts.params = vim.lsp.util.make_given_range_params({ opts.start_line, 1 }, { opts.end_line, 1 }, opts.bufnr)

I implemented my own function around lsp_code_actions:

local TSRCA = function()
  local opts =  {}
  opts.params = vim.lsp.util.make_given_range_params()
  require('telescope.builtin').lsp_code_actions(opts)
end

And this simply gets the actual limits of the visual range, both the lines and the columns. However when I have a keymap to just call TSRCA (using 0.7 nightly vim.keymap.set) or like :lua TSRCA()<cr> (So it adds '<,'> before lua) I get placed in insert (VISUAL LINE), but calling it like :<c-u>lua TSRCA()<cr> it works correctly.

Neovim version

NVIM v0.7.0-dev+1125-g726ec7fb1
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3

Operating system and version

Arch linux 5.16.10-arch1-1

checkhealth telescope

telescope: require("telescope.health").check()
========================================================================
## Checking for required plugins
  - OK: plenary installed.
  - OK: nvim-treesitter installed.

## Checking external dependencies
  - OK: rg: found ripgrep 13.0.0
  - OK: fd: found fd 8.3.2

## ===== Installed extensions =====

Steps to reproduce

--

Expected behavior

I would expect :Telescope lsp_range_code_actions to ask the LSP for code actions that relate to the visual selection I've made.

Actual behavior

It cuts off the last line in the selection (for example when using extract to function it extracts all but the last line of the selection, and selecting one line too much gives the expected behaviour). It doesn't work at all for normal visual range (for example when extracting an expression to a variable)

Minimal config

--
ghillb commented 2 years ago

There is something amiss with :Telescope lsp_range_code_actions, it produces none of the selection specific actions for me. Here a comparison of the results for built in lsp range code action and telescope range code action commands for the jdtls ls:

Result of :'<,'>lua vim.lsp.buf.range_code_action() (yields 8 actions): image

Result of :'<,'>Telescope lsp_range_code_actions (yields only 3 actions): image

Conni2461 commented 2 years ago

code_actions where removed from telescope in https://github.com/nvim-telescope/telescope.nvim/pull/1866

See :help telescope.changelog-1866 for more information