navigator.lua/lua/navigator/gui.lua

128 lines
3.1 KiB
Lua
Raw Normal View History

2021-04-19 02:56:32 +00:00
local M = {}
2022-07-26 14:24:40 +00:00
-- local ListView = require('guihua.listview')
-- local TextView = require('guihua.textview')
2021-12-12 23:42:53 +00:00
local util = require('navigator.util')
2021-12-13 06:43:51 +00:00
local log = util.log
2021-12-12 23:42:53 +00:00
local trace = require('navigator.util').trace
2021-04-20 07:42:03 +00:00
local api = vim.api
2021-12-30 05:05:25 +00:00
local active_list_view -- only one listview at a time
2021-04-19 02:56:32 +00:00
function M.new_list_view(opts)
2022-06-01 15:41:26 +00:00
-- log(opts)
2021-12-12 23:42:53 +00:00
local config = require('navigator').config_values()
2021-12-30 05:05:25 +00:00
if active_list_view ~= nil then
2022-02-17 11:21:34 +00:00
trace(active_list_view)
2021-12-30 05:05:25 +00:00
local winnr = active_list_view.win
local bufnr = active_list_view.buf
2022-07-26 14:24:40 +00:00
if bufnr and api.nvim_buf_is_valid(bufnr) and winnr and api.nvim_win_is_valid(winnr) then
2021-12-30 05:05:25 +00:00
log('list view already present')
return active_list_view
2021-12-30 05:05:25 +00:00
end
end
2021-04-19 02:56:32 +00:00
local items = opts.items
2021-06-25 10:18:55 +00:00
opts.height_ratio = opts.height or config.height
opts.width_ratio = opts.height or config.width
opts.preview_height_ratio = opts.preview_height or config.preview_height
opts.preview_lines = config.preview_lines
if opts.rawdata then
2021-12-12 23:42:53 +00:00
opts.data = items
else
2021-12-12 23:42:53 +00:00
opts.data = require('navigator.render').prepare_for_render(items, opts)
end
opts.border = config.border or 'shadow'
2022-06-01 15:41:26 +00:00
if vim.fn.hlID('TelescopePromptBorder') > 0 then
opts.border_hl = 'TelescopePromptBorder'
2022-07-17 21:53:13 +00:00
else
opts.border_hl = 'FloatBorder'
2022-06-01 15:41:26 +00:00
end
2021-12-12 23:42:53 +00:00
if not items or vim.tbl_isempty(items) then
log('empty data return')
return
end
opts.transparency = config.transparency
if #items >= config.lines_show_prompt then
opts.prompt = true
end
opts.external = config.external
opts.preview_lines_before = 4
if _NgConfigValues.debug then
local logopts = { items = {}, data = {} }
logopts = vim.tbl_deep_extend('keep', logopts, opts)
log(logopts)
end
2021-12-30 05:05:25 +00:00
active_list_view = require('guihua.gui').new_list_view(opts)
return active_list_view
2021-04-19 02:56:32 +00:00
end
return M
-- Doc
--[[
-- each item should look like this
-- update if API changes
{
call_by = { <table 1> },
col = 40,
display_filename = "./curry.js",
2021-08-10 05:27:20 +00:00
filename = "/Users/username/lsp_test/js/curry.js",
lnum = 4,
range = {
end = {
character = 46,
line = 3 -- note: C index
},
start = {
character = 39,
line = 3
}
},
rpath = "js/curry.js",
text = " (sum, element, index) => (sum += element * vector2[index]),",
2021-08-10 05:27:20 +00:00
uri = "file:///Users/username/lsp_test/js/curry.js"
}
--]]
-- on move item:
--[[
call_by = { {
kind = "",
node_scope = {
end = {
character = 1,
line = 7
},
start = {
character = 0,
line = 0
}
},
node_text = "curriedDot",
type = "var"
} },
col = 22,
display_filename = "./curry.js",
2021-08-10 05:27:20 +00:00
filename = "/Users/username/lsp_test/js/curry.js",
lnum = 4,
range = {
end = {
character = 26,
line = 3
},
start = {
character = 21,
line = 3
}
},
rpath = "js/curry.js",
text = " 4: (sum, element, index) => (sum += element * vector   curriedDot()",
2021-08-10 05:27:20 +00:00
uri = "file:///Users/username/lsp_test/js/curry.js"
--
]]