feat: lsp definitions (#631)
* added lsp definitoins * don't call locations_to_items when there is one Co-authored-by: Jae-Won Chung <jaywonchung@snu.ac.kr> * added missing end * added description * added to feature map * Update lua/telescope/builtin/lsp.lua Co-authored-by: fdschmidt93 <39233597+fdschmidt93@users.noreply.github.com> * Update lua/telescope/builtin/lsp.lua Co-authored-by: Jae-Won Chung <jaywonchung@snu.ac.kr> Co-authored-by: Jae-Won Chung <jaywonchung@snu.ac.kr> Co-authored-by: fdschmidt93 <39233597+fdschmidt93@users.noreply.github.com>
This commit is contained in:
@@ -410,6 +410,7 @@ Built-in functions. Ready to be bound to any key you like. :smile:
|
|||||||
| `builtin.lsp_range_code_actions` | Lists LSP range code action to be trigged on enter. |
|
| `builtin.lsp_range_code_actions` | Lists LSP range code action to be trigged on enter. |
|
||||||
| `builtin.lsp_document_diagnostics` | Lists LSP Diagnostics in the current document. |
|
| `builtin.lsp_document_diagnostics` | Lists LSP Diagnostics in the current document. |
|
||||||
| `builtin.lsp_workspace_diagnostics` | Lists LSP Diagnostics in the workspace if supported and otherwise open buffers. |
|
| `builtin.lsp_workspace_diagnostics` | Lists LSP Diagnostics in the workspace if supported and otherwise open buffers. |
|
||||||
|
| `builtin.lsp_definitions` | Goto definition if there is only one. If there are multiple, open them up in telescope |
|
||||||
|
|
||||||
### Git Pickers
|
### Git Pickers
|
||||||
|
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ builtin.autocommands = require('telescope.builtin.internal').autocommands
|
|||||||
builtin.spell_suggest = require('telescope.builtin.internal').spell_suggest
|
builtin.spell_suggest = require('telescope.builtin.internal').spell_suggest
|
||||||
|
|
||||||
builtin.lsp_references = require('telescope.builtin.lsp').references
|
builtin.lsp_references = require('telescope.builtin.lsp').references
|
||||||
|
builtin.lsp_definitions = require('telescope.builtin.lsp').definitions
|
||||||
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_document_diagnostics = require('telescope.builtin.lsp').diagnostics
|
builtin.lsp_document_diagnostics = require('telescope.builtin.lsp').diagnostics
|
||||||
|
|||||||
@@ -38,6 +38,36 @@ lsp.references = function(opts)
|
|||||||
}):find()
|
}):find()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
lsp.definitions = function(opts)
|
||||||
|
opts = opts or {}
|
||||||
|
|
||||||
|
local params = vim.lsp.util.make_position_params()
|
||||||
|
local result = vim.lsp.buf_request_sync(0, "textDocument/definition", params, opts.timeout or 10000)
|
||||||
|
local flattened_results = {}
|
||||||
|
for _, server_results in pairs(result) do
|
||||||
|
if server_results.result then
|
||||||
|
vim.list_extend(flattened_results, server_results.result)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if #flattened_results == 0 then
|
||||||
|
return
|
||||||
|
elseif #flattened_results == 1 then
|
||||||
|
vim.lsp.util.jump_to_location(flattened_results[1])
|
||||||
|
else
|
||||||
|
local locations = vim.lsp.util.locations_to_items(flattened_results)
|
||||||
|
pickers.new(opts, {
|
||||||
|
prompt_title = 'LSP Definitions',
|
||||||
|
finder = finders.new_table {
|
||||||
|
results = locations,
|
||||||
|
entry_maker = opts.entry_maker or make_entry.gen_from_quickfix(opts),
|
||||||
|
},
|
||||||
|
previewer = conf.qflist_previewer(opts),
|
||||||
|
sorter = conf.generic_sorter(opts),
|
||||||
|
}):find()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
lsp.document_symbols = function(opts)
|
lsp.document_symbols = function(opts)
|
||||||
local params = vim.lsp.util.make_position_params()
|
local params = vim.lsp.util.make_position_params()
|
||||||
local results_lsp = vim.lsp.buf_request_sync(0, "textDocument/documentSymbol", params, opts.timeout or 10000)
|
local results_lsp = vim.lsp.buf_request_sync(0, "textDocument/documentSymbol", params, opts.timeout or 10000)
|
||||||
@@ -246,6 +276,7 @@ local feature_map = {
|
|||||||
["code_actions"] = "code_action",
|
["code_actions"] = "code_action",
|
||||||
["document_symbols"] = "document_symbol",
|
["document_symbols"] = "document_symbol",
|
||||||
["references"] = "find_references",
|
["references"] = "find_references",
|
||||||
|
["definitions"] = "goto_definition",
|
||||||
["workspace_symbols"] = "workspace_symbol",
|
["workspace_symbols"] = "workspace_symbol",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user