vim_codex
vim_codex copied to clipboard
Option for CODEX to ignore certain comments (or code)
I took a stab at implementing this.
How it works:
# codex-ignorewill ignore this and the next line# codex-on/offwill toggle and ignore everything inbetween- if enabled, comments starting with an item from
skip_list, currentlytodoandfixme, 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_listadjustable, should it be a vim variable or part of the function, or do we need it at all? - [ ] should
#codex-ignore [n]take an optionalnparameter to skip not just the next, but the nextnlines - [ ] 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.
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
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
Can the existing code already be merged to the project? It's still displayed for me as a draft
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.