feat: add lsp range code actions (#297)

https://github.com/neovim/neovim/pull/12962

authored by: @windwp
This commit is contained in:
windwp
2020-11-28 13:16:17 +07:00
committed by GitHub
parent 6edbd1db5f
commit 16f11b6c27
3 changed files with 44 additions and 37 deletions

View File

@@ -347,7 +347,7 @@ require('telescope.builtin').fd({ -- or new custom picker's attach_mappings fiel
Built-in function ready to be bound to any key you like :smile:. Built-in function ready to be bound to any key you like :smile:.
| Functions | Description | | Functions | Description |
|-------------------------------------|------------------------------------------------------------------| |-------------------------------------|---------------------------------------------------------------------------------------------|
| `builtin.planets` | Demo showcasing how simple to create pickers with telescope. | | `builtin.planets` | Demo showcasing how simple to create pickers with telescope. |
| `builtin.builtin` | Lists Built-in pickers and run them on enter. | | `builtin.builtin` | Lists Built-in pickers and run them on enter. |
| `builtin.find_files` | Lists Files in current directory. | | `builtin.find_files` | Lists Files in current directory. |
@@ -370,6 +370,7 @@ Built-in function ready to be bound to any key you like :smile:.
| `builtin.lsp_document_symbols` | Searches in LSP Document Symbols in the current document. | | `builtin.lsp_document_symbols` | Searches in LSP Document Symbols in the current document. |
| `builtin.lsp_workspace_symbols` | Searches in LSP all workspace symbols. | | `builtin.lsp_workspace_symbols` | Searches in LSP all workspace symbols. |
| `builtin.lsp_code_actions` | Lists LSP action to be trigged on enter. | | `builtin.lsp_code_actions` | Lists LSP action to be trigged on enter. |
| `builtin.lsp_range_code_actions` | Lists LSP range code action to be trigged on enter. |
| `builtin.quickfix` | Lists items from quickfix. | | `builtin.quickfix` | Lists items from quickfix. |
| `builtin.loclist` | Lists items from current window's location list. | | `builtin.loclist` | Lists items from current window's location list. |
| `builtin.reloader` | Lists lua modules and reload them on enter. | | `builtin.reloader` | Lists lua modules and reload them on enter. |
@@ -378,8 +379,8 @@ Built-in function ready to be bound to any key you like :smile:.
| `builtin.keymaps` | Lists normal-mode mappings. | | `builtin.keymaps` | Lists normal-mode mappings. |
| `builtin.filetypes` | Lists all filetypes. | | `builtin.filetypes` | Lists all filetypes. |
| `builtin.highlights` | Lists all highlights. | | `builtin.highlights` | Lists all highlights. |
| `builtin.git_commits` | Lists git commits with diff preview and on enter checkout the commit.| | `builtin.git_commits` | Lists git commits with diff preview and on enter checkout the commit. |
| `builtin.git_bcommits` | Lists buffer's git commits with diff preview and checkouts it out on enter.| | `builtin.git_bcommits` | Lists buffer's git commits with diff preview and checkouts it out on enter. |
| `builtin.git_branches` | Lists all branches with log preview and checkout action. | | `builtin.git_branches` | Lists all branches with log preview and checkout action. |
| `builtin.git_status` | Lists current changes per file with diff preview and add action. (Multiselection still WIP) | | `builtin.git_status` | Lists current changes per file with diff preview and add action. (Multiselection still WIP) |
| .................................. | Your next awesome finder function here :D | | .................................. | Your next awesome finder function here :D |

View File

@@ -62,6 +62,7 @@ builtin.highlights = require('telescope.builtin.internal').highlights
builtin.lsp_references = require('telescope.builtin.lsp').references builtin.lsp_references = require('telescope.builtin.lsp').references
builtin.lsp_document_symbols = require('telescope.builtin.lsp').document_symbols builtin.lsp_document_symbols = require('telescope.builtin.lsp').document_symbols
builtin.lsp_code_actions = require('telescope.builtin.lsp').code_actions builtin.lsp_code_actions = require('telescope.builtin.lsp').code_actions
builtin.lsp_range_code_actions = require('telescope.builtin.lsp').range_code_actions
builtin.lsp_workspace_symbols = require('telescope.builtin.lsp').workspace_symbols builtin.lsp_workspace_symbols = require('telescope.builtin.lsp').workspace_symbols
return builtin return builtin

View File

@@ -68,7 +68,7 @@ lsp.document_symbols = function(opts)
end end
lsp.code_actions = function(opts) lsp.code_actions = function(opts)
local params = vim.lsp.util.make_range_params() local params = opts.params or vim.lsp.util.make_range_params()
params.context = { params.context = {
diagnostics = vim.lsp.diagnostic.get_line_diagnostics() diagnostics = vim.lsp.diagnostic.get_line_diagnostics()
@@ -134,6 +134,11 @@ lsp.code_actions = function(opts)
}):find() }):find()
end end
lsp.range_code_actions = function(opts)
opts.params = vim.lsp.util.make_given_range_params()
lsp.code_actions(opts)
end
lsp.workspace_symbols = function(opts) lsp.workspace_symbols = function(opts)
opts.shorten_path = utils.get_default(opts.shorten_path, true) opts.shorten_path = utils.get_default(opts.shorten_path, true)