-
-
Notifications
You must be signed in to change notification settings - Fork 126
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
feat: allow rules to be treesitter context aware (#423) #424
Conversation
0757ff3
to
3534bfd
Compare
Thank you for your PR. I expect it can handle a different behavior of existing rule with inline file type
or rule Yeah, I know it needs a lot of refactoring. That's why I suggest using a conditional behavior. Your tree sitter context only of affecting one rule with the character Rule('*', '*', { 'markdown' }):with_pair(ts_conds.is_not_inside_context()) |
Yours is a much cleaner implementation. I think would be good to have Rule("*", "*"):with_pair(ts_conds.is_inside_context({"markdown"}))
Rule('f"""', '"""'):with_pair(ts_conds.is_inside_context({"python"})) That way, we can have the behaviour you mentioned.
I think if we specify the filetype, the rule will not run when we are not in the filetype specified. I.e. if we did |
but the problem is if we use condition then that rule will not load to buffer or create a mapping on buffer if you change this pr to add a new condition. i will merge. |
d1b6987
to
15edfbb
Compare
Okay. I've implemented it how you suggested |
15edfbb
to
5aa0a87
Compare
When a rule is defined with the `:with_context()` method, has a specified filetype, and is operating in a buffer with a treesitter parser attached, the rule will only execute iff the treesitter language at the cursor matches one of the filetypes specified in the initial rule definition. > If there are no specified filetypes, of there is no parser attached to > the current buffer, the rule executes as normal
- Add 'ts_context markdown `*` success md_context' - Add 'ts_context codeblock `*` fail js_context'
5aa0a87
to
bd41c43
Compare
ok, thank |
When a rule is defined which calls the
:with_context()
method, has aspecified filetype, and is operating in a buffer with a treesitter
parser attached, the rule will only execute iff the treesitter language
at the cursor matches one of the filetypes specified in the initial rule
definition.
For the tests, I created a sample.md file which I then use with the rule to test. It was required to make a small modification to
Test_withfile
. We needed to carry out a full parse of the buffer tree which returns a language tree with the injected child trees. The test check if the rules work exclusively in the specified grammars/filetypes.