Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ if you do not pass a name. If `persist.session.prompt_if_missing = true`, you'll
for a name instead of using the default.

> [!WARNING]
> Persistence scope is fixed to the current git repository.
> Persistence target is fixed to the current git repository.

### Auto persist (optional)

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

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

## 🪟 Popup buffer modes
Expand Down
5 changes: 3 additions & 2 deletions doc/peekstack.txt
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ PERSIST *peekstack-persist*

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

Persistence scope is fixed to the current git repository ("repo").
Persistence target is fixed to the current git repository.

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

Auto persistence runs only inside a git repository and uses scope "repo".
Auto persistence runs only inside a git repository and always uses
the repository session storage.

==============================================================================
BUFFER MODES *peekstack-buffer-modes*
Expand Down
12 changes: 7 additions & 5 deletions lua/peekstack/commands.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local M = {}
local notify = require("peekstack.util.notify")

local loaded = false
local COMMAND_NAMES = {
Expand Down Expand Up @@ -85,8 +86,9 @@ function M.setup()
persist.list_sessions({
on_done = function(sessions)
local names = vim.tbl_keys(sessions)
table.sort(names)
if #names == 0 then
vim.notify("No saved sessions", vim.log.levels.INFO)
notify.info("No saved sessions")
return
end
vim.ui.select(names, { prompt = "Select a session" }, function(selected)
Expand All @@ -113,7 +115,7 @@ function M.setup()
vim.api.nvim_create_user_command("PeekstackDeleteSession", function(opts)
local name = opts.args
if not name or name == "" then
vim.notify("Usage: PeekstackDeleteSession <name>", vim.log.levels.WARN)
notify.warn("Usage: PeekstackDeleteSession <name>")
return
end
vim.ui.select({ "Yes", "No" }, { prompt = "Delete session '" .. name .. "'?" }, function(choice)
Expand All @@ -129,14 +131,14 @@ function M.setup()
vim.api.nvim_create_user_command("PeekstackRestorePopup", function()
local restored = require("peekstack.core.stack").restore_last()
if not restored then
vim.notify("No closed popups to restore", vim.log.levels.INFO)
notify.info("No closed popups to restore")
end
end, {})

vim.api.nvim_create_user_command("PeekstackRestoreAllPopups", function()
local restored = require("peekstack.core.stack").restore_all()
if #restored == 0 then
vim.notify("No closed popups to restore", vim.log.levels.INFO)
notify.info("No closed popups to restore")
end
end, {})

Expand All @@ -145,7 +147,7 @@ function M.setup()
local loc = require("peekstack.core.location")
local history = stack.history_list()
if #history == 0 then
vim.notify("No history entries", vim.log.levels.INFO)
notify.info("No history entries")
return
end
local items = {}
Expand Down
2 changes: 1 addition & 1 deletion lua/peekstack/core/location.lua
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ function M.display_text(location, preview_lines, opts)
local raw_path = fs.uri_to_fname(location.uri) or ""
local path = raw_path
if opts.path_base then
path = str.relative_path(raw_path, opts.path_base)
path = str.relative_path(raw_path, opts.path_base, opts)
else
path = str.shorten_path(raw_path)
end
Expand Down
11 changes: 6 additions & 5 deletions lua/peekstack/core/popup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local fs = require("peekstack.util.fs")
local render = require("peekstack.ui.render")
local diagnostics_ui = require("peekstack.ui.diagnostics")
local keymaps = require("peekstack.ui.keymaps")
local notify = require("peekstack.util.notify")

local M = {}

Expand Down Expand Up @@ -127,18 +128,18 @@ function M.create(location, opts)

local ok_buf, fname = pcall(fs.uri_to_fname, location.uri)
if not ok_buf or not fname then
vim.notify("Failed to resolve file: " .. tostring(location.uri), vim.log.levels.WARN)
notify.warn("Failed to resolve file: " .. tostring(location.uri))
return nil
end

local source_bufnr = vim.fn.bufadd(fname)
if source_bufnr == 0 then
vim.notify("Failed to add buffer: " .. fname, vim.log.levels.WARN)
notify.warn("Failed to add buffer: " .. fname)
return nil
end
local ok_load = pcall(vim.fn.bufload, source_bufnr)
if not ok_load then
vim.notify("Failed to load buffer: " .. fname, vim.log.levels.WARN)
notify.warn("Failed to load buffer: " .. fname)
return nil
end

Expand All @@ -158,7 +159,7 @@ function M.create(location, opts)
line_offset = vp_offset
local ok_lines, lines = pcall(vim.api.nvim_buf_get_lines, source_bufnr, vp_start, vp_end, false)
if not ok_lines then
vim.notify("Failed to read buffer contents: " .. fname, vim.log.levels.WARN)
notify.warn("Failed to read buffer contents: " .. fname)
return nil
end
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
Expand All @@ -170,7 +171,7 @@ function M.create(location, opts)
if buffer_mode ~= "source" and vim.api.nvim_buf_is_valid(bufnr) then
pcall(vim.api.nvim_buf_delete, bufnr, { force = true })
end
vim.notify("Failed to open popup window", vim.log.levels.WARN)
notify.warn("Failed to open popup window")
return nil
end

Expand Down
3 changes: 2 additions & 1 deletion lua/peekstack/core/promote.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local fs = require("peekstack.util.fs")
local config = require("peekstack.config")
local user_events = require("peekstack.core.user_events")
local notify = require("peekstack.util.notify")

local M = {}

Expand All @@ -10,7 +11,7 @@ local function open_in_win(winid, location)
local fname = fs.uri_to_fname(location.uri)
local ok, bufnr = pcall(vim.fn.bufadd, fname)
if not ok or not bufnr then
vim.notify("Failed to add buffer: " .. fname, vim.log.levels.WARN)
notify.warn("Failed to add buffer: " .. fname)
return
end
pcall(vim.fn.bufload, bufnr)
Expand Down
12 changes: 11 additions & 1 deletion lua/peekstack/core/stack.lua
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,9 @@ end
function M.push(location, opts)
deps()
opts = opts or {}
local defer_reflow = opts.defer_reflow == true
local create_opts = vim.tbl_extend("force", {}, opts)
create_opts.defer_reflow = nil
create_opts.parent_popup_id = resolve_parent_popup_id(opts)

-- Handle quick-peek mode (don't add to stack)
Expand All @@ -282,13 +284,21 @@ function M.push(location, opts)
table.insert(stack.popups, model)
index_popup(model, stack.root_winid)
stack.focused_id = model.id
layout.reflow(stack)
if not defer_reflow then
layout.reflow(stack)
end

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

return model
end

---@param winid? integer
function M.reflow(winid)
deps()
layout.reflow(ensure_stack(winid))
end

---@param winid? integer
---@return PeekstackPopupModel[]
function M.list(winid)
Expand Down
5 changes: 3 additions & 2 deletions lua/peekstack/extensions/fzf_lua.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local ext = require("peekstack.extensions")
local notify = require("peekstack.util.notify")

local M = {}

Expand Down Expand Up @@ -29,12 +30,12 @@ local function open_picker(fzf_picker, provider, opts)
opts = opts or {}
local ok, fzf = pcall(require, "fzf-lua")
if not ok then
vim.notify("fzf-lua not available", vim.log.levels.WARN)
notify.warn("fzf-lua not available")
return
end
local fn = fzf[fzf_picker]
if not fn then
vim.notify("fzf-lua." .. fzf_picker .. " not found", vim.log.levels.WARN)
notify.warn("fzf-lua." .. fzf_picker .. " not found")
return
end

Expand Down
5 changes: 3 additions & 2 deletions lua/peekstack/extensions/snacks.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local ext = require("peekstack.extensions")
local notify = require("peekstack.util.notify")

local M = {}

Expand Down Expand Up @@ -28,12 +29,12 @@ local function open_picker(snacks_picker, provider, opts)
opts = opts or {}
local ok, snacks = pcall(require, "snacks.picker")
if not ok then
vim.notify("snacks.nvim not available", vim.log.levels.WARN)
notify.warn("snacks.nvim not available")
return
end
local fn = snacks[snacks_picker]
if not fn then
vim.notify("snacks.picker." .. snacks_picker .. " not found", vim.log.levels.WARN)
notify.warn("snacks.picker." .. snacks_picker .. " not found")
return
end

Expand Down
7 changes: 4 additions & 3 deletions lua/peekstack/init.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
local notify = require("peekstack.util.notify")
local M = {}

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

vim.notify("Invalid location payload: expected uri/range", vim.log.levels.WARN)
notify.warn("Invalid location payload: expected uri/range")
return nil
end

Expand Down Expand Up @@ -145,7 +146,7 @@ end
---@param opts? table
function M.peek_locations(locations, opts)
if not locations or #locations == 0 then
vim.notify("No locations", vim.log.levels.INFO)
notify.info("No locations")
return
end
if #locations == 1 then
Expand All @@ -167,7 +168,7 @@ end
local function peek_by_provider(provider, opts)
local fn = ensure_provider(provider)
if not fn then
vim.notify("Unknown provider: " .. tostring(provider), vim.log.levels.WARN)
notify.warn("Unknown provider: " .. tostring(provider))
return
end
local context = require("peekstack.core.context")
Expand Down
3 changes: 1 addition & 2 deletions lua/peekstack/persist/auto.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ local function save_session(root_winid, opts)
return false
end
persist.save_current(resolve_session_name(), {
scope = "repo",
root_winid = normalize_root_winid(root_winid),
silent = true,
sync = opts and opts.sync or false,
Expand Down Expand Up @@ -100,7 +99,7 @@ function M.maybe_restore()
end

last_restored_repo = repo_root
persist.restore(resolve_session_name(), { scope = "repo", silent = true })
persist.restore(resolve_session_name(), { silent = true })
return true
end

Expand Down
Loading