Add some WIP stuff

This commit is contained in:
TJ DeVries
2020-08-31 22:23:12 -04:00
parent 8cf3952f27
commit 51ed9c3e98
3 changed files with 63 additions and 28 deletions

View File

@@ -33,26 +33,25 @@ end
-- TODO: Make it so that when you select stuff, it's inserted -- TODO: Make it so that when you select stuff, it's inserted
-- TODO: Make it so the previewer shows the help text. -- TODO: Make it so the previewer shows the help text.
WIP.completion = function() WIP.completion = function(opts)
local results = {} local results = {}
for k, v in pairs(vim.api) do for k, _ in pairs(vim.api) do
table.insert(results, k) table.insert(results, k .. "()")
end end
local lsp_reference_finder = finders.new { local lsp_reference_finder = finders.new {
results = results results = results
} }
-- local reference_previewer = previewers.qflist -- TODO: Open the help text for the line.
local reference_picker = pickers.new { local reference_picker = pickers.new(opts, {
-- previewer = reference_previewer prompt = 'vim.api Help Reference',
}
reference_picker:find {
prompt = 'LSP References',
finder = lsp_reference_finder, finder = lsp_reference_finder,
sorter = sorters.get_norcalli_sorter(), sorter = sorters.get_norcalli_sorter(),
} previewer = previewers.help,
})
reference_picker:find {}
end end
-- TODO: Use tree sitter to get "everything" in your current scope / file / etc. -- TODO: Use tree sitter to get "everything" in your current scope / file / etc.

View File

@@ -1,3 +1,5 @@
local context_manager = require('plenary.context_manager')
local log = require('telescope.log') local log = require('telescope.log')
local previewers = {} local previewers = {}
@@ -34,6 +36,14 @@ previewers.new = function(...)
return Previewer:new(...) return Previewer:new(...)
end end
local with_preview_window = function(status, callable)
return context_manager.with(function()
vim.cmd(string.format("noautocmd call win_gotoid(%s)", status.preview_win))
coroutine.yield()
vim.cmd(string.format("noautocmd call win_gotoid(%s)", status.prompt_win))
end, callable)
end
previewers.new_termopen = function(opts) previewers.new_termopen = function(opts)
local entry_value = opts.get_value or function(entry) local entry_value = opts.get_value or function(entry)
return entry.value return entry.value
@@ -47,10 +57,9 @@ previewers.new_termopen = function(opts)
vim.api.nvim_win_set_buf(status.preview_win, bufnr) vim.api.nvim_win_set_buf(status.preview_win, bufnr)
-- HACK! Requires `termopen` to accept buffer argument. with_preview_window(status, function()
vim.cmd(string.format("noautocmd call win_gotoid(%s)", status.preview_win))
vim.fn.termopen(string.format(command_string, entry_value(entry))) vim.fn.termopen(string.format(command_string, entry_value(entry)))
vim.cmd(string.format("noautocmd call win_gotoid(%s)", status.prompt_win)) end)
end end
} }
end end
@@ -133,10 +142,9 @@ previewers.cat = previewers.new {
vim.api.nvim_win_set_buf(status.preview_win, bufnr) vim.api.nvim_win_set_buf(status.preview_win, bufnr)
-- HACK! Requires `termopen` to accept buffer argument. with_preview_window(status, function()
vim.cmd(string.format("noautocmd call win_gotoid(%s)", status.preview_win))
vim.fn.termopen(string.format(self.state.command_string, entry.value)) vim.fn.termopen(string.format(self.state.command_string, entry.value))
vim.cmd(string.format("noautocmd call win_gotoid(%s)", status.prompt_win)) end)
vim.api.nvim_buf_set_name(bufnr, tostring(bufnr)) vim.api.nvim_buf_set_name(bufnr, tostring(bufnr))
end end
@@ -174,10 +182,9 @@ previewers.vimgrep = previewers.new {
local termopen_command = string.format(self.state.command_string, filename, lnum, start, finish) local termopen_command = string.format(self.state.command_string, filename, lnum, start, finish)
-- HACK! Requires `termopen` to accept buffer argument. with_preview_window(status, function()
vim.cmd(string.format("noautocmd call win_gotoid(%s)", status.preview_win))
vim.fn.termopen(termopen_command) vim.fn.termopen(termopen_command)
vim.cmd(string.format("noautocmd call win_gotoid(%s)", status.prompt_win)) end)
end end
} }
@@ -210,10 +217,39 @@ previewers.qflist = previewers.new {
local termopen_command = string.format(self.state.command_string, filename, lnum, start, finish) local termopen_command = string.format(self.state.command_string, filename, lnum, start, finish)
-- HACK! Requires `termopen` to accept buffer argument. with_preview_window(status, function()
vim.cmd(string.format("noautocmd call win_gotoid(%s)", status.preview_win))
vim.fn.termopen(termopen_command) vim.fn.termopen(termopen_command)
vim.cmd(string.format("noautocmd call win_gotoid(%s)", status.prompt_win)) end)
end
}
previewers.help = previewers.new {
preview_fn = function(_, entry, status)
with_preview_window(status, function()
local old_tags = vim.o.tags
vim.o.tags = vim.fn.expand("$VIMRUNTIME") .. '/doc/tags'
local taglist = vim.fn.taglist('^' .. entry.value .. '$')
if vim.tbl_isempty(taglist) then
taglist = vim.fn.taglist(entry.value)
end
if vim.tbl_isempty(taglist) then
return
end
local best_entry = taglist[1]
local new_bufnr = vim.fn.bufnr(best_entry.filename, true)
vim.api.nvim_buf_set_option(new_bufnr, 'filetype', 'help')
vim.api.nvim_win_set_buf(status.preview_win, new_bufnr)
vim.cmd [["gg"]]
print(best_entry.cmd)
vim.cmd(string.format([[execute "%s"]], best_entry.cmd))
vim.o.tags = old_tags
end)
end end
} }

View File

@@ -96,7 +96,7 @@ utils.path_shorten = (function()
]] ]]
return function(path) return function(path)
local c_str = ffi.new("char[?]", #path) local c_str = ffi.new("char[?]", #path + 1)
ffi.copy(c_str, path) ffi.copy(c_str, path)
return ffi.string(ffi.C.shorten_dir(c_str)) return ffi.string(ffi.C.shorten_dir(c_str))
end end