summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimUntersberger <32014449+TimUntersberger@users.noreply.github.com>2020-09-16 18:31:16 +0200
committerGitHub <noreply@github.com>2020-09-16 12:31:16 -0400
commit93e683f0e7b87bc22234ef445baff084c13396fb (patch)
tree3d86985acb4d33c305a3de738e1a1e49b9897155
parent7d1a8292b6c7db7401af05f75e6d9992fc8ed28a (diff)
feat: add builtin.lsp_code_actions (#77)
* fix: use correct path separator on windows * fix: add utils.get_separator * asdf * feat: add builtin.commands * change commands sorter * change sorter * change sorter * feat: make it possible to specify the find_command for find_files * temp * feat: add find_command option for find_files * wip * fix: execute code action
-rw-r--r--lua/telescope/builtin.lua73
1 files changed, 73 insertions, 0 deletions
diff --git a/lua/telescope/builtin.lua b/lua/telescope/builtin.lua
index 36a585c..8f7f5db 100644
--- a/lua/telescope/builtin.lua
+++ b/lua/telescope/builtin.lua
@@ -187,6 +187,79 @@ builtin.lsp_document_symbols = function(opts)
}):find()
end
+builtin.lsp_code_actions = function(opts)
+ opts = opts or {}
+
+ local params = vim.lsp.util.make_range_params()
+
+ params.context = {
+ diagnostics = vim.lsp.util.get_line_diagnostics()
+ }
+
+ local results_lsp, err = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params, 1000)
+
+ if err then
+ print("ERROR: " .. err)
+ return
+ end
+
+ if not results_lsp or vim.tbl_isempty(results_lsp) then
+ print("No results from textDocument/codeAction")
+ return
+ end
+
+ local results = (results_lsp[1] or results_lsp[2]).result;
+
+ if #results == 0 then
+ print("No code actions available")
+ return
+ end
+
+ for i,x in ipairs(results) do
+ x.idx = i
+ end
+
+ pickers.new(opts, {
+ prompt = 'LSP Code Actions',
+ finder = finders.new_table {
+ results = results,
+ entry_maker = function(line)
+ return {
+ valid = line ~= nil,
+ entry_type = make_entry.types.GENERIC,
+ value = line,
+ ordinal = line.idx .. line.title,
+ display = line.idx .. ': ' .. line.title
+ }
+ end
+ },
+ attach_mappings = function(prompt_bufnr, map)
+ local execute = function()
+ local selection = actions.get_selected_entry(prompt_bufnr)
+ actions.close(prompt_bufnr)
+ local val = selection.value
+
+ if val.edit or type(val.command) == "table" then
+ if val.edit then
+ vim.lsp.util.apply_workspace_edit(val.edit)
+ end
+ if type(val.command) == "table" then
+ vim.lsp.buf.execute_command(val.command)
+ end
+ else
+ vim.lsp.buf.execute_command(val)
+ end
+ end
+
+ map('i', '<CR>', execute)
+ map('n', '<CR>', execute)
+
+ return true
+ end,
+ sorter = sorters.get_generic_fuzzy_sorter(),
+ }):find()
+end
+
builtin.lsp_workspace_symbols = function(opts)
opts = opts or {}
opts.shorten_path = utils.get_default(opts.shorten_path, true)