mirror of
https://github.com/tiyn/nvim-docs-view.git
synced 2025-11-13 13:59:46 +01:00
init
This commit is contained in:
22
README.md
Normal file
22
README.md
Normal file
@@ -0,0 +1,22 @@
|
||||
# nvim-docs-view
|
||||
|
||||
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).
|
||||
|
||||
### Installation
|
||||
|
||||
Using [vim-plug](https://github.com/junegunn/vim-plug)
|
||||
|
||||
```viml
|
||||
Plug 'amrbashir/nvim-docs-view'
|
||||
```
|
||||
|
||||
Using [packer.nvim](https://github.com/wbthomason/packer.nvim)
|
||||
|
||||
```lua
|
||||
use { 'amrbashir/nvim-docs-view' }
|
||||
```
|
||||
|
||||
### Usage
|
||||
|
||||
Use `:DocsViewOpen` to open the docs view side panel
|
||||
59
lua/docs_view.lua
Normal file
59
lua/docs_view.lua
Normal file
@@ -0,0 +1,59 @@
|
||||
local buf, win, start_win
|
||||
local api = vim.api
|
||||
local lsp = vim.lsp
|
||||
|
||||
local function split(s, delimiter)
|
||||
result = {};
|
||||
for match in (s..delimiter):gmatch("(.-)"..delimiter) do
|
||||
table.insert(result, match);
|
||||
end
|
||||
return result;
|
||||
end
|
||||
|
||||
local function open()
|
||||
if win and api.nvim_win_is_valid(win) then return end
|
||||
|
||||
start_win = api.nvim_get_current_win()
|
||||
|
||||
api.nvim_command("botright vnew")
|
||||
|
||||
win = api.nvim_get_current_win()
|
||||
buf = api.nvim_get_current_buf()
|
||||
|
||||
api.nvim_buf_set_name(buf, "Docs View")
|
||||
api.nvim_buf_set_option(buf, "buftype", "nofile")
|
||||
api.nvim_buf_set_option(buf, "swapfile", false)
|
||||
api.nvim_buf_set_option(buf, "bufhidden", "wipe")
|
||||
api.nvim_buf_set_option(buf, "filetype", "nvim-docs-view")
|
||||
|
||||
-- api.nvim_win_set_option(win, "wrap", false)
|
||||
|
||||
api.nvim_set_current_win(start_win)
|
||||
|
||||
api.nvim_create_autocmd(
|
||||
{ "CursorHold" },
|
||||
{ pattern = "*", callback = function()
|
||||
local l,c = unpack(api.nvim_win_get_cursor(0))
|
||||
lsp.buf_request(0, "textDocument/hover", {
|
||||
textDocument = { uri = "file://"..api.nvim_buf_get_name(0) },
|
||||
position = { line = l - 1, character = c }
|
||||
}, function(err, result, ctx, config)
|
||||
if not (result and result.contents) then return end
|
||||
|
||||
local md_lines = lsp.util.convert_input_to_markdown_lines(result.contents)
|
||||
md_lines = lsp.util.trim_empty_lines(md_lines)
|
||||
if vim.tbl_isempty(md_lines) then return end
|
||||
|
||||
api.nvim_buf_set_option(buf, "modifiable", true)
|
||||
lsp.util.stylize_markdown(buf, md_lines)
|
||||
api.nvim_buf_set_option(buf, "modifiable", false)
|
||||
end
|
||||
)
|
||||
end
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
return {
|
||||
open = open
|
||||
}
|
||||
7
plugin/docs_view.vim
Normal file
7
plugin/docs_view.vim
Normal file
@@ -0,0 +1,7 @@
|
||||
if exists('g:loaded_docs_view')
|
||||
finish
|
||||
endif
|
||||
let g:loaded_docs_view = 1
|
||||
|
||||
command! DocsViewOpen lua require'docs_view'.open()
|
||||
|
||||
Reference in New Issue
Block a user