Skip to content
Open
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ local node_type = {
omit = {},
---Non-bracket nodes (e.g., with 'then|()' ... 'end' instead of { ... }|< ... >|[ ... ])
---If value is table, should be contains follow keys: { left = 'text', right = 'text' }. Empty string uses by default
---For indentation-based blocks with no closing delimiter, add `outer_framing = false` to stop framing from extending to the parent's sibling
---@type boolean|table
non_bracket_node = false,
---If you need to process only nodes in the range from / to.
Expand Down Expand Up @@ -638,6 +639,13 @@ specifies what text should wrap the actual base node.

E.g., table value: `{ left = 'text', right = 'text' }`

For indentation-based blocks that have no closing delimiter (e.g. Python,
GDScript), also set `outer_framing = false`, e.g.
`{ left = '', right = '', outer_framing = false }`. By default the range
framing climbs to the parent's sibling when the node has none of its own; for
such blocks that sibling is the following statement, so the join range would
otherwise extend over it and swallow it.

<details>

<summary>Example of usage</summary>
Expand Down
1 change: 1 addition & 0 deletions lua/treesj/langs/default_preset.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ return {
omit = {},
---Non-bracket nodes (e.g., with 'then|()' ... 'end' instead of { ... }|< ... >|[ ... ])
---If value is table, should be contains follow keys: { left = 'text', right = 'text' }. Empty string uses by default
---For indentation-based blocks with no closing delimiter, add `outer_framing = false` to stop framing from extending to the parent's sibling
---@type boolean|table
non_bracket_node = false,
---If you need to process only nodes in the range from / to.
Expand Down
13 changes: 11 additions & 2 deletions lua/treesj/search.lua
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,18 @@ function M.range(tsn, preset)
local er, ec = get_last_symbol_range(tsn, to)

if preset and (non_bracket_node and not shrink_node) then
-- Indentation-based blocks (e.g. Python) have no closing delimiter token.
-- `outer_framing = false` stops framing from climbing to the parent's sibling
local climb = type(non_bracket_node) ~= 'table'
or non_bracket_node.outer_framing ~= false

local function get_framing_for_non_bracket(n)
local first = n:prev_sibling() or n:parent():prev_sibling()
local last = n:next_sibling() or n:parent():next_sibling()
local first = n:prev_sibling()
local last = n:next_sibling()
if climb then
first = first or n:parent():prev_sibling()
last = last or n:parent():next_sibling()
end
return first, last
end

Expand Down