Skip to content

Commit

Permalink
added some stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
oberblastmeister committed Mar 30, 2021
1 parent 5662a49 commit 068c91b
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
1 change: 1 addition & 0 deletions lua/telescope/builtin/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@ builtin.lsp_document_diagnostics = require('telescope.builtin.lsp').diagnostics
builtin.lsp_workspace_diagnostics = require('telescope.builtin.lsp').workspace_diagnostics
builtin.lsp_range_code_actions = require('telescope.builtin.lsp').range_code_actions
builtin.lsp_workspace_symbols = require('telescope.builtin.lsp').workspace_symbols
builtin.lsp_live_workspace_symbols = require('telescope.builtin.lsp').live_workspace_symbols

return builtin
57 changes: 57 additions & 0 deletions lua/telescope/builtin/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ local finders = require('telescope.finders')
local make_entry = require('telescope.make_entry')
local pickers = require('telescope.pickers')
local utils = require('telescope.utils')
local a = require('plenary.async_lib')
local async, await = a.async, a.await
local channel = a.util.channel

local conf = require('telescope.config').values

Expand Down Expand Up @@ -192,6 +195,8 @@ lsp.workspace_symbols = function(opts)
return
end

dump(results_lsp)

local locations = {}
for _, server_results in pairs(results_lsp) do
if server_results.result then
Expand Down Expand Up @@ -220,6 +225,58 @@ lsp.workspace_symbols = function(opts)
}):find()
end

local function get_workspace_symbols_requester()
local cancel = function() end

return async(function(prompt_bufnr, prompt)
-- cancel()

local tx, rx = channel.oneshot()
cancel = vim.lsp.buf_request(prompt_bufnr, "workspace/symbol", {query = prompt}, tx)

local err, _, results_lsp = await(rx())
assert(not err, err)
-- dump(results_lsp)
-- assert(not err, err)
-- dump(await(rx()))

local locations = vim.lsp.util.symbols_to_items(results_lsp, prompt_bufnr) or {}
-- dump(locations)
-- local locations vim.tbl_map(function(result)
-- return
-- end, results_lsp)
-- dump(locations)
-- return locations
return locations
-- local locations = {}
-- for _, server_results in pairs(results_lsp) do
-- if server_results.result then
-- vim.list_extend(locations, vim.lsp.util.symbols_to_items(server_results.result, 0) or {})
-- end
-- end

-- return locations
end)
end

lsp.live_workspace_symbols = function(opts)
local curr_buf = vim.api.nvim_get_current_buf()

pickers.new(opts, {
prompt_title = 'LSP Workspace Symbols',
finder = finders.new_live {
curr_buf = curr_buf,
entry_maker = opts.entry_maker or make_entry.gen_from_lsp_symbols(opts),
fn = get_workspace_symbols_requester(),
},
previewer = conf.qflist_previewer(opts),
sorter = conf.prefilter_sorter{
tag = "symbol_type",
sorter = conf.generic_sorter(opts)
}
}):find()
end

lsp.diagnostics = function(opts)
local locations = utils.diagnostics_to_tbl(opts)

Expand Down
21 changes: 20 additions & 1 deletion lua/telescope/finders.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ local Job = require('plenary.job')

local make_entry = require('telescope.make_entry')
local log = require('telescope.log')
local a = require('plenary.async_lib')
local await, async = a.await, a.async

local finders = {}

Expand Down Expand Up @@ -112,6 +114,7 @@ function LiveFinder:new(opts)
assert(not opts.static, "`static` should be used with finder.new_oneshot_job")

local obj = setmetatable({
curr_buf = opts.curr_buf,
fn = opts.fn,
entry_maker = opts.entry_maker or make_entry.from_string,
fn_command = opts.fn_command,
Expand All @@ -126,7 +129,19 @@ function LiveFinder:new(opts)
return obj
end

function LiveFinder:_find(opts)
function LiveFinder:_find(prompt, process_result, process_complete)
local fn = async(function()
local results = await(self.fn(self.curr_buf, prompt))
for _, result in ipairs(results) do
dump("processing result", result)
process_result(result)
end

await(a.scheduler())
process_complete()
end)

a.util.run(fn())
end

local OneshotJobFinder = _callable_obj()
Expand Down Expand Up @@ -359,4 +374,8 @@ finders.new_table = function(t)
return StaticFinder:new(t)
end

finders.new_live = function(t)
return LiveFinder:new(t)
end

return finders

0 comments on commit 068c91b

Please sign in to comment.