mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 19:38:20 +00:00
feat(health): show :checkhealth in floating window #31086
Problem: health can not shown in a floating window Solution: add g:health variable
This commit is contained in:
@@ -21,6 +21,17 @@ To run all healthchecks, use: >vim
|
|||||||
<
|
<
|
||||||
Plugin authors are encouraged to write new healthchecks. |health-dev|
|
Plugin authors are encouraged to write new healthchecks. |health-dev|
|
||||||
|
|
||||||
|
*g:health*
|
||||||
|
g:health This global variable controls the behavior and appearance of the
|
||||||
|
`health` floating window. It should be a dictionary containing the
|
||||||
|
following optional keys:
|
||||||
|
- `style`: string? Determines the display style of the `health` window.
|
||||||
|
Set to `'float'` to enable a floating window. Other
|
||||||
|
styles are not currently supported.
|
||||||
|
|
||||||
|
Example: >lua
|
||||||
|
vim.g.health = { style = 'float' }
|
||||||
|
|
||||||
Commands *health-commands*
|
Commands *health-commands*
|
||||||
|
|
||||||
*:che* *:checkhealth*
|
*:che* *:checkhealth*
|
||||||
|
@@ -2024,7 +2024,7 @@ Lua module: vim.lsp.util *lsp-util*
|
|||||||
• {zindex}? (`integer`) override `zindex`, defaults to 50
|
• {zindex}? (`integer`) override `zindex`, defaults to 50
|
||||||
• {title}? (`string`)
|
• {title}? (`string`)
|
||||||
• {title_pos}? (`'left'|'center'|'right'`)
|
• {title_pos}? (`'left'|'center'|'right'`)
|
||||||
• {relative}? (`'mouse'|'cursor'`) (default: `'cursor'`)
|
• {relative}? (`'mouse'|'cursor'|'editor'`) (default: `'cursor'`)
|
||||||
• {anchor_bias}? (`'auto'|'above'|'below'`, default: `'auto'`) -
|
• {anchor_bias}? (`'auto'|'above'|'below'`, default: `'auto'`) -
|
||||||
"auto": place window based on which side of the
|
"auto": place window based on which side of the
|
||||||
cursor has more lines
|
cursor has more lines
|
||||||
|
@@ -359,6 +359,8 @@ UI
|
|||||||
• |vim.diagnostic.setqflist()| updates an existing quickfix list with the
|
• |vim.diagnostic.setqflist()| updates an existing quickfix list with the
|
||||||
given title if found
|
given title if found
|
||||||
• |ui-messages| content chunks now also contain the highlight group ID.
|
• |ui-messages| content chunks now also contain the highlight group ID.
|
||||||
|
• |:checkhealth| can be display in a floating window and controlled by
|
||||||
|
the |g:health| variable.
|
||||||
|
|
||||||
==============================================================================
|
==============================================================================
|
||||||
CHANGED FEATURES *news-changed*
|
CHANGED FEATURES *news-changed*
|
||||||
|
@@ -11,6 +11,17 @@
|
|||||||
--- <
|
--- <
|
||||||
--- Plugin authors are encouraged to write new healthchecks. |health-dev|
|
--- Plugin authors are encouraged to write new healthchecks. |health-dev|
|
||||||
---
|
---
|
||||||
|
--- *g:health*
|
||||||
|
--- g:health This global variable controls the behavior and appearance of the
|
||||||
|
--- `health` floating window. It should be a dictionary containing the
|
||||||
|
--- following optional keys:
|
||||||
|
--- - `style`: string? Determines the display style of the `health` window.
|
||||||
|
--- Set to `'float'` to enable a floating window. Other
|
||||||
|
--- styles are not currently supported.
|
||||||
|
---
|
||||||
|
--- Example: >lua
|
||||||
|
--- vim.g.health = { style = 'float' }
|
||||||
|
---
|
||||||
--- Commands *health-commands*
|
--- Commands *health-commands*
|
||||||
---
|
---
|
||||||
--- *:che* *:checkhealth*
|
--- *:che* *:checkhealth*
|
||||||
@@ -331,13 +342,31 @@ function M._check(mods, plugin_names)
|
|||||||
|
|
||||||
local emptybuf = vim.fn.bufnr('$') == 1 and vim.fn.getline(1) == '' and 1 == vim.fn.line('$')
|
local emptybuf = vim.fn.bufnr('$') == 1 and vim.fn.getline(1) == '' and 1 == vim.fn.line('$')
|
||||||
|
|
||||||
-- When no command modifiers are used:
|
|
||||||
-- - If the current buffer is empty, open healthcheck directly.
|
|
||||||
-- - If not specified otherwise open healthcheck in a tab.
|
|
||||||
local buf_cmd = #mods > 0 and (mods .. ' sbuffer') or emptybuf and 'buffer' or 'tab sbuffer'
|
|
||||||
|
|
||||||
local bufnr = vim.api.nvim_create_buf(true, true)
|
local bufnr = vim.api.nvim_create_buf(true, true)
|
||||||
vim.cmd(buf_cmd .. ' ' .. bufnr)
|
if
|
||||||
|
vim.g.health
|
||||||
|
and type(vim.g.health) == 'table'
|
||||||
|
and vim.tbl_get(vim.g.health, 'style') == 'float'
|
||||||
|
then
|
||||||
|
local max_height = math.floor(vim.o.lines * 0.8)
|
||||||
|
local max_width = 80
|
||||||
|
local float_bufnr, float_winid = vim.lsp.util.open_floating_preview({}, '', {
|
||||||
|
height = max_height,
|
||||||
|
width = max_width,
|
||||||
|
offset_x = math.floor((vim.o.columns - max_width) / 2),
|
||||||
|
offset_y = math.floor((vim.o.lines - max_height) / 2) - 1,
|
||||||
|
relative = 'editor',
|
||||||
|
})
|
||||||
|
vim.api.nvim_set_current_win(float_winid)
|
||||||
|
vim.bo[float_bufnr].modifiable = true
|
||||||
|
vim.wo[float_winid].list = false
|
||||||
|
else
|
||||||
|
-- When no command modifiers are used:
|
||||||
|
-- - If the current buffer is empty, open healthcheck directly.
|
||||||
|
-- - If not specified otherwise open healthcheck in a tab.
|
||||||
|
local buf_cmd = #mods > 0 and (mods .. ' sbuffer') or emptybuf and 'buffer' or 'tab sbuffer'
|
||||||
|
vim.cmd(buf_cmd .. ' ' .. bufnr)
|
||||||
|
end
|
||||||
|
|
||||||
if vim.fn.bufexists('health://') == 1 then
|
if vim.fn.bufexists('health://') == 1 then
|
||||||
vim.cmd.bwipe('health://')
|
vim.cmd.bwipe('health://')
|
||||||
|
@@ -875,11 +875,13 @@ function M.make_floating_popup_options(width, height, opts)
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
anchor = anchor,
|
anchor = anchor,
|
||||||
|
row = row + (opts.offset_y or 0),
|
||||||
col = col + (opts.offset_x or 0),
|
col = col + (opts.offset_x or 0),
|
||||||
height = height,
|
height = height,
|
||||||
focusable = opts.focusable,
|
focusable = opts.focusable,
|
||||||
relative = opts.relative == 'mouse' and 'mouse' or 'cursor',
|
relative = opts.relative == 'mouse' and 'mouse'
|
||||||
row = row + (opts.offset_y or 0),
|
or opts.relative == 'editor' and 'editor'
|
||||||
|
or 'cursor',
|
||||||
style = 'minimal',
|
style = 'minimal',
|
||||||
width = width,
|
width = width,
|
||||||
border = opts.border or default_border,
|
border = opts.border or default_border,
|
||||||
@@ -1494,7 +1496,7 @@ end
|
|||||||
--- @field title_pos? 'left'|'center'|'right'
|
--- @field title_pos? 'left'|'center'|'right'
|
||||||
---
|
---
|
||||||
--- (default: `'cursor'`)
|
--- (default: `'cursor'`)
|
||||||
--- @field relative? 'mouse'|'cursor'
|
--- @field relative? 'mouse'|'cursor'|'editor'
|
||||||
---
|
---
|
||||||
--- - "auto": place window based on which side of the cursor has more lines
|
--- - "auto": place window based on which side of the cursor has more lines
|
||||||
--- - "above": place the window above the cursor unless there are not enough lines
|
--- - "above": place the window above the cursor unless there are not enough lines
|
||||||
|
@@ -66,6 +66,18 @@ describe(':checkhealth', function()
|
|||||||
eq({}, getcompletion('', 'checkhealth'))
|
eq({}, getcompletion('', 'checkhealth'))
|
||||||
assert_alive()
|
assert_alive()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it('vim.g.health', function()
|
||||||
|
clear()
|
||||||
|
command("let g:health = {'style':'float'}")
|
||||||
|
command('checkhealth lsp')
|
||||||
|
eq(
|
||||||
|
'editor',
|
||||||
|
exec_lua([[
|
||||||
|
return vim.api.nvim_win_get_config(0).relative
|
||||||
|
]])
|
||||||
|
)
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
describe('vim.health', function()
|
describe('vim.health', function()
|
||||||
|
Reference in New Issue
Block a user