Skip to content

Commit

Permalink
feat: Lsp implementation (#50)
Browse files Browse the repository at this point in the history
* feat(providers.lsp): Add textDocument/implementation support

* Update README.md for LSP lists

Co-authored-by: Tom Praschan <praschan@mueller-elektronik.de>
  • Loading branch information
tom-anders and Tom Praschan committed Jun 14, 2021
1 parent a7dca62 commit 069cdae
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -10,6 +10,8 @@ A pretty list for showing diagnostics, references, telescope results, quickfix a
* pretty list of:
- LSP Diagnostics
- LSP references
- LSP implementations
- LSP definitions
- quickfix list
- location list
- [Telescope](https://github.com/nvim-telescope/telescope.nvim) search results
Expand Down
1 change: 1 addition & 0 deletions lua/trouble/providers/init.lua
Expand Up @@ -9,6 +9,7 @@ M.providers = {
lsp_workspace_diagnostics = lsp.diagnostics,
lsp_document_diagnostics = lsp.diagnostics,
lsp_references = lsp.references,
lsp_implementations = lsp.implementations,
lsp_definitions = lsp.definitions,
quickfix = qf.qflist,
loclist = qf.loclist,
Expand Down
18 changes: 18 additions & 0 deletions lua/trouble/providers/lsp.lua
Expand Up @@ -34,6 +34,24 @@ function M.references(win, buf, cb, _options)
end)
end

---@return Item[]
function M.implementations(win, buf, cb, _options)
local method = "textDocument/implementation"
local params = util.make_position_params(win, buf)
params.context = { includeDeclaration = true }
lsp.buf_request(buf, method, params, function(err, _method, result, _client_id, _bufnr, _config)
if err then
util.error("an error happened getting implementation: " .. err)
return cb({})
end
if result == nil or #result == 0 then
return cb({})
end
local ret = util.locations_to_items({ result }, 0)
cb(ret)
end)
end

---@return Item[]
function M.definitions(win, buf, cb, _options)
local method = "textDocument/definition"
Expand Down

0 comments on commit 069cdae

Please sign in to comment.