-
Notifications
You must be signed in to change notification settings - Fork 215
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: Support context recognition for injected languages #388
Merged
lewis6991
merged 7 commits into
nvim-treesitter:master
from
kwaszczuk:respect-injections
Feb 16, 2024
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3c78f63
feat: Support context recognition for injected languages
kwaszczuk 4171557
fix: Avoid redefining variables
kwaszczuk 02f27f8
fix: Traverse children langtrees manually
kwaszczuk 6244f77
test: Replace html test case with markdown one
kwaszczuk db65dc2
test: Fix Markdown tests runtime
kwaszczuk c17f9b6
test: Add missing html & javascript parsers
kwaszczuk 2776752
test: Use more general module initialization
kwaszczuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,6 +132,20 @@ | |
var b = 2; | ||
function test() { | ||
let test = "asdasd"; | ||
|
||
|
||
|
||
if test != "" { | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
} | ||
} | ||
|
||
var c = a + b; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work properly for nested injections? it looks to me this will only return at most 2 langtrees. The root and the most inner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, I misunderstood
language_for_range
implementation. I changed the code to manually traverse children langtrees, please take a look.To test the nested injection, I came up with the markdown test case replacing HTML one. Context both for
<html>
and<script>
displays properly when I run vim manually, but in tests injecting language in Markdown seems to be broken (look attest
job for the reference). Do you have any idea what could be the problem here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lewis6991 It took me a while, but I finally get it to work.
Looks like tests are not performing full initialization of
nvim-treesitter
plugin, but justrequire'nvim-treesitter.configs'.setup { ... }
. Because of that some modules are not initialized, includingnvim-treesitter.query_predicates
which containsset-lang-from-info-string!
directive configuration required by Markdown queries.My straightforward solution for that is to explicitly initialize the plugin via
require'nvim-treesitter'.setup()
. I don't think it is the greatest solution, as we end up invokingsetup()
twice (just on different modules), which seems weird, but I couldn't find any other way that would not inducesetup
duplication.