-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Treewalker's node swapping is unique in that it carries comments and annotations / decorators around with it. Hopefully this makes for very convenient swapping. Does not work in md files.
- Loading branch information
Showing
27 changed files
with
1,005 additions
and
310 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
# TODO | ||
|
||
* Check for errant util.log or util.R usages in CI/local | ||
* Swapping | ||
* Jumplist | ||
* Get more languages into movement/highlight/swap specs | ||
* :help treesitter-parsers | ||
* Python decorators (tough b/c of the identifier node underneath) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
local nodes = require "treewalker.nodes" | ||
|
||
local M = {} | ||
|
||
-- Gets the "augment" nodes that exist above a given node | ||
-- These are nodes that are, like, kind of attached to the provided node. | ||
-- Think comments, decorators, annotations, etc. Stuff that wants to stay | ||
-- with the given node. This was originally implemented to aid with swapping, | ||
-- because if you swap a node that has a comment description, comment types, | ||
-- annotations, etc, those should move along with the node. | ||
---@param node TSNode | ||
---@return TSNode[] | ||
function M.get_node_augments(node) | ||
local augments = {} | ||
local row = nodes.range(node)[1] + 1 | ||
while true do | ||
local candidate = nodes.get_from_neighboring_line(row, "up") | ||
if candidate and nodes.is_augment_target(candidate) then | ||
table.insert(augments, candidate) | ||
row = row - 1 | ||
else | ||
break | ||
end | ||
end | ||
|
||
return augments | ||
end | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
local ops = require "treewalker.ops" | ||
local targets = require "treewalker.targets" | ||
|
||
local M = {} | ||
|
||
---@return nil | ||
function M.move_out() | ||
local target, row, line = targets.out() | ||
if target and row and line then | ||
--util.log("no out candidate") | ||
ops.jump(row, target) | ||
return | ||
end | ||
end | ||
|
||
---@return nil | ||
function M.move_in() | ||
local target, row, line = targets.inn() | ||
|
||
if target and row and line then | ||
--util.log("no in candidate") | ||
ops.jump(row, target) | ||
end | ||
end | ||
|
||
---@return nil | ||
function M.move_up() | ||
local target, row, line = targets.up() | ||
|
||
if target and row and line then | ||
--util.log("no up candidate") | ||
ops.jump(row, target) | ||
end | ||
end | ||
|
||
---@return nil | ||
function M.move_down() | ||
local target, row, line = targets.down() | ||
|
||
if target and row and line then | ||
--util.log("no down candidate") | ||
ops.jump(row, target) | ||
end | ||
end | ||
|
||
return M |
Oops, something went wrong.