Skip to content

Commit

Permalink
feat(providers.lsp): Add definitions support (#20)
Browse files Browse the repository at this point in the history
* feat(providers.lsp): Add definitions support

Some LSP give back multiple locations for definitions, mostly lua

* fix(providers.lsp): Fix error message
  • Loading branch information
simrat39 committed May 4, 2021
1 parent ff46a9a commit a951198
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions lua/trouble/providers/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ M.providers = {
lsp_workspace_diagnostics = lsp.diagnostics,
lsp_document_diagnostics = lsp.diagnostics,
lsp_references = lsp.references,
lsp_definitions = lsp.definitions,
quickfix = qf.qflist,
loclist = qf.loclist,
telescope = telescope.telescope
Expand Down
24 changes: 24 additions & 0 deletions lua/trouble/providers/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,30 @@ function M.references(win, buf, cb, options)
end)
end

---@return Item[]
function M.definitions(win, buf, cb, options)
local method = "textDocument/definition"
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 definitions: " .. err)
return cb({})
end
if result == nil or #result == 0 then
util.warn("No definitions found")
return cb({})
end
for _, value in ipairs(result) do
value.uri = value.targetUri
value.range = value.targetSelectionRange
end
local ret = util.locations_to_items({result}, 0)
cb(ret)
end)
end

function M.get_signs()
local signs = {}
for _, v in pairs(util.severity) do
Expand Down

0 comments on commit a951198

Please sign in to comment.