break: remove lsp code actions (#1866)
see :help telescope.changelog-1866 for more information
This commit is contained in:
@@ -301,8 +301,6 @@ Built-in functions. Ready to be bound to any key you like.
|
|||||||
| `builtin.lsp_document_symbols` | Lists LSP document symbols in the current buffer |
|
| `builtin.lsp_document_symbols` | Lists LSP document symbols in the current buffer |
|
||||||
| `builtin.lsp_workspace_symbols` | Lists LSP document symbols in the current workspace |
|
| `builtin.lsp_workspace_symbols` | Lists LSP document symbols in the current workspace |
|
||||||
| `builtin.lsp_dynamic_workspace_symbols` | Dynamically Lists LSP for all workspace symbols |
|
| `builtin.lsp_dynamic_workspace_symbols` | Dynamically Lists LSP for all workspace symbols |
|
||||||
| `builtin.lsp_code_actions` | Lists any LSP actions for the word under the cursor, that can be triggered with `<cr>` |
|
|
||||||
| `builtin.lsp_range_code_actions` | Lists any LSP actions for a given range, that can be triggered with `<cr>` |
|
|
||||||
| `builtin.diagnostics` | Lists Diagnostics for all open buffers or a specific buffer. Use option `bufnr=0` for current buffer. |
|
| `builtin.diagnostics` | Lists Diagnostics for all open buffers or a specific buffer. Use option `bufnr=0` for current buffer. |
|
||||||
| `builtin.lsp_implementations` | Goto the implementation of the word under the cursor if there's only one, otherwise show all options in Telescope |
|
| `builtin.lsp_implementations` | Goto the implementation of the word under the cursor if there's only one, otherwise show all options in Telescope |
|
||||||
| `builtin.lsp_definitions` | Goto the definition of the word under the cursor, if there's only one, otherwise show all options in Telescope |
|
| `builtin.lsp_definitions` | Goto the definition of the word under the cursor, if there's only one, otherwise show all options in Telescope |
|
||||||
|
|||||||
@@ -1403,33 +1403,6 @@ builtin.lsp_implementations({opts}) *telescope.builtin.lsp_implementations()*
|
|||||||
{trim_text} (boolean) trim results text (default: false)
|
{trim_text} (boolean) trim results text (default: false)
|
||||||
|
|
||||||
|
|
||||||
builtin.lsp_code_actions({opts}) *telescope.builtin.lsp_code_actions()*
|
|
||||||
Lists any LSP actions for the word under the cursor which can be triggered
|
|
||||||
with `<cr>`
|
|
||||||
|
|
||||||
|
|
||||||
Parameters: ~
|
|
||||||
{opts} (table) options to pass to the picker
|
|
||||||
|
|
||||||
Options: ~
|
|
||||||
{timeout} (number) timeout for the sync call (default: 10000)
|
|
||||||
|
|
||||||
|
|
||||||
builtin.lsp_range_code_actions({opts}) *telescope.builtin.lsp_range_code_actions()*
|
|
||||||
Lists any LSP actions for a given range, that can be triggered with `<cr>`
|
|
||||||
|
|
||||||
|
|
||||||
Parameters: ~
|
|
||||||
{opts} (table) options to pass to the picker
|
|
||||||
|
|
||||||
Options: ~
|
|
||||||
{timeout} (number) timeout for the sync call (default: 10000)
|
|
||||||
{start_line} (number) where the code action starts (default: handled
|
|
||||||
by :'<,'>Telescope lsp_range_code_actions)
|
|
||||||
{end_line} (number) where the code action ends (default: handled by
|
|
||||||
:'<,'>Telescope lsp_range_code_actions)
|
|
||||||
|
|
||||||
|
|
||||||
builtin.lsp_document_symbols({opts}) *telescope.builtin.lsp_document_symbols()*
|
builtin.lsp_document_symbols({opts}) *telescope.builtin.lsp_document_symbols()*
|
||||||
Lists LSP document symbols in the current buffer
|
Lists LSP document symbols in the current buffer
|
||||||
- Default keymaps:
|
- Default keymaps:
|
||||||
@@ -1564,7 +1537,7 @@ themes.get_cursor() *telescope.themes.get_cursor()*
|
|||||||
|
|
||||||
`local builtin = require('telescope.builtin')`
|
`local builtin = require('telescope.builtin')`
|
||||||
`local themes = require('telescope.themes')`
|
`local themes = require('telescope.themes')`
|
||||||
`builtin.lsp_code_actions(themes.get_cursor())`
|
`builtin.lsp_references(themes.get_cursor())`
|
||||||
<
|
<
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ get all diagnostics for all open buffers.
|
|||||||
|
|
||||||
*telescope.changelog-1851*
|
*telescope.changelog-1851*
|
||||||
|
|
||||||
Date: December 10, 2021
|
Date: April 22, 2022
|
||||||
PR: https://github.com/nvim-telescope/telescope.nvim/pull/1851
|
PR: https://github.com/nvim-telescope/telescope.nvim/pull/1851
|
||||||
|
|
||||||
Telescope requires now Neovim release 0.7.0 or a more recent nightly.
|
Telescope requires now Neovim release 0.7.0 or a more recent nightly.
|
||||||
@@ -175,5 +175,25 @@ versions. You can read more about this strategy here:
|
|||||||
https://github.com/nvim-telescope/telescope.nvim/issues/1772
|
https://github.com/nvim-telescope/telescope.nvim/issues/1772
|
||||||
|
|
||||||
|
|
||||||
|
*telescope.changelog-1866*
|
||||||
|
|
||||||
|
Date: April 25, 2022
|
||||||
|
PR: https://github.com/nvim-telescope/telescope.nvim/pull/1866
|
||||||
|
|
||||||
|
We decided to remove both `lsp_code_actions` and `lsp_range_code_actions`.
|
||||||
|
Currently, both functions are highly duplicated code from neovim, with fewer
|
||||||
|
features, because it's out of date. So rather that we copy over the required
|
||||||
|
changes to fix some bugs or implement client side code actions, we decided to
|
||||||
|
remove both of them and suggest you use `vim.lsp.buf.code_actions` and
|
||||||
|
`vim.lsp.buf.range_code_actions`. The transition to it is easy thanks to
|
||||||
|
`vim.ui.select` which allows you to override the select UI. We provide a small
|
||||||
|
extension for quite some time that make it easy to use telescope for
|
||||||
|
`vim.ui.select`. You can found the code here
|
||||||
|
https://github.com/nvim-telescope/telescope-ui-select.nvim. It offers the same
|
||||||
|
displaying as the current version of `lsp_code_actions`. An alternative is
|
||||||
|
https://github.com/stevearc/dressing.nvim which has support for multiple
|
||||||
|
different backends including telescope.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
vim:tw=78:ts=8:ft=help:norl:
|
vim:tw=78:ts=8:ft=help:norl:
|
||||||
|
|||||||
@@ -382,18 +382,6 @@ builtin.lsp_type_definitions = require("telescope.builtin.lsp").type_definitions
|
|||||||
---@field trim_text boolean: trim results text (default: false)
|
---@field trim_text boolean: trim results text (default: false)
|
||||||
builtin.lsp_implementations = require_on_exported_call("telescope.builtin.lsp").implementations
|
builtin.lsp_implementations = require_on_exported_call("telescope.builtin.lsp").implementations
|
||||||
|
|
||||||
--- Lists any LSP actions for the word under the cursor which can be triggered with `<cr>`
|
|
||||||
---@param opts table: options to pass to the picker
|
|
||||||
---@field timeout number: timeout for the sync call (default: 10000)
|
|
||||||
builtin.lsp_code_actions = require_on_exported_call("telescope.builtin.lsp").code_actions
|
|
||||||
|
|
||||||
--- Lists any LSP actions for a given range, that can be triggered with `<cr>`
|
|
||||||
---@param opts table: options to pass to the picker
|
|
||||||
---@field timeout number: timeout for the sync call (default: 10000)
|
|
||||||
---@field start_line number: where the code action starts (default: handled by :'<,'>Telescope lsp_range_code_actions)
|
|
||||||
---@field end_line number: where the code action ends (default: handled by :'<,'>Telescope lsp_range_code_actions)
|
|
||||||
builtin.lsp_range_code_actions = require_on_exported_call("telescope.builtin.lsp").range_code_actions
|
|
||||||
|
|
||||||
--- Lists LSP document symbols in the current buffer
|
--- Lists LSP document symbols in the current buffer
|
||||||
--- - Default keymaps:
|
--- - Default keymaps:
|
||||||
--- - `<C-l>`: show autocompletion menu to prefilter your query by type of symbol you want to see (i.e. `:variable:`)
|
--- - `<C-l>`: show autocompletion menu to prefilter your query by type of symbol you want to see (i.e. `:variable:`)
|
||||||
|
|||||||
@@ -1,13 +1,9 @@
|
|||||||
local channel = require("plenary.async.control").channel
|
local channel = require("plenary.async.control").channel
|
||||||
|
|
||||||
local action_state = require "telescope.actions.state"
|
|
||||||
local actions = require "telescope.actions"
|
|
||||||
local conf = require("telescope.config").values
|
local conf = require("telescope.config").values
|
||||||
local entry_display = require "telescope.pickers.entry_display"
|
|
||||||
local finders = require "telescope.finders"
|
local finders = require "telescope.finders"
|
||||||
local make_entry = require "telescope.make_entry"
|
local make_entry = require "telescope.make_entry"
|
||||||
local pickers = require "telescope.pickers"
|
local pickers = require "telescope.pickers"
|
||||||
local strings = require "plenary.strings"
|
|
||||||
local utils = require "telescope.utils"
|
local utils = require "telescope.utils"
|
||||||
|
|
||||||
local lsp = {}
|
local lsp = {}
|
||||||
@@ -162,211 +158,6 @@ lsp.document_symbols = function(opts)
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
lsp.code_actions = function(opts)
|
|
||||||
local params = vim.F.if_nil(opts.params, vim.lsp.util.make_range_params(opts.winnr))
|
|
||||||
local lnum = vim.api.nvim_win_get_cursor(opts.winnr)[1]
|
|
||||||
|
|
||||||
params.context = {
|
|
||||||
diagnostics = vim.lsp.diagnostic.get_line_diagnostics(opts.bufnr, lnum - 1),
|
|
||||||
}
|
|
||||||
|
|
||||||
local results_lsp, err = vim.lsp.buf_request_sync(
|
|
||||||
opts.bufnr,
|
|
||||||
"textDocument/codeAction",
|
|
||||||
params,
|
|
||||||
vim.F.if_nil(opts.timeout, 10000)
|
|
||||||
)
|
|
||||||
|
|
||||||
if err then
|
|
||||||
utils.notify("builtin.lsp_code_actions", {
|
|
||||||
msg = err,
|
|
||||||
level = "ERROR",
|
|
||||||
})
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if not results_lsp or vim.tbl_isempty(results_lsp) then
|
|
||||||
utils.notify("builtin.lsp_document_symbols", {
|
|
||||||
msg = "No results from textDocument/codeAction",
|
|
||||||
level = "INFO",
|
|
||||||
})
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local idx = 1
|
|
||||||
local results = {}
|
|
||||||
local widths = {
|
|
||||||
idx = 0,
|
|
||||||
command_title = 0,
|
|
||||||
client_name = 0,
|
|
||||||
}
|
|
||||||
|
|
||||||
for client_id, response in pairs(results_lsp) do
|
|
||||||
if response.result then
|
|
||||||
local client = vim.lsp.get_client_by_id(client_id)
|
|
||||||
|
|
||||||
for _, result in pairs(response.result) do
|
|
||||||
local entry = {
|
|
||||||
idx = idx,
|
|
||||||
command_title = result.title:gsub("\r\n", "\\r\\n"):gsub("\n", "\\n"),
|
|
||||||
client = client,
|
|
||||||
client_name = client and client.name or "",
|
|
||||||
command = result,
|
|
||||||
}
|
|
||||||
|
|
||||||
for key, value in pairs(widths) do
|
|
||||||
widths[key] = math.max(value, strings.strdisplaywidth(entry[key]))
|
|
||||||
end
|
|
||||||
|
|
||||||
table.insert(results, entry)
|
|
||||||
idx = idx + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if #results == 0 then
|
|
||||||
utils.notify("builtin.lsp_document_symbols", {
|
|
||||||
msg = "No code actions available",
|
|
||||||
level = "INFO",
|
|
||||||
})
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local displayer = entry_display.create {
|
|
||||||
separator = " ",
|
|
||||||
items = {
|
|
||||||
{ width = widths.idx + 1 }, -- +1 for ":" suffix
|
|
||||||
{ width = widths.command_title },
|
|
||||||
{ width = widths.client_name },
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
local function make_display(entry)
|
|
||||||
return displayer {
|
|
||||||
{ entry.value.idx .. ":", "TelescopePromptPrefix" },
|
|
||||||
{ entry.value.command_title },
|
|
||||||
{ entry.value.client_name, "TelescopeResultsComment" },
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
-- If the text document version is 0, set it to nil instead so that Neovim
|
|
||||||
-- won't refuse to update a buffer that it believes is newer than edits.
|
|
||||||
-- See: https://github.com/eclipse/eclipse.jdt.ls/issues/1695
|
|
||||||
-- Source:
|
|
||||||
-- https://github.com/neovim/nvim-lspconfig/blob/486f72a25ea2ee7f81648fdfd8999a155049e466/lua/lspconfig/jdtls.lua#L62
|
|
||||||
local function fix_zero_version(workspace_edit)
|
|
||||||
if workspace_edit and workspace_edit.documentChanges then
|
|
||||||
for _, change in pairs(workspace_edit.documentChanges) do
|
|
||||||
local text_document = change.textDocument
|
|
||||||
if text_document and text_document.version and text_document.version == 0 then
|
|
||||||
text_document.version = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return workspace_edit
|
|
||||||
end
|
|
||||||
|
|
||||||
--[[
|
|
||||||
-- actions is (Command | CodeAction)[] | null
|
|
||||||
-- CodeAction
|
|
||||||
-- title: String
|
|
||||||
-- kind?: CodeActionKind
|
|
||||||
-- diagnostics?: Diagnostic[]
|
|
||||||
-- isPreferred?: boolean
|
|
||||||
-- edit?: WorkspaceEdit
|
|
||||||
-- command?: Command
|
|
||||||
--
|
|
||||||
-- Command
|
|
||||||
-- title: String
|
|
||||||
-- command: String
|
|
||||||
-- arguments?: any[]
|
|
||||||
--]]
|
|
||||||
local transform_action = opts.transform_action
|
|
||||||
or function(action)
|
|
||||||
-- Remove 0 -version from LSP codeaction request payload.
|
|
||||||
-- Is only run on the "java.apply.workspaceEdit" codeaction.
|
|
||||||
-- Fixed Java/jdtls compatibility with Telescope
|
|
||||||
-- See fix_zero_version commentary for more information
|
|
||||||
local command = (action.command and action.command.command) or action.command
|
|
||||||
if command ~= "java.apply.workspaceEdit" then
|
|
||||||
return action
|
|
||||||
end
|
|
||||||
local arguments = (action.command and action.command.arguments) or action.arguments
|
|
||||||
action.edit = fix_zero_version(arguments[1])
|
|
||||||
return action
|
|
||||||
end
|
|
||||||
|
|
||||||
local execute_action = opts.execute_action
|
|
||||||
or function(action, offset_encoding)
|
|
||||||
if action.edit or type(action.command) == "table" then
|
|
||||||
if action.edit then
|
|
||||||
vim.lsp.util.apply_workspace_edit(action.edit, offset_encoding)
|
|
||||||
end
|
|
||||||
if type(action.command) == "table" then
|
|
||||||
vim.lsp.buf.execute_command(action.command)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
vim.lsp.buf.execute_command(action)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
pickers.new(opts, {
|
|
||||||
prompt_title = "LSP Code Actions",
|
|
||||||
finder = finders.new_table {
|
|
||||||
results = results,
|
|
||||||
entry_maker = function(action)
|
|
||||||
return {
|
|
||||||
value = action,
|
|
||||||
ordinal = action.idx .. action.command_title,
|
|
||||||
display = make_display,
|
|
||||||
}
|
|
||||||
end,
|
|
||||||
},
|
|
||||||
attach_mappings = function(prompt_bufnr)
|
|
||||||
actions.select_default:replace(function()
|
|
||||||
local selection = action_state.get_selected_entry()
|
|
||||||
actions.close(prompt_bufnr)
|
|
||||||
local action = selection.value.command
|
|
||||||
local client = selection.value.client
|
|
||||||
local eff_execute = function(transformed)
|
|
||||||
execute_action(transformed, client.offset_encoding)
|
|
||||||
end
|
|
||||||
if
|
|
||||||
not action.edit
|
|
||||||
and client
|
|
||||||
and type(client.resolved_capabilities.code_action) == "table"
|
|
||||||
and client.resolved_capabilities.code_action.resolveProvider
|
|
||||||
then
|
|
||||||
client.request("codeAction/resolve", action, function(resolved_err, resolved_action)
|
|
||||||
if resolved_err then
|
|
||||||
utils.notify("builtin.lsp_code_actions", {
|
|
||||||
msg = string.format("codeAction/resolve failed: %s : %s", resolved_err.code, resolved_err.message),
|
|
||||||
level = "ERROR",
|
|
||||||
})
|
|
||||||
return
|
|
||||||
end
|
|
||||||
if resolved_action then
|
|
||||||
eff_execute(transform_action(resolved_action))
|
|
||||||
else
|
|
||||||
eff_execute(transform_action(action))
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
else
|
|
||||||
eff_execute(transform_action(action))
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
return true
|
|
||||||
end,
|
|
||||||
sorter = conf.generic_sorter(opts),
|
|
||||||
}):find()
|
|
||||||
end
|
|
||||||
|
|
||||||
lsp.range_code_actions = function(opts)
|
|
||||||
opts.params = vim.lsp.util.make_given_range_params({ opts.start_line, 1 }, { opts.end_line, 1 }, opts.bufnr)
|
|
||||||
lsp.code_actions(opts)
|
|
||||||
end
|
|
||||||
|
|
||||||
lsp.workspace_symbols = function(opts)
|
lsp.workspace_symbols = function(opts)
|
||||||
local params = { query = opts.query or "" }
|
local params = { query = opts.query or "" }
|
||||||
vim.lsp.buf_request(opts.bufnr, "workspace/symbol", params, function(err, server_result, _, _)
|
vim.lsp.buf_request(opts.bufnr, "workspace/symbol", params, function(err, server_result, _, _)
|
||||||
@@ -470,7 +261,6 @@ local function check_capabilities(feature, bufnr)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local feature_map = {
|
local feature_map = {
|
||||||
["code_actions"] = "code_action",
|
|
||||||
["document_symbols"] = "document_symbol",
|
["document_symbols"] = "document_symbol",
|
||||||
["references"] = "find_references",
|
["references"] = "find_references",
|
||||||
["definitions"] = "goto_definition",
|
["definitions"] = "goto_definition",
|
||||||
|
|||||||
@@ -223,19 +223,16 @@ function command.register_keyword(keyword)
|
|||||||
split_keywords[keyword] = true
|
split_keywords[keyword] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
function command.load_command(start_line, end_line, count, cmd, ...)
|
function command.load_command(cmd, ...)
|
||||||
local args = { ... }
|
local args = { ... }
|
||||||
if cmd == nil then
|
if cmd == nil then
|
||||||
run_command { cmd = "builtin" }
|
run_command { cmd = "builtin" }
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local user_opts = {}
|
local user_opts = {
|
||||||
user_opts["cmd"] = cmd
|
cmd = cmd,
|
||||||
user_opts.opts = {
|
opts = {},
|
||||||
start_line = start_line,
|
|
||||||
end_line = end_line,
|
|
||||||
count = count,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, arg in ipairs(args) do
|
for _, arg in ipairs(args) do
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ end
|
|||||||
---
|
---
|
||||||
--- `local builtin = require('telescope.builtin')`
|
--- `local builtin = require('telescope.builtin')`
|
||||||
--- `local themes = require('telescope.themes')`
|
--- `local themes = require('telescope.themes')`
|
||||||
--- `builtin.lsp_code_actions(themes.get_cursor())`
|
--- `builtin.lsp_references(themes.get_cursor())`
|
||||||
--- </code>
|
--- </code>
|
||||||
function themes.get_cursor(opts)
|
function themes.get_cursor(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
|
|||||||
@@ -106,10 +106,9 @@ vim.keymap.set(
|
|||||||
)
|
)
|
||||||
|
|
||||||
vim.api.nvim_create_user_command("Telescope", function(opts)
|
vim.api.nvim_create_user_command("Telescope", function(opts)
|
||||||
require("telescope.command").load_command(opts.line1, opts.line2, opts.count, unpack(opts.fargs))
|
require("telescope.command").load_command(unpack(opts.fargs))
|
||||||
end, {
|
end, {
|
||||||
nargs = "*",
|
nargs = "*",
|
||||||
range = true,
|
|
||||||
complete = function(_, line)
|
complete = function(_, line)
|
||||||
local builtin_list = vim.tbl_keys(require "telescope.builtin")
|
local builtin_list = vim.tbl_keys(require "telescope.builtin")
|
||||||
local extensions_list = vim.tbl_keys(require("telescope._extensions").manager)
|
local extensions_list = vim.tbl_keys(require("telescope._extensions").manager)
|
||||||
|
|||||||
Reference in New Issue
Block a user