aboutsummaryrefslogtreecommitdiffstats
path: root/lua/lspconfig/ui
diff options
context:
space:
mode:
authorRaphael <glepnir@neovim.pro>2023-01-11 16:15:44 +0800
committerGitHub <noreply@github.com>2023-01-11 16:15:44 +0800
commit949e65afbaec2c62fc73ccbbced80cc86cfcd8c1 (patch)
tree0d22005ba23c3b61495089a6e62d26ece9de533f /lua/lspconfig/ui
parentdocs: update server_configurations.md (diff)
downloadnvim-lspconfig-949e65afbaec2c62fc73ccbbced80cc86cfcd8c1.tar
nvim-lspconfig-949e65afbaec2c62fc73ccbbced80cc86cfcd8c1.tar.gz
nvim-lspconfig-949e65afbaec2c62fc73ccbbced80cc86cfcd8c1.tar.bz2
nvim-lspconfig-949e65afbaec2c62fc73ccbbced80cc86cfcd8c1.tar.lz
nvim-lspconfig-949e65afbaec2c62fc73ccbbced80cc86cfcd8c1.tar.xz
nvim-lspconfig-949e65afbaec2c62fc73ccbbced80cc86cfcd8c1.tar.zst
nvim-lspconfig-949e65afbaec2c62fc73ccbbced80cc86cfcd8c1.zip
feat: support show server doc description in LspInfo (#2373)
* feat: support show server doc description in LspInfo * feat: add show other match client desc * fix: check buf unload * fix: desc Co-authored-by: William Boman <william@redwill.se> * fix: imrove * fix: improve Co-authored-by: William Boman <william@redwill.se>
Diffstat (limited to 'lua/lspconfig/ui')
-rw-r--r--lua/lspconfig/ui/lspinfo.lua57
1 files changed, 54 insertions, 3 deletions
diff --git a/lua/lspconfig/ui/lspinfo.lua b/lua/lspconfig/ui/lspinfo.lua
index 942d65bc..e080baae 100644
--- a/lua/lspconfig/ui/lspinfo.lua
+++ b/lua/lspconfig/ui/lspinfo.lua
@@ -202,7 +202,7 @@ return function()
end
-- insert the tips at the top of window
- table.insert(buf_lines, 'Use [q] or [Esc] to quit the window')
+ table.insert(buf_lines, 'Press q or <Esc> to close this window. Press <Tab> to view server doc.')
local header = {
'',
@@ -268,7 +268,7 @@ return function()
local function close()
api.nvim_clear_autocmds { group = augroup, buffer = bufnr }
- if api.nvim_buf_is_valid(bufnr) then
+ if api.nvim_buf_is_loaded(bufnr) then
api.nvim_buf_delete(bufnr, { force = true })
end
if api.nvim_win_is_valid(win_id) then
@@ -278,7 +278,7 @@ return function()
vim.keymap.set('n', '<ESC>', close, { buffer = bufnr, nowait = true })
vim.keymap.set('n', 'q', close, { buffer = bufnr, nowait = true })
- api.nvim_create_autocmd({ 'BufDelete', 'BufLeave', 'BufHidden' }, {
+ api.nvim_create_autocmd({ 'BufDelete', 'BufHidden' }, {
once = true,
buffer = bufnr,
callback = close,
@@ -306,4 +306,55 @@ return function()
]]
api.nvim_buf_add_highlight(bufnr, 0, 'LspInfoTip', 0, 0, -1)
+
+ local function show_doc()
+ local lines = {}
+ local function append_lines(config)
+ if not config then
+ return
+ end
+ local desc = vim.tbl_get(config, 'document_config', 'docs', 'description')
+ if desc then
+ table.insert(lines, string.format('# %s', config.name))
+ table.insert(lines, '')
+ vim.list_extend(lines, vim.split(desc, '\n'))
+ table.insert(lines, '')
+ end
+ end
+
+ table.insert(lines, 'Press <Tab> to close server info.')
+ table.insert(lines, '')
+
+ for _, client in pairs(buf_clients) do
+ local config = require('lspconfig.configs')[client.name]
+ append_lines(config)
+ end
+
+ for _, config in pairs(other_matching_configs) do
+ append_lines(config)
+ end
+
+ local info = windows.percentage_range_window(0.8, 0.7)
+ lines = indent_lines(lines, ' ')
+ lines = vim.lsp.util._trim(lines, {})
+ api.nvim_buf_set_lines(info.bufnr, 0, -1, false, lines)
+ api.nvim_buf_add_highlight(info.bufnr, 0, 'LspInfoTip', 0, 0, -1)
+
+ vim.bo[info.bufnr].filetype = 'markdown'
+ vim.bo[info.bufnr].syntax = 'on'
+ vim.wo[info.win_id].concealcursor = 'niv'
+ vim.wo[info.win_id].conceallevel = 2
+ vim.wo[info.win_id].breakindent = false
+ vim.wo[info.win_id].breakindentopt = ''
+
+ local close_doc_win = function()
+ if api.nvim_win_is_valid(info.win_id) then
+ api.nvim_win_close(info.win_id, true)
+ end
+ end
+
+ vim.keymap.set('n', '<TAB>', close_doc_win, { buffer = info.bufnr })
+ end
+
+ vim.keymap.set('n', '<TAB>', show_doc, { buffer = true, nowait = true })
end