aboutsummaryrefslogtreecommitdiffstats
path: root/lua
diff options
context:
space:
mode:
authorRaphael <glepnir@neovim.pro>2022-08-26 20:38:35 +0800
committerGitHub <noreply@github.com>2022-08-26 20:38:35 +0800
commit03981bd991fe700c5a870d0a1422812045426781 (patch)
tree3e492986231b3f89aefbd8b379e1cec99838f56d /lua
parentfix: lspstart should be work without arg (#2090) (diff)
downloadnvim-lspconfig-03981bd991fe700c5a870d0a1422812045426781.tar
nvim-lspconfig-03981bd991fe700c5a870d0a1422812045426781.tar.gz
nvim-lspconfig-03981bd991fe700c5a870d0a1422812045426781.tar.bz2
nvim-lspconfig-03981bd991fe700c5a870d0a1422812045426781.tar.lz
nvim-lspconfig-03981bd991fe700c5a870d0a1422812045426781.tar.xz
nvim-lspconfig-03981bd991fe700c5a870d0a1422812045426781.tar.zst
nvim-lspconfig-03981bd991fe700c5a870d0a1422812045426781.zip
feat: improve LspInfo (#2081)
* feat: improve LspInfo * feat: update README for highlight * fix: wrong typo * fix: ci failed * fix: remove unnecessary block * fix: stylua format * fix: set default border to none * fix: update the doc * fix: define names in if statement * fix: use default_options to set border * fix: use available servers list * fix: fixup * fix: format by stylua * fix: use bufdelete event * fix: format * fix: add tips * fix: stylua format * fix: use wrap * fix: add 122 to luacheck ignore * fix: reset the default options * fix: merge master * fix: remove unecessary code * feat: update the highlight group * feat: update doc for highlight * fix: remove highlig from README * fix: remae highlight group in doc
Diffstat (limited to 'lua')
-rw-r--r--lua/lspconfig/ui/lspinfo.lua54
-rw-r--r--lua/lspconfig/ui/windows.lua30
2 files changed, 62 insertions, 22 deletions
diff --git a/lua/lspconfig/ui/lspinfo.lua b/lua/lspconfig/ui/lspinfo.lua
index e9066b7c..6b1c52d1 100644
--- a/lua/lspconfig/ui/lspinfo.lua
+++ b/lua/lspconfig/ui/lspinfo.lua
@@ -1,3 +1,4 @@
+local api = vim.api
local configs = require 'lspconfig.configs'
local windows = require 'lspconfig.ui.windows'
local util = require 'lspconfig.util'
@@ -52,7 +53,7 @@ local function make_config_info(config, bufnr)
config_info.cmd_is_executable = 'NA'
end
- local buffer_dir = vim.api.nvim_buf_call(bufnr, function()
+ local buffer_dir = api.nvim_buf_call(bufnr, function()
return vim.fn.expand '%:p:h'
end)
local root_dir = config.get_root_dir(buffer_dir)
@@ -150,7 +151,12 @@ return function()
local buf_clients = vim.lsp.buf_get_clients()
local clients = vim.lsp.get_active_clients()
local buffer_filetype = vim.bo.filetype
- local original_bufnr = vim.api.nvim_get_current_buf()
+ local original_bufnr = api.nvim_get_current_buf()
+
+ windows.default_options.wrap = true
+ windows.default_options.breakindent = true
+ windows.default_options.breakindentopt = 'shift:25'
+ windows.default_options.showbreak = 'NONE'
local win_info = windows.percentage_range_window(0.8, 0.7)
local bufnr, win_id = win_info.bufnr, win_info.win_id
@@ -169,6 +175,9 @@ return function()
end
end
+ -- insert the tips at the top of window
+ table.insert(buf_lines, 'Use [q] or [Esc] to quit the window')
+
local header = {
'',
'Language client log: ' .. (vim.lsp.get_log_path()),
@@ -216,22 +225,39 @@ return function()
local matching_config_header = {
'',
- 'Configured servers list: ' .. table.concat(vim.tbl_keys(configs), ', '),
+ 'Configured servers list: ' .. table.concat(util.available_servers(), ', '),
}
+
vim.list_extend(buf_lines, matching_config_header)
local fmt_buf_lines = indent_lines(buf_lines, ' ')
fmt_buf_lines = vim.lsp.util._trim(fmt_buf_lines, {})
- vim.api.nvim_buf_set_lines(bufnr, 0, -1, true, fmt_buf_lines)
- vim.api.nvim_buf_set_option(bufnr, 'modifiable', false)
- vim.api.nvim_buf_set_option(bufnr, 'filetype', 'lspinfo')
+ api.nvim_buf_set_lines(bufnr, 0, -1, true, fmt_buf_lines)
+ api.nvim_buf_set_option(bufnr, 'modifiable', false)
+ api.nvim_buf_set_option(bufnr, 'filetype', 'lspinfo')
- vim.api.nvim_buf_set_keymap(bufnr, 'n', '<esc>', '<cmd>bd<CR>', { noremap = true })
- vim.api.nvim_command(
- string.format('autocmd BufHidden,BufLeave <buffer> ++once lua pcall(vim.api.nvim_win_close, %d, true)', win_id)
- )
+ local augroup = api.nvim_create_augroup('lspinfo', { clear = false })
+
+ local function close()
+ api.nvim_clear_autocmds { group = augroup, buffer = bufnr }
+ if api.nvim_buf_is_valid(bufnr) then
+ api.nvim_buf_delete(bufnr, { force = true })
+ end
+ if api.nvim_win_is_valid(win_id) then
+ api.nvim_win_close(win_id, true)
+ end
+ end
+
+ 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' }, {
+ once = true,
+ buffer = bufnr,
+ callback = close,
+ group = augroup,
+ })
vim.fn.matchadd(
'Error',
@@ -246,12 +272,14 @@ return function()
vim.cmd 'let m=matchadd("string", "true")'
vim.cmd 'let m=matchadd("error", "false")'
for _, config in pairs(configs) do
- vim.fn.matchadd('Title', '\\%(Client\\|Config\\):.*\\zs' .. config.name .. '\\ze')
- vim.fn.matchadd('Visual', 'list:.*\\zs' .. config.name .. '\\ze')
+ vim.fn.matchadd('LspInfoTitle', '\\%(Client\\|Config\\):.*\\zs' .. config.name .. '\\ze')
+ vim.fn.matchadd('LspInfoList', 'list:.*\\zs' .. config.name .. '\\ze')
if config.filetypes then
for _, ft in pairs(config.filetypes) do
- vim.fn.matchadd('Type', '\\%(filetypes\\|filetype\\):.*\\zs' .. ft .. '\\ze')
+ vim.fn.matchadd('LspInfoFiletype', '\\%(filetypes\\|filetype\\):.*\\zs' .. ft .. '\\ze')
end
end
end
+
+ api.nvim_buf_add_highlight(bufnr, 0, 'LspInfoTip', 0, 0, -1)
end
diff --git a/lua/lspconfig/ui/windows.lua b/lua/lspconfig/ui/windows.lua
index 8a39204d..c4149b4c 100644
--- a/lua/lspconfig/ui/windows.lua
+++ b/lua/lspconfig/ui/windows.lua
@@ -1,6 +1,8 @@
-- The following is extracted and modified from plenary.vnim by
-- TJ Devries. It is not a stable API, and is expected to change
--
+local api = vim.api
+
local function apply_defaults(original, defaults)
if original == nil then
original = {}
@@ -19,13 +21,10 @@ end
local win_float = {}
-win_float.default_options = {
- winblend = 15,
- percentage = 0.9,
-}
+win_float.default_options = {}
function win_float.default_opts(options)
- options = apply_defaults(options, win_float.default_options)
+ options = apply_defaults(options, { percentage = 0.9 })
local width = math.floor(vim.o.columns * options.percentage)
local height = math.floor(vim.o.lines * options.percentage)
@@ -52,6 +51,8 @@ function win_float.default_opts(options)
},
}
+ opts.border = options.border and options.border
+
return opts
end
@@ -85,6 +86,7 @@ function win_float.percentage_range_window(col_range, row_range, options)
win_opts.height = math.ceil(vim.o.lines * height_percentage)
win_opts.row = math.ceil(vim.o.lines * row_start_percentage)
+ win_opts.border = options.border or 'none'
local width_percentage, col_start_percentage
if type(col_range) == 'number' then
@@ -102,11 +104,21 @@ function win_float.percentage_range_window(col_range, row_range, options)
win_opts.col = math.floor(vim.o.columns * col_start_percentage)
win_opts.width = math.floor(vim.o.columns * width_percentage)
- local bufnr = options.bufnr or vim.api.nvim_create_buf(false, true)
- local win_id = vim.api.nvim_open_win(bufnr, true, win_opts)
- vim.api.nvim_win_set_buf(win_id, bufnr)
+ local bufnr = options.bufnr or api.nvim_create_buf(false, true)
+ local win_id = api.nvim_open_win(bufnr, true, win_opts)
+ api.nvim_win_set_option(win_id, 'winhl', 'FloatBorder:LspInfoBorder')
+
+ for k, v in pairs(win_float.default_options) do
+ if k ~= 'border' then
+ vim.opt_local[k] = v
+ end
+ end
+
+ api.nvim_win_set_buf(win_id, bufnr)
- vim.cmd 'setlocal nocursorcolumn ts=2 sw=2'
+ api.nvim_win_set_option(win_id, 'cursorcolumn', false)
+ api.nvim_buf_set_option(bufnr, 'tabstop', 2)
+ api.nvim_buf_set_option(bufnr, 'shiftwidth', 2)
return {
bufnr = bufnr,