From c5fe79d6dfda2fff5faaf7a56437e7b8a743a7cd Mon Sep 17 00:00:00 2001 From: ray-x Date: Fri, 25 Jun 2021 20:18:55 +1000 Subject: [PATCH] update window height and width preset --- README.md | 13 ++++++++----- lua/navigator.lua | 6 +++--- lua/navigator/gui.lua | 16 +++++++++------- lua/navigator/lspclient/mapping.lua | 4 ++-- lua/navigator/reference.lua | 3 ++- 5 files changed, 24 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index a74796d..9c2ef30 100644 --- a/README.md +++ b/README.md @@ -181,13 +181,16 @@ Nondefault configuration example: ```lua require.'navigator'.setup({ - debug = false, -- log output not implemented + debug = false, -- log output code_action_icon = " ", - width = 0.75, -- number of cols for the floating window - height = 0.3, -- preview window size, 0.3 by default + width = 0.75, -- max width ratio (number of cols for the floating window) / (window width) + height = 0.3, -- max list window height, 0.3 by default + preview_height = 0.35, -- max height of preview windows border = {"╭", "─", "╮", "│", "╯", "─", "╰", "│"}, -- border style, can be one of 'none', 'single', 'double', -- 'shadow', or a list of chars which defines the border - on_attach = nil, + on_attach = function(client, bufnr) + -- your hook + end, -- put a on_attach of your own here, e.g -- function(client, bufnr) -- -- the on_attach will be called at end of navigator on_attach @@ -205,7 +208,7 @@ require.'navigator'.setup({ diagnostic_head = '🐛', diagnostic_head_severity_1 = "🈲", -- refer to lua/navigator.lua for more icons setups - } + }, lsp = { format_on_save = true, -- set to false to disasble lsp code format on save (if you are using prettier/efm/formater etc) tsserver = { diff --git a/lua/navigator.lua b/lua/navigator.lua index c5e1f3c..db6f6d9 100644 --- a/lua/navigator.lua +++ b/lua/navigator.lua @@ -3,7 +3,7 @@ _NgConfigValues = { debug = false, -- log output not implemented width = 0.6, -- valeu of cols TODO allow float e.g. 0.6 preview_height = 0.35, - height = nil, + height = 0.35, default_mapping = true, on_attach = nil, -- function(client, bufnr) @@ -46,9 +46,9 @@ _NgConfigValues = { associated = "🤝", namespace = "🚀", type = " ", - field = "🏈", + field = "🏈" }, - treesitter_defult = "🌲", + treesitter_defult = "🌲" } } diff --git a/lua/navigator/gui.lua b/lua/navigator/gui.lua index 1123fd1..a3a93c5 100644 --- a/lua/navigator/gui.lua +++ b/lua/navigator/gui.lua @@ -50,7 +50,7 @@ function M._preview_location(opts) -- location, width, pos_x, pos_y syntax = syntax, width = opts.width, height = display_range['end'].line - display_range.start.line + 1, - preview_height = opts.preview_height, + preview_height = opts.height or opts.preview_height, pos_x = opts.offset_x, pos_y = opts.offset_y, range = opts.range, @@ -113,13 +113,16 @@ function M.new_list_view(opts) local wwidth = api.nvim_get_option("columns") local loc = "top_center" - local width = math.floor(wwidth * 0.75) + + local mwidth = _NgConfigValues.width + local width = math.floor(wwidth * mwidth) if config.width ~= nil and config.width > 0.3 and config.width < 0.99 then width = math.floor(wwidth * config.width) end - width = math.min(opts.width or 120, width) - opts.width = width - local wheight = config.height or math.floor(api.nvim_get_option("lines") * 0.8) + width = math.min(120, width) + local wheight = math.floor(1 + api.nvim_get_option("lines") + * (_NgConfigValues.height + _NgConfigValues.preview_height)) + local pheight = math.floor(api.nvim_get_option("lines") * _NgConfigValues.preview_height) local prompt = opts.prompt or false if opts.rawdata then data = items @@ -137,8 +140,7 @@ function M.new_list_view(opts) prompt = true end - local lheight = math.min(#data, math.floor(wheight / 2)) - local pheight = math.min(wheight - lheight, math.floor(wheight / 2)) + local lheight = math.min(#data, math.floor(wheight * _NgConfigValues.height)) local r, _ = top_center(lheight, width) diff --git a/lua/navigator/lspclient/mapping.lua b/lua/navigator/lspclient/mapping.lua index f7ca530..acaf7e5 100644 --- a/lua/navigator/lspclient/mapping.lua +++ b/lua/navigator/lspclient/mapping.lua @@ -96,7 +96,7 @@ local function set_mapping(user_opts) local range_fmt = false local doc_fmt = false local ccls = false - log(vim.lsp.buf_get_clients(0)) + -- log(vim.lsp.buf_get_clients(0)) for _, value in pairs(vim.lsp.buf_get_clients(0)) do if value == nil or value.resolved_capabilities == nil then return @@ -108,7 +108,7 @@ local function set_mapping(user_opts) range_fmt = true end - log("override ccls", value.config) + -- log("override ccls", value.config) if value.config.name == "ccls" then ccls = true diff --git a/lua/navigator/reference.lua b/lua/navigator/reference.lua index 4c4873c..a404477 100644 --- a/lua/navigator/reference.lua +++ b/lua/navigator/reference.lua @@ -39,7 +39,8 @@ local function ref_hdlr(err, api, locations, num, bufnr) local ft = vim.api.nvim_buf_get_option(bufnr, "ft") local wwidth = vim.api.nvim_get_option("columns") - width = math.min(width + 30, 120, math.floor(wwidth * 0.8)) + local mwidth = _NgConfigValues.width + width = math.min(width + 30, 120, math.floor(wwidth * mwidth)) gui.new_list_view({ items = items, ft = ft,