Skip to content

Commit f3f9aea

Browse files
authored
feat!: version 3 (#186)
* feat: new command format (#183) Co-authored-by: Oli Morris <[email protected]> * feat: can delete session in `vim.ui.select` (#184) Co-authored-by: Oli Morris <[email protected]> * tests: move from plenary to mini.test (#185) --------- Co-authored-by: Oli Morris <[email protected]>
1 parent 5063ee8 commit f3f9aea

30 files changed

+895
-455
lines changed

.github/workflows/ci.yml

Lines changed: 15 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,57 +12,29 @@ concurrency:
1212

1313
jobs:
1414
tests:
15-
runs-on: ${{ matrix.os }}
1615
strategy:
1716
fail-fast: false
1817
matrix:
19-
include:
20-
- os: ubuntu-latest
21-
url: https://github.com/neovim/neovim/releases/download/nightly/nvim-linux-x86_64.tar.gz
22-
- os: ubuntu-latest
23-
url: https://github.com/neovim/neovim/releases/download/v0.11.0/nvim-linux-x86_64.tar.gz
24-
- os: ubuntu-latest
25-
url: https://github.com/neovim/neovim/releases/download/v0.10.0/nvim-linux64.tar.gz
26-
- os: ubuntu-latest
27-
url: https://github.com/neovim/neovim/releases/download/v0.9.0/nvim-linux64.tar.gz
28-
- os: ubuntu-latest
29-
url: https://github.com/neovim/neovim/releases/download/v0.8.0/nvim-linux64.tar.gz
18+
os: [ubuntu-latest]
19+
nvim_tag: [nightly, v0.11.0, v0.10.0, v0.9.0, v0.8.0]
20+
name: ${{ matrix.os }} / ${{ matrix.nvim_tag }}
21+
runs-on: ${{ matrix.os }}
22+
env:
23+
NVIM: ${{ matrix.os == 'windows-latest' && 'nvim-win64\\bin\\nvim.exe' || 'nvim' }}
3024

3125
steps:
32-
- uses: actions/checkout@v4
33-
- run: date +%F > todays-date
34-
- name: Restore from todays cache
35-
uses: actions/cache@v4
36-
with:
37-
path: _neovim
38-
key: ${{ runner.os }}-${{ matrix.url }}-${{ hashFiles('todays-date') }}
26+
- name: Checkout 📋
27+
uses: actions/checkout@v6
3928

40-
- name: Prepare
29+
- name: Prepare Neovim 🚧
30+
env:
31+
NVIM_TAG: ${{ matrix.nvim_tag }}
4132
run: |
42-
test -d _neovim || {
43-
mkdir -p _neovim
44-
curl -sL ${{ matrix.url }} | tar xzf - --strip-components=1 -C "${PWD}/_neovim"
45-
}
46-
mkdir -p ~/.local/share/nvim/site/pack/vendor/start
47-
git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ~/.local/share/nvim/site/pack/vendor/start/plenary.nvim
48-
ln -s $(pwd) ~/.local/share/nvim/site/pack/vendor/start
33+
#bash ./scripts/dependencies.sh
34+
bash ./scripts/ci-install.sh
4935
50-
- name: Run tests
36+
- name: Run tests 🧪
5137
run: |
52-
export PATH="${PWD}/_neovim/bin:${PATH}"
53-
export VIM="${PWD}/_neovim/share/nvim/runtime"
54-
nvim --version
38+
$NVIM --version
5539
make test
5640
57-
release:
58-
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
59-
runs-on: ubuntu-latest
60-
needs:
61-
- tests
62-
permissions:
63-
contents: write
64-
pull-requests: write
65-
steps:
66-
- uses: googleapis/release-please-action@v4
67-
with:
68-
release-type: simple

.github/workflows/format.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Format with StyLua
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
stylua:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout 🛎️
10+
uses: actions/checkout@v4
11+
12+
- name: Format 🖌️
13+
uses: JohnnyMorganz/stylua-action@v4
14+
with:
15+
token: ${{ secrets.GITHUB_TOKEN }}
16+
version: v2.0.2
17+
args: --check .
18+

.github/workflows/release.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
12+
permissions:
13+
contents: write
14+
pull-requests: write
15+
16+
steps:
17+
- name: Release 📦
18+
uses: googleapis/release-please-action@v4
19+
with:
20+
release-type: simple
21+

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
misc/
1+
deps/
22
!tests/**/*
3-
.luarc.json
43
todo.md
54

65
tests/.DS_Store

.luarc.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"runtime": {
3+
"version": "LuaJIT",
4+
"pathStrict": true
5+
},
6+
"diagnostics.globals": ["vim",
7+
"describe",
8+
"it",
9+
"MiniTest",
10+
"before_each",
11+
"after_each"],
12+
"type": {
13+
"checkTableShape": true
14+
}
15+
}

Makefile

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,45 @@
1-
PANVIMDOC_DIR = misc/panvimdoc
2-
PANVIMDOC_URL = https://github.com/kdheepak/panvimdoc
3-
PLENARY_DIR = misc/plenary
4-
PLENARY_URL = https://github.com/nvim-lua/plenary.nvim
1+
all: format docs test
52

6-
all: format test docs
7-
8-
docs: $(PANVIMDOC_DIR)
9-
@cd $(PANVIMDOC_DIR) && \
10-
pandoc \
3+
docs: deps/panvimdoc
4+
@echo Generating Docs...
5+
@LUA_PATH="deps/panvimdoc/?.lua;;" pandoc \
6+
README.md \
117
--metadata="project:persisted.nvim" \
128
--metadata="description:Simple session management for Neovim" \
9+
--metadata="titledatepattern:%Y %B %d" \
1310
--metadata="toc:true" \
1411
--metadata="incrementheadinglevelby:0" \
1512
--metadata="treesitter:true" \
16-
--lua-filter scripts/skip-blocks.lua \
17-
--lua-filter scripts/include-files.lua \
18-
--lua-filter scripts/remove-emojis.lua \
19-
-t scripts/panvimdoc.lua \
20-
../../README.md \
21-
-o ../../doc/persisted.nvim.txt
13+
--metadata="dedupsubheadings:true" \
14+
--metadata="ignorerawblocks:true" \
15+
--metadata="docmapping:false" \
16+
--metadata="docmappingproject:true" \
17+
--lua-filter deps/panvimdoc/scripts/include-files.lua \
18+
--lua-filter deps/panvimdoc/scripts/skip-blocks.lua \
19+
--lua-filter deps/panvimdoc/scripts/remove-emojis.lua \
20+
-t deps/panvimdoc/scripts/panvimdoc.lua \
21+
-o doc/persisted.nvim.txt
22+
23+
format:
24+
@echo Formatting...
25+
@stylua tests/ lua/ -f ./stylua.toml
2226

23-
$(PANVIMDOC_DIR):
24-
git clone --depth=1 --no-single-branch $(PANVIMDOC_URL) $(PANVIMDOC_DIR)
25-
@rm -rf doc/panvimdoc/.git
27+
test: deps
28+
@echo Testing...
29+
nvim --headless --noplugin -u ./scripts/minimal_init.lua -c "lua MiniTest.run()"
2630

27-
check:
28-
stylua --check lua/ tests/ -f ./stylua.toml
31+
test_file: deps
32+
@echo Testing File...
33+
nvim --headless --noplugin -u ./scripts/minimal_init.lua -c "lua MiniTest.run_file('$(FILE)')"
34+
35+
deps: deps/mini.nvim deps/panvimdoc
36+
@echo Pulling...
37+
38+
deps/mini.nvim:
39+
@mkdir -p deps
40+
git clone --filter=blob:none https://github.com/echasnovski/mini.nvim $@
41+
42+
deps/panvimdoc:
43+
@mkdir -p deps
44+
git clone --filter=blob:none https://github.com/kdheepak/panvimdoc $@
2945

30-
format:
31-
stylua lua/ tests/ -f ./stylua.toml
32-
33-
test: $(PLENARY_DIR)
34-
nvim --headless --noplugin -u tests/minimal.vim +Setup
35-
# nvim --headless --noplugin -u tests/minimal.vim +TestAutoloading
36-
nvim --headless --noplugin -u tests/minimal.vim +TestGitBranching
37-
nvim --headless --noplugin -u tests/minimal.vim +TestFollowCwd
38-
nvim --headless --noplugin -u tests/minimal.vim +TestDefaults
39-
nvim --headless --noplugin -u tests/minimal.vim +TestDirs
40-
nvim --headless --noplugin -u tests/minimal.vim +TearDown
41-
42-
$(PLENARY_DIR):
43-
git clone --depth=1 --branch v0.1.3 $(PLENARY_URL) $(PLENARY_DIR)
44-
@rm -rf $(PLENARY_DIR)/.git

README.md

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,17 @@ require('telescope').setup({
103103

104104
**Commands**
105105

106-
The plugin comes with a number of commands:
107-
108-
- `:SessionToggle` - Determines whether to load, start or stop a session
109-
- `:SessionStart` - Start recording a session. Useful if `autostart = false`
110-
- `:SessionStop` - Stop recording a session
111-
- `:SessionSave` - Save the current session
112-
- `:SessionSelect` - Load a session from the list (useful if you don't wish to use the Telescope extension)
113-
- `:SessionLoad` - Load the session for the current directory and current branch (if `git_use_branch = true`)
114-
- `:SessionLoadLast` - Load the most recent session
115-
- `:SessionLoadFromFile` - Load a session from a given path
116-
- `:SessionDelete` - Delete the current session
106+
The plugin has a number of commands:
107+
108+
- `:Persisted toggle` - Determines whether to load, start or stop a session
109+
- `:Persisted start` - Start recording a session. Useful if `autostart = false`
110+
- `:Persisted stop` - Stop recording a session
111+
- `:Persisted save` - Save the current session
112+
- `:Persisted select` - Load a session from a list (useful if you don't wish to use the Telescope extension)
113+
- `:Persisted load` - Load the session for the current directory and current branch (if `git_use_branch = true`)
114+
- `:Persisted load_last` - Load the most recent session
115+
- `:Persisted delete` - Delete a session from a list
116+
- `:Persisted delete_current` - Delete the current session
117117

118118
**Telescope extension**
119119

@@ -528,6 +528,27 @@ You may wish to only save a session if the current working directory is in a tab
528528
}
529529
```
530530

531+
**Notifying when a session has been deleted**
532+
533+
When you delete a session, it can be helpful to have a notification appear confirming the deletion:
534+
535+
```lua
536+
{
537+
"olimorris/persisted.nvim",
538+
lazy = false,
539+
config = function()
540+
local persisted = require("persisted").setup()
541+
542+
vim.api.nvim_create_autocmd("User", {
543+
pattern = "PersistedDeletePost",
544+
callback = function(event)
545+
vim.notify("Session `" .. event.data.path .. "` deleted")
546+
end,
547+
})
548+
end,
549+
}
550+
```
551+
531552
<!-- panvimdoc-ignore-start -->
532553

533554
## :clap: Acknowledgements

lua/persisted/init.lua

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ local uv = vim.uv or vim.loop
1010

1111
---Fire an event
1212
---@param event string
13+
---@param data? table
1314
---@return nil
14-
function M.fire(event)
15-
vim.api.nvim_exec_autocmds("User", { pattern = "Persisted" .. event })
15+
function M.fire(event, data)
16+
data = data or {}
17+
vim.api.nvim_exec_autocmds("User", { pattern = "Persisted" .. event, data = data })
1618
end
1719

1820
---Get the current session for the current working directory and git branch
@@ -126,17 +128,17 @@ end
126128
---Delete a session
127129
---@param opts? { path?: string }
128130
---@return nil
129-
function M.delete(opts)
131+
function M.delete_current(opts)
130132
opts = opts or {}
131133
local session = opts.path or M.current()
132134

133135
if session and uv.fs_stat(session) ~= 0 then
134-
M.fire("DeletePre")
136+
M.fire("DeletePre", { path = session })
135137
vim.schedule(function()
136138
M.stop()
137139
vim.fn.delete(vim.fn.expand(session))
138140
end)
139-
M.fire("DeletePost")
141+
M.fire("DeletePost", { path = session })
140142
end
141143
end
142144

@@ -149,9 +151,11 @@ function M.branch()
149151
end
150152
end
151153

152-
---Select a session to load
154+
---Handle the vim.ui.select behaviour
155+
---@param opts { prompt: string, handler: function}
153156
---@return nil
154-
function M.select()
157+
function M.handle_selected(opts)
158+
---@type { session: string, dir: string, branch?: string }[]
155159
local items = {} ---@type { session: string, dir: string, branch?: string }[]
156160
local found = {} ---@type table<string, boolean>
157161
for _, session in ipairs(M.list()) do
@@ -169,7 +173,7 @@ function M.select()
169173
end
170174
end
171175
vim.ui.select(items, {
172-
prompt = "Load a session: ",
176+
prompt = opts.prompt,
173177
format_item = function(item)
174178
local name = vim.fn.fnamemodify(item.dir, ":p:~")
175179
if item.branch then
@@ -179,12 +183,34 @@ function M.select()
179183
end,
180184
}, function(item)
181185
if item then
186+
opts.handler(item)
187+
end
188+
end)
189+
end
190+
191+
---Load a session from the list
192+
---@return nil
193+
function M.select()
194+
M.handle_selected({
195+
prompt = "Load a session: ",
196+
handler = function(item)
182197
M.fire("SelectPre")
183198
vim.fn.chdir(item.dir)
184199
M.load()
185200
M.fire("SelectPost")
186-
end
187-
end)
201+
end,
202+
})
203+
end
204+
205+
---Delete a session from the list
206+
---@return nil
207+
function M.delete()
208+
M.handle_selected({
209+
prompt = "Delete a session: ",
210+
handler = function(item)
211+
M.delete_current({ path = item.session })
212+
end,
213+
})
188214
end
189215

190216
---Determines whether to load, start or stop a session

0 commit comments

Comments
 (0)