balpan-rs / balpan

Simple CLI Tool that supports your onboarding for a journey on source code.
37 stars 7 forks source link

[Feature] `balpan toggle` subcommand #41

Open malkoG opened 1 year ago

malkoG commented 1 year ago

This subcommand will toggle line comment labeled [TODO] to [DONE] Usage of this would be integration with editor plugin (such as VSCode, Neovim)

Example

balpan toggle models/post.py:100

balpan toggle models/post.py:100-200

malkoG commented 1 year ago

Abstracted implementation would be like this:

  1. Pass the cursor's range to toggle command (in commandline, we just pass a line number)
  2. Using Tree-sitter, Find closest commentable node that includes the range by accessing ancestors
    • ex. Range(start_point: (row: line_number, col: end_of_line), end_point: (row: line_number, col: end_of_line))
  3. Choose which commentable node would be appropriate
    • If the commentable node includes the cursor, and the leftmost commentable node within the commentable node's children is after the cursor, the parent is appropriate
    • If the commentable node includes the cursor, but the leftmost commentable node within the commentable node's children is in front of the cursor, the parent is appropriate. and the toggle command do not anything. do not continues to Step 4
    • If the commentable node includes the cursor, and has no commentable node within its children, that node is appropriate.
  4. And Find TODO comment of the commentable node, Switch TODO -> DONE, DONE -> TODO.

If we pass the range of line number to toggle command, we can do it with set's union operation.