Skip to content

Commit b9fda3b

Browse files
committed
feat(health): add picker backend, persist, and tree-sitter diagnostics
Extend :checkhealth to verify that the configured picker backend plugin is installed, report persist status and git repo detection, and check tree-sitter parser availability when ui.title.context is enabled.
1 parent e074b79 commit b9fda3b

2 files changed

Lines changed: 181 additions & 0 deletions

File tree

lua/peekstack/health.lua

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
local M = {}
22

3+
---@type table<string, string>
4+
local PICKER_MODULES = {
5+
telescope = "telescope",
6+
["fzf-lua"] = "fzf-lua",
7+
snacks = "snacks",
8+
}
9+
310
function M.check()
411
vim.health.start("peekstack")
512

@@ -14,6 +21,54 @@ function M.check()
1421
else
1522
vim.health.warn("rg not found (grep.search will be unavailable)")
1623
end
24+
25+
local ok, cfg_mod = pcall(require, "peekstack.config")
26+
if not ok then
27+
return
28+
end
29+
local cfg = cfg_mod.get()
30+
31+
-- Picker backend
32+
local backend = cfg.picker and cfg.picker.backend
33+
if backend and backend ~= "builtin" then
34+
local plugin_name = PICKER_MODULES[backend]
35+
if plugin_name then
36+
local has = pcall(require, plugin_name)
37+
if has then
38+
vim.health.ok("picker backend '" .. backend .. "' available")
39+
else
40+
vim.health.warn("picker backend '" .. backend .. "' is configured but the plugin is not installed")
41+
end
42+
else
43+
vim.health.warn("unknown picker backend '" .. backend .. "'")
44+
end
45+
end
46+
47+
-- Persist
48+
local persist = cfg.persist
49+
if persist and persist.enabled then
50+
local fs = require("peekstack.util.fs")
51+
local repo = fs.repo_root()
52+
if repo then
53+
vim.health.ok("persist enabled (repo: " .. repo .. ")")
54+
else
55+
vim.health.warn("persist enabled but not inside a git repository; sessions will use cwd-based storage")
56+
end
57+
if persist.auto and persist.auto.enabled then
58+
vim.health.ok("auto persist enabled (session: " .. (persist.auto.session_name or "auto") .. ")")
59+
end
60+
end
61+
62+
-- Tree-sitter context
63+
local title = cfg.ui and cfg.ui.title
64+
if title and title.context and title.context.enabled then
65+
local ts_ok = pcall(vim.treesitter.get_parser, 0)
66+
if ts_ok then
67+
vim.health.ok("tree-sitter context enabled (parser available for current buffer)")
68+
else
69+
vim.health.info("tree-sitter context enabled but no parser for the current buffer filetype")
70+
end
71+
end
1772
end
1873

1974
return M

tests/health_spec.lua

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
describe("peekstack.health", function()
2+
local health = require("peekstack.health")
3+
local config = require("peekstack.config")
4+
5+
local original_health_start
6+
local original_health_ok
7+
local original_health_warn
8+
local original_health_error
9+
local original_health_info
10+
local original_executable
11+
local original_has
12+
13+
---@type string[]
14+
local messages
15+
16+
before_each(function()
17+
messages = {}
18+
original_health_start = vim.health.start
19+
original_health_ok = vim.health.ok
20+
original_health_warn = vim.health.warn
21+
original_health_error = vim.health.error
22+
original_health_info = vim.health.info
23+
original_executable = vim.fn.executable
24+
original_has = vim.fn.has
25+
26+
vim.health.start = function() end
27+
vim.health.ok = function(msg)
28+
table.insert(messages, "ok:" .. msg)
29+
end
30+
vim.health.warn = function(msg)
31+
table.insert(messages, "warn:" .. msg)
32+
end
33+
vim.health.error = function(msg)
34+
table.insert(messages, "error:" .. msg)
35+
end
36+
vim.health.info = function(msg)
37+
table.insert(messages, "info:" .. msg)
38+
end
39+
end)
40+
41+
after_each(function()
42+
vim.health.start = original_health_start
43+
vim.health.ok = original_health_ok
44+
vim.health.warn = original_health_warn
45+
vim.health.error = original_health_error
46+
vim.health.info = original_health_info
47+
vim.fn.executable = original_executable
48+
vim.fn.has = original_has
49+
config.setup({})
50+
end)
51+
52+
it("reports ok for nvim version and rg when available", function()
53+
vim.fn.has = function()
54+
return 1
55+
end
56+
vim.fn.executable = function()
57+
return 1
58+
end
59+
config.setup({})
60+
61+
health.check()
62+
63+
assert.is_true(vim.list_contains(messages, "ok:nvim >= 0.10"))
64+
assert.is_true(vim.list_contains(messages, "ok:rg available"))
65+
end)
66+
67+
it("warns when rg is not available", function()
68+
vim.fn.has = function()
69+
return 1
70+
end
71+
vim.fn.executable = function()
72+
return 0
73+
end
74+
config.setup({})
75+
76+
health.check()
77+
78+
local found = false
79+
for _, msg in ipairs(messages) do
80+
if msg:find("warn:rg not found") then
81+
found = true
82+
end
83+
end
84+
assert.is_true(found)
85+
end)
86+
87+
it("warns when configured picker backend is not installed", function()
88+
vim.fn.has = function()
89+
return 1
90+
end
91+
vim.fn.executable = function()
92+
return 1
93+
end
94+
config.setup({ picker = { backend = "telescope" } })
95+
96+
health.check()
97+
98+
local found = false
99+
for _, msg in ipairs(messages) do
100+
if msg:find("warn:") and msg:find("telescope") and msg:find("not installed") then
101+
found = true
102+
end
103+
end
104+
assert.is_true(found)
105+
end)
106+
107+
it("reports persist status when enabled inside a git repo", function()
108+
vim.fn.has = function()
109+
return 1
110+
end
111+
vim.fn.executable = function()
112+
return 1
113+
end
114+
config.setup({ persist = { enabled = true } })
115+
116+
health.check()
117+
118+
local found_persist = false
119+
for _, msg in ipairs(messages) do
120+
if msg:find("persist") then
121+
found_persist = true
122+
end
123+
end
124+
assert.is_true(found_persist)
125+
end)
126+
end)

0 commit comments

Comments
 (0)