Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: working toggling for sublists #1492

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mtrajano
Copy link

First pass. Might still need some cleaning up but toggling / inverting sublists is working. I can also write some tests for this, what is the status on testing? Do we have this set up already?

Demo:

Screen.Recording.2024-06-28.at.3.45.13.PM.mov

---@param match_self boolean #If true can match on self, if false needs to match on ancestor to node
---@return TSNode?
-- TODO: if remove match_self param, need to check other functionality that depends on this
find_parent = function(node, types, match_self)
Copy link
Author

@mtrajano mtrajano Jun 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this was intended functionality but the previous version of this method allowed to match on the node passed so I had to include this param to stricly match on ancestor. The default is to keep the previous behavior (match_self = true).

node = node:parent()
end

if type(types) == "string" then
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplified the method so we're only working with one type of param (table) otherwise should behave the same way. For tables it also used to check for equality whereas now it does pattern matching. If a string is passed that is not a pattern it should behave the same way

---@param types table|string #If `types` is a table, this function will attempt to match any of the types present in the table.
-- If the type is a string, the function will attempt to pattern match the `types` value with the node type.
find_parent = function(node, types)
local _node = node
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really sure what this local _node was doing so I removed it. Also added the TSNode typehint to get rid of the ignore diagnostic comments cc: @pysan3

local parent = module.required["core.integrations.treesitter"].find_parent(node, {
"^unordered_list%d$",
"^ordered_list%d$",
"^generic_list$", -- for level 1 lists the parent is a generic_list
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because find_parent can now accept patterns we can now change this to also be a list of pattern instead of an exhaustive list


if not first_child then
return
end
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really necessary due to the previous checks on node and it's parent existing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant