Skip to content

Commit 00551ac

Browse files
authored
Merge pull request #15 from mhiro2/perf/persist-ui-cleanups
perf: Optimize rendering and clean up persist/UI code
2 parents 138cec0 + 682a06a commit 00551ac

33 files changed

Lines changed: 532 additions & 96 deletions

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ if you do not pass a name. If `persist.session.prompt_if_missing = true`, you'll
317317
for a name instead of using the default.
318318

319319
> [!WARNING]
320-
> Persistence scope is fixed to the current git repository.
320+
> Persistence target is fixed to the current git repository.
321321
322322
### Auto persist (optional)
323323

@@ -327,7 +327,7 @@ When `persist.auto.enabled = true`, peekstack can automatically restore and save
327327
- **Save** on `PeekstackPush` / `PeekstackClose` / `PeekstackRestorePopup` with a debounce
328328
- **Save on leave** on `VimLeavePre` if `save_on_leave = true`
329329

330-
Auto persist only runs inside a git repository and uses `scope = "repo"` internally. Make sure
330+
Auto persist only runs inside a git repository and always uses the repository session storage. Make sure
331331
`persist.enabled = true` as well.
332332

333333
## 🪟 Popup buffer modes

doc/peekstack.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ PERSIST *peekstack-persist*
417417

418418
Persistence is disabled by default. Enable with `persist.enabled = true`.
419419

420-
Persistence scope is fixed to the current git repository ("repo").
420+
Persistence target is fixed to the current git repository.
421421

422422
`persist.session.default_name` is used when a name is omitted, unless
423423
`persist.session.prompt_if_missing` is true.
@@ -431,7 +431,8 @@ Auto persistence (`persist.auto`) requires `persist.enabled = true`:
431431
debounce_ms debounce time for auto save
432432
save_on_leave save on VimLeavePre
433433

434-
Auto persistence runs only inside a git repository and uses scope "repo".
434+
Auto persistence runs only inside a git repository and always uses
435+
the repository session storage.
435436

436437
==============================================================================
437438
BUFFER MODES *peekstack-buffer-modes*

lua/peekstack/commands.lua

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local M = {}
2+
local notify = require("peekstack.util.notify")
23

34
local loaded = false
45
local COMMAND_NAMES = {
@@ -85,8 +86,9 @@ function M.setup()
8586
persist.list_sessions({
8687
on_done = function(sessions)
8788
local names = vim.tbl_keys(sessions)
89+
table.sort(names)
8890
if #names == 0 then
89-
vim.notify("No saved sessions", vim.log.levels.INFO)
91+
notify.info("No saved sessions")
9092
return
9193
end
9294
vim.ui.select(names, { prompt = "Select a session" }, function(selected)
@@ -113,7 +115,7 @@ function M.setup()
113115
vim.api.nvim_create_user_command("PeekstackDeleteSession", function(opts)
114116
local name = opts.args
115117
if not name or name == "" then
116-
vim.notify("Usage: PeekstackDeleteSession <name>", vim.log.levels.WARN)
118+
notify.warn("Usage: PeekstackDeleteSession <name>")
117119
return
118120
end
119121
vim.ui.select({ "Yes", "No" }, { prompt = "Delete session '" .. name .. "'?" }, function(choice)
@@ -129,14 +131,14 @@ function M.setup()
129131
vim.api.nvim_create_user_command("PeekstackRestorePopup", function()
130132
local restored = require("peekstack.core.stack").restore_last()
131133
if not restored then
132-
vim.notify("No closed popups to restore", vim.log.levels.INFO)
134+
notify.info("No closed popups to restore")
133135
end
134136
end, {})
135137

136138
vim.api.nvim_create_user_command("PeekstackRestoreAllPopups", function()
137139
local restored = require("peekstack.core.stack").restore_all()
138140
if #restored == 0 then
139-
vim.notify("No closed popups to restore", vim.log.levels.INFO)
141+
notify.info("No closed popups to restore")
140142
end
141143
end, {})
142144

@@ -145,7 +147,7 @@ function M.setup()
145147
local loc = require("peekstack.core.location")
146148
local history = stack.history_list()
147149
if #history == 0 then
148-
vim.notify("No history entries", vim.log.levels.INFO)
150+
notify.info("No history entries")
149151
return
150152
end
151153
local items = {}

lua/peekstack/core/location.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ function M.display_text(location, preview_lines, opts)
233233
local raw_path = fs.uri_to_fname(location.uri) or ""
234234
local path = raw_path
235235
if opts.path_base then
236-
path = str.relative_path(raw_path, opts.path_base)
236+
path = str.relative_path(raw_path, opts.path_base, opts)
237237
else
238238
path = str.shorten_path(raw_path)
239239
end

lua/peekstack/core/popup.lua

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local fs = require("peekstack.util.fs")
33
local render = require("peekstack.ui.render")
44
local diagnostics_ui = require("peekstack.ui.diagnostics")
55
local keymaps = require("peekstack.ui.keymaps")
6+
local notify = require("peekstack.util.notify")
67

78
local M = {}
89

@@ -127,18 +128,18 @@ function M.create(location, opts)
127128

128129
local ok_buf, fname = pcall(fs.uri_to_fname, location.uri)
129130
if not ok_buf or not fname then
130-
vim.notify("Failed to resolve file: " .. tostring(location.uri), vim.log.levels.WARN)
131+
notify.warn("Failed to resolve file: " .. tostring(location.uri))
131132
return nil
132133
end
133134

134135
local source_bufnr = vim.fn.bufadd(fname)
135136
if source_bufnr == 0 then
136-
vim.notify("Failed to add buffer: " .. fname, vim.log.levels.WARN)
137+
notify.warn("Failed to add buffer: " .. fname)
137138
return nil
138139
end
139140
local ok_load = pcall(vim.fn.bufload, source_bufnr)
140141
if not ok_load then
141-
vim.notify("Failed to load buffer: " .. fname, vim.log.levels.WARN)
142+
notify.warn("Failed to load buffer: " .. fname)
142143
return nil
143144
end
144145

@@ -158,7 +159,7 @@ function M.create(location, opts)
158159
line_offset = vp_offset
159160
local ok_lines, lines = pcall(vim.api.nvim_buf_get_lines, source_bufnr, vp_start, vp_end, false)
160161
if not ok_lines then
161-
vim.notify("Failed to read buffer contents: " .. fname, vim.log.levels.WARN)
162+
notify.warn("Failed to read buffer contents: " .. fname)
162163
return nil
163164
end
164165
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
@@ -170,7 +171,7 @@ function M.create(location, opts)
170171
if buffer_mode ~= "source" and vim.api.nvim_buf_is_valid(bufnr) then
171172
pcall(vim.api.nvim_buf_delete, bufnr, { force = true })
172173
end
173-
vim.notify("Failed to open popup window", vim.log.levels.WARN)
174+
notify.warn("Failed to open popup window")
174175
return nil
175176
end
176177

lua/peekstack/core/promote.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local fs = require("peekstack.util.fs")
22
local config = require("peekstack.config")
33
local user_events = require("peekstack.core.user_events")
4+
local notify = require("peekstack.util.notify")
45

56
local M = {}
67

@@ -10,7 +11,7 @@ local function open_in_win(winid, location)
1011
local fname = fs.uri_to_fname(location.uri)
1112
local ok, bufnr = pcall(vim.fn.bufadd, fname)
1213
if not ok or not bufnr then
13-
vim.notify("Failed to add buffer: " .. fname, vim.log.levels.WARN)
14+
notify.warn("Failed to add buffer: " .. fname)
1415
return
1516
end
1617
pcall(vim.fn.bufload, bufnr)

lua/peekstack/core/stack.lua

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,9 @@ end
257257
function M.push(location, opts)
258258
deps()
259259
opts = opts or {}
260+
local defer_reflow = opts.defer_reflow == true
260261
local create_opts = vim.tbl_extend("force", {}, opts)
262+
create_opts.defer_reflow = nil
261263
create_opts.parent_popup_id = resolve_parent_popup_id(opts)
262264

263265
-- Handle quick-peek mode (don't add to stack)
@@ -282,13 +284,21 @@ function M.push(location, opts)
282284
table.insert(stack.popups, model)
283285
index_popup(model, stack.root_winid)
284286
stack.focused_id = model.id
285-
layout.reflow(stack)
287+
if not defer_reflow then
288+
layout.reflow(stack)
289+
end
286290

287291
emit_popup_event("PeekstackPush", model, stack.root_winid)
288292

289293
return model
290294
end
291295

296+
---@param winid? integer
297+
function M.reflow(winid)
298+
deps()
299+
layout.reflow(ensure_stack(winid))
300+
end
301+
292302
---@param winid? integer
293303
---@return PeekstackPopupModel[]
294304
function M.list(winid)

lua/peekstack/extensions/fzf_lua.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local ext = require("peekstack.extensions")
2+
local notify = require("peekstack.util.notify")
23

34
local M = {}
45

@@ -29,12 +30,12 @@ local function open_picker(fzf_picker, provider, opts)
2930
opts = opts or {}
3031
local ok, fzf = pcall(require, "fzf-lua")
3132
if not ok then
32-
vim.notify("fzf-lua not available", vim.log.levels.WARN)
33+
notify.warn("fzf-lua not available")
3334
return
3435
end
3536
local fn = fzf[fzf_picker]
3637
if not fn then
37-
vim.notify("fzf-lua." .. fzf_picker .. " not found", vim.log.levels.WARN)
38+
notify.warn("fzf-lua." .. fzf_picker .. " not found")
3839
return
3940
end
4041

lua/peekstack/extensions/snacks.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local ext = require("peekstack.extensions")
2+
local notify = require("peekstack.util.notify")
23

34
local M = {}
45

@@ -28,12 +29,12 @@ local function open_picker(snacks_picker, provider, opts)
2829
opts = opts or {}
2930
local ok, snacks = pcall(require, "snacks.picker")
3031
if not ok then
31-
vim.notify("snacks.nvim not available", vim.log.levels.WARN)
32+
notify.warn("snacks.nvim not available")
3233
return
3334
end
3435
local fn = snacks[snacks_picker]
3536
if not fn then
36-
vim.notify("snacks.picker." .. snacks_picker .. " not found", vim.log.levels.WARN)
37+
notify.warn("snacks.picker." .. snacks_picker .. " not found")
3738
return
3839
end
3940

lua/peekstack/init.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
local notify = require("peekstack.util.notify")
12
local M = {}
23

34
---@type table<string, fun(ctx: PeekstackProviderContext, cb: fun(locations: PeekstackLocation[]))>
@@ -104,7 +105,7 @@ local function prepare_location(loc, opts)
104105
return normalized
105106
end
106107

107-
vim.notify("Invalid location payload: expected uri/range", vim.log.levels.WARN)
108+
notify.warn("Invalid location payload: expected uri/range")
108109
return nil
109110
end
110111

@@ -145,7 +146,7 @@ end
145146
---@param opts? table
146147
function M.peek_locations(locations, opts)
147148
if not locations or #locations == 0 then
148-
vim.notify("No locations", vim.log.levels.INFO)
149+
notify.info("No locations")
149150
return
150151
end
151152
if #locations == 1 then
@@ -167,7 +168,7 @@ end
167168
local function peek_by_provider(provider, opts)
168169
local fn = ensure_provider(provider)
169170
if not fn then
170-
vim.notify("Unknown provider: " .. tostring(provider), vim.log.levels.WARN)
171+
notify.warn("Unknown provider: " .. tostring(provider))
171172
return
172173
end
173174
local context = require("peekstack.core.context")

0 commit comments

Comments
 (0)