feat, refactor: add "bottom" position opt, update to Lua API command creation (#2)

* refactor: use Lua API for user command

    • remove "plugin" dir
    • make toggle() local

* feat: add "bottom" as valid "position" opt

    If "bottom" is given as "position" configuration value, open
    the docs window at the bottom of the window. Adding the "height"
    option complicates setting the window dimensions, e.g. if we are
    opening a split on the sides but also change the height of the
    window, it will resize "prev_win" as well. As a consequence, we
    want to "reset" the width or height vals back to the current win
    dimension depending on the position we choose.

    Associated refactors:
        • add default "height" value in default configuration
        • rename user and default configuration tables for clarity
        • programatically set default configuration table

* refactor: cleanup after change request

    • use tbl_extend() to produce a new configuration table from
      the default cfg and user cfg

    • choose local variables over updating the default cfg when
      updating height and width inside of toggle() based on the
      chosen window position

    • move the default cfg table inside of setup()

* Update README.md

Add GIF displaying functionality

* include demo.gif in the repo
This commit is contained in:
jmp
2022-06-20 18:46:43 -07:00
committed by GitHub
parent 9c186ab938
commit ea36462bb8
5 changed files with 27 additions and 27 deletions

View File

@@ -3,8 +3,7 @@
A neovim plugin to display lsp hover documentation in a side panel. A neovim plugin to display lsp hover documentation in a side panel.
> Inspired by the VSCode extension [Docs View](https://marketplace.visualstudio.com/items?itemName=bierner.docs-view). > Inspired by the VSCode extension [Docs View](https://marketplace.visualstudio.com/items?itemName=bierner.docs-view).
<img alt="doc-view-example" src="demo.gif" width="500" />
<img src="demo.png" width="500"/>
## Installation ## Installation

BIN
demo.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 289 KiB

BIN
demo.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 233 KiB

View File

@@ -1,38 +1,34 @@
local M = {} local M = {}
local config = { local cfg = {}
position = "right",
width = 60,
}
M.setup = function(conf)
if conf.position then
config.position = conf.position
end
if conf.width then
config.width = conf.width
end
end
local buf, win, prev_win, autocmd local buf, win, prev_win, autocmd
M.toggle = function()
local function toggle()
if win and vim.api.nvim_win_is_valid(win) then if win and vim.api.nvim_win_is_valid(win) then
vim.api.nvim_win_close(win, false) vim.api.nvim_win_close(win, false)
vim.api.nvim_del_autocmd(autocmd) vim.api.nvim_del_autocmd(autocmd)
buf, win, prev_win, autocmd = nil, nil, nil, nil buf, win, prev_win, autocmd = nil, nil, nil, nil
else else
local height = cfg["height"]
local width = cfg["width"]
prev_win = vim.api.nvim_get_current_win() prev_win = vim.api.nvim_get_current_win()
if config.position == "left" then if cfg.position == "bottom" then
vim.api.nvim_command("bel new")
width = vim.api.nvim_win_get_width(prev_win)
elseif cfg.position == "left" then
vim.api.nvim_command("topleft vnew") vim.api.nvim_command("topleft vnew")
height = vim.api.nvim_win_get_height(prev_win)
else else
vim.api.nvim_command("botright vnew") vim.api.nvim_command("botright vnew")
height = vim.api.nvim_win_get_height(prev_win)
end end
win = vim.api.nvim_get_current_win() win = vim.api.nvim_get_current_win()
buf = vim.api.nvim_get_current_buf() buf = vim.api.nvim_get_current_buf()
vim.api.nvim_win_set_width(win, math.ceil(config.width)) vim.api.nvim_win_set_height(win, math.ceil(height))
vim.api.nvim_win_set_width(win, math.ceil(width))
vim.api.nvim_buf_set_name(buf, "Docs View") vim.api.nvim_buf_set_name(buf, "Docs View")
vim.api.nvim_buf_set_option(buf, "buftype", "nofile") vim.api.nvim_buf_set_option(buf, "buftype", "nofile")
@@ -73,4 +69,16 @@ M.toggle = function()
end end
end end
M.setup = function(user_cfg)
local default_cfg = {
position = "right",
height = 10,
width = 60,
}
cfg = vim.tbl_extend("force", default_cfg, user_cfg)
vim.api.nvim_create_user_command("DocsViewToggle", toggle, { nargs = 0 })
end
return M return M

View File

@@ -1,7 +0,0 @@
if exists('g:loaded_docs_view')
finish
endif
let g:loaded_docs_view = 1
command! -nargs=0 DocsViewToggle lua require("docs-view").toggle()