Skip to content

Commit 81d22f0

Browse files
committed
refactor: delegate traversal to vim.treesitter._select
Drop nvim-treesitter dependency and manual parent-walking loop. Neovim 0.12+ built-in _select handles node traversal, injection language trees, and normalization. Wildfire becomes a thin surround- awareness layer on top. - Extract surround detection into surround.lua using TS node structure (anonymous children as delimiters) - Add pluggable checkpoint protocol (single trail stack) for selection undo history - Switch visual-mode mappings to function callbacks so _select can read v/. marks correctly - Remove: nvim-treesitter requires, count variable, fallback traversal, print_selection, duplicated coord conversion BREAKING CHANGE: requires Neovim 0.12+
1 parent 918a187 commit 81d22f0

4 files changed

Lines changed: 250 additions & 318 deletions

File tree

lua/wildfire/checkpoint.lua

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
--- Pluggable checkpoint protocol for selection history.
2+
---
3+
---@class wildfire.Checkpoint
4+
---@field save fun(self, buf: integer, selection: TSNode|integer[])
5+
---@field restore fun(self, buf: integer): TSNode|integer[]|nil
6+
---@field reset fun(self, buf: integer)
7+
---@field selection fun(self, buf: integer): TSNode|integer[]|nil
8+
---@field has_state fun(self, buf: integer): boolean
9+
10+
---@class wildfire.StackCheckpoint: wildfire.Checkpoint
11+
---@field private _trail table<integer, (TSNode|integer[])[]>
12+
local StackCheckpoint = {}
13+
StackCheckpoint.__index = StackCheckpoint
14+
15+
---@return wildfire.StackCheckpoint
16+
function StackCheckpoint.new()
17+
return setmetatable({ _trail = {} }, StackCheckpoint)
18+
end
19+
20+
function StackCheckpoint:reset(buf)
21+
self._trail[buf] = {}
22+
end
23+
24+
function StackCheckpoint:save(buf, selection)
25+
if not self._trail[buf] then
26+
self._trail[buf] = {}
27+
end
28+
table.insert(self._trail[buf], selection)
29+
end
30+
31+
function StackCheckpoint:restore(buf)
32+
local trail = self._trail[buf]
33+
if not trail or #trail < 2 then return nil end
34+
table.remove(trail)
35+
return trail[#trail]
36+
end
37+
38+
function StackCheckpoint:selection(buf)
39+
local trail = self._trail[buf]
40+
return trail and trail[#trail]
41+
end
42+
43+
function StackCheckpoint:has_state(buf)
44+
local trail = self._trail[buf]
45+
return trail ~= nil and #trail > 0
46+
end
47+
48+
return { new = StackCheckpoint.new }

0 commit comments

Comments
 (0)