Skip to content

Commit 0490ea5

Browse files
authored
feat(info): add backdrop to NullLsInfo window (#326)
* feat(info): add backdrop * fix(info): disable backdrop by default
1 parent f61f46d commit 0490ea5

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

lua/null-ls/config.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ local defaults = {
2121
update_in_insert = false,
2222
-- prevent double setup
2323
_setup = false,
24+
backdrop = 100,
2425
}
2526

2627
local config = vim.deepcopy(defaults)
@@ -34,6 +35,7 @@ local type_overrides = {
3435
sources = { "table", "nil" },
3536
temp_dir = { "string", "nil" },
3637
border = { "table", "string", "nil" },
38+
backdrop = { "number", "nil" },
3739
}
3840

3941
local wanted_type = function(k)

lua/null-ls/info.lua

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ local make_window = function(height_percentage, width_percentage, border)
2525
height = height,
2626
style = "minimal",
2727
border = border or "solid",
28+
zindex = 50,
2829
}
2930

3031
local bufnr = api.nvim_create_buf(false, true)
@@ -36,6 +37,40 @@ local make_window = function(height_percentage, width_percentage, border)
3637
return bufnr, win_id
3738
end
3839

40+
local make_backdrop = function(backdrop)
41+
-- adapted from `lazy.nvim`
42+
local normal, has_bg
43+
if vim.fn.has("nvim-0.9.0") == 0 then
44+
normal = vim.api.nvim_get_hl_by_name("Normal", true)
45+
has_bg = normal and normal.background ~= nil
46+
else
47+
normal = vim.api.nvim_get_hl(0, { name = "Normal" })
48+
has_bg = normal and normal.bg ~= nil
49+
end
50+
51+
if has_bg and backdrop and backdrop < 100 and vim.o.termguicolors then
52+
local backdrop_buf = api.nvim_create_buf(false, true)
53+
local backdrop_win = api.nvim_open_win(backdrop_buf, false, {
54+
relative = "editor",
55+
width = vim.o.columns,
56+
height = vim.o.lines,
57+
row = 0,
58+
col = 0,
59+
style = "minimal",
60+
focusable = false,
61+
zindex = 49,
62+
})
63+
64+
vim.api.nvim_set_hl(0, "NullLsBackdrop", { bg = "#000000", default = true })
65+
vim.wo[backdrop_win].winhighlight = "Normal:NullLsBackdrop"
66+
vim.wo[backdrop_win].winblend = backdrop
67+
vim.bo[backdrop_buf].buftype = "nofile"
68+
vim.bo[backdrop_buf].filetype = "null-ls-backdrop"
69+
70+
return backdrop_buf, backdrop_win
71+
end
72+
end
73+
3974
local function indent_lines(lines, offset)
4075
offset = offset or "\t"
4176
return vim.tbl_map(function(val)
@@ -159,6 +194,7 @@ M.show_window = function(opts)
159194
lines = vim.list_extend(lines, indent_lines(info_lines))
160195
end
161196

197+
local backdrop_buf, backdrop_win = make_backdrop(opts.backdrop or c.get().backdrop)
162198
local win_bufnr, win_id = make_window(0.8, 0.7, opts.border or c.get().border)
163199
api.nvim_set_option_value("winhl", "FloatBorder:NullLsInfoBorder", { win = win_id })
164200

@@ -172,6 +208,13 @@ M.show_window = function(opts)
172208
end
173209

174210
local close = function()
211+
if backdrop_win and api.nvim_win_is_valid(backdrop_win) then
212+
api.nvim_win_close(backdrop_win, true)
213+
end
214+
if backdrop_buf and api.nvim_buf_is_valid(backdrop_buf) then
215+
api.nvim_buf_delete(backdrop_buf, { force = true })
216+
end
217+
175218
if api.nvim_buf_is_valid(win_bufnr) then
176219
api.nvim_buf_delete(win_bufnr, { force = true })
177220
end

0 commit comments

Comments
 (0)