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

Option for CODEX to ignore certain comments (or code) #21

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

Conversation

clotodex
Copy link

I took a stab at implementing this.

How it works:

  • # codex-ignore will ignore this and the next line
  • # codex-on/off will toggle and ignore everything inbetween
  • if enabled, comments starting with an item from skip_list, currently todo and fixme, will be skipped

A few open questions:

  • creation of vim commands (not my expertise here, don't know if optional arguments etc could be handled, would follow your lead)
  • how to best make the skip_list adjustable, should it be a vim variable or part of the function, or do we need it at all?
  • should #codex-ignore [n] take an optional n parameter to skip not just the next, but the next n lines
  • how to handle whole e.g. todo comment blocks, i.e. when the comment spans multiple lines, currently I am just removing the one containing the todo
  • multilingual support, currently I am just parsing based on #, is there a way to get comments language-independant or is there a smarter way to parse this

Feel free to check it out, add your comments and thoughts and then let's go from there.

@clotodex
Copy link
Author

After a discussion with @tom-doerr I will take an opinionated approach to this implementation

  • vim commands: whatever I can figure out, since they are on top and just wrap python functions this could be easily changed later
  • skiplist - would rather make this project (.skipcodex) or file specific (# CODEX_SKIP_PREFIX todo fixme ...) => for now most likely just a on/off config with the default
  • [n] - implementation later
  • todo blocks => would shelve this for now and rather handle it with codex on and off (if it is a long todo explanation, adding this should not be a problem, lateron this behavior could be a flag)
  • multilingual support => is kind of essential from the get go => will introduce an optional dependency to tree-sitter

@clotodex
Copy link
Author

Thoughts to tree-sitter (might give performance hit - dont know)

def search_comments():
    # Get the buffer's content as a string
    buffer_content = vim.current.buffer[:]

    # Get the tree-sitter parser for the buffer's language
    language = vim.eval("tree_sitter_language#get_parser().language")
    parser = vim.eval("tree_sitter_language#get_parser().parser")

    # Parse the buffer's content
    tree = parser.parse(buffer_content)

    # Query the tree for comment nodes
    comments = tree.root.query("//comment")

    # Print the line number and text content of each comment node
    for comment in comments:
        start_byte = comment.start_byte
        end_byte = comment.end_byte
        comment_text = buffer_content[start_byte:end_byte]
        line_number = buffer_content.count('\n', 0, start_byte) + 1
        print(f"Line {line_number}: {comment_text}")

Checking if installed:

if vim.eval("exists('g:loaded_tree_sitter')") == '1':
    # Tree-sitter is installed
else:
    # Tree-sitter is not installed

@tom-doerr
Copy link
Owner

Can the existing code already be merged to the project? It's still displayed for me as a draft

@clotodex
Copy link
Author

Can the existing code already be merged to the project? It's still displayed for me as a draft

In theory it is ready to merge, however I did not even test it yet - If you test it, feel free to merge. Sadly I don't have much time right now and only will get to it in the upcoming weeks.

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.

2 participants