Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return find_references results to caller #5

Open
wants to merge 1 commit into
base: default
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -861,22 +861,26 @@ function M.goto_type_definition() return goto_definition('typeDefinition') end
function M.goto_implementation() return goto_definition('implementation') end

---
-- Searches for project references to the current symbol and prints them.
-- Searches for project references to the current symbol and both prints and returns them.
-- @name find_references
function M.find_references()
-- @param no_print Optional, if `true` then no `ui._print` occurs.
function M.find_references(no_print)
local server = servers[buffer:get_lexer()]
if server and buffer.filename and server.capabilities.referencesProvider then
server:sync_buffer()
local params = get_buffer_position_params()
params.context = {includeDeclaration = true}
local locations = server:request('textDocument/references', params)
if not locations or #locations == 0 then return end
for _, location in ipairs(locations) do
-- Print trailing ': ' to enable 'find in files' features like double-click, menu items,
-- Return keypress, etc.
ui._print(_L['[Files Found Buffer]'],
string.format('%s:%d: ', tofilename(location.uri), location.range.start.line))
if not locations or #locations == 0 then return nil end
if not no_print then
for _, location in ipairs(locations) do
-- Print trailing ': ' to enable 'find in files' features like double-click, menu items,
-- Return keypress, etc.
ui._print(_L['[Files Found Buffer]'],
string.format('%s:%d: ', tofilename(location.uri), location.range.start.line))
end
end
return locations
end
end

Expand Down