-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: Determine comment tokens from injection layers #12759
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
base: master
Are you sure you want to change the base?
Conversation
63e26be
to
3281c81
Compare
019fe67
to
c585fca
Compare
c160b1e
to
dd5d4e8
Compare
1afd4c5
to
8f9fcc1
Compare
Thank you for this PR! I really hope it lands ASAP and its gonna be finally truly possible to work with It uses incorrect comment tokens if there are whitespaces in beginning or end? Not sure. css.example.mp4when.line.wraps.incorrect.tokens.mp4 |
Thanks for checking out the PR! When you select the full line like that, what actually happens is that your line has 2 injections in it: the CSS (inner) and the HTML (outer) That's because the CSS injection doesnt start at the beginning of the line. It starts after a few spaces (Its weird, but it isnt a bug) Here, the PR chooses comment tokens based upon the most tightly encompassing injection range. Because the CSS injection isnt fully encompassing the selection, it chooses the HTML comment tokens because that layer is fully encompassing |
You can verify this with |
Yeah, I checked that, indeed. or maybe they comment correctly with the help of their LSP which is more sophisticated? (Im just guessing, I have no idea) yo.mp4 |
Co-authored-by: the-mikedavis <[email protected]>
8f9fcc1
to
d09f773
Compare
waiting for this one to land...it is a much needed quality of life in web dev |
just fyi, this PR is waiting on #12972 at the moment |
Previously, if you had a file like this:
Pressing
Space + c
(toggle comment) on the JavaScript comment would've used the HTML comment token:This PR fixes that. Now, the comment token is properly recognized:
It also works for continue comment functionality (when pressing
o
or adding a newline, for example)Additionally, the PR adds a new
:tree-sitter-injections
command:`:tree-sitter-injections` output
With this file:
We get the following when we run
:tree-sitter-injections
:Languages Tested
I've added a lot of tests, each of which actually helped me fix a bug or two while I was implementing this. So I ended up extracting all comment-relating integration tests into a separate module
The core functionality works. What's left is to make sure that we do all we can to have individual languages work as well. For example, Svelte's comment tokens had to be adjusted in this PR for the best experience.
I've tested these languages manually as well. If you have a language which relies on injections, be sure to test it and comment here, I'll add it to the list.
JSX and TSX
These languages don't use tree-sitter injections:
Has just this injection:
Which means this PR won't affect them
You can use
Space + C
to comment JSX at the moment. It'd be nice if you could useSpace + c
to make line comments that use the tokens{/*
and*/}
though, as it uses//
right now.But to do this we could have
.tsx
and.jsx
languages usets
andjs
as the file's "main" language, and then when we injecttsx
andjsx
languages when we encounter a tag.Not exactly sure how to accomplish this though, and it's not really related to this PR (can be done as a follow up if I or someone figures out how to do this)
Implementation
Before:
Selection
'sRange
to aChange
Transaction
from those changesNow
Range
inSelection
get its comment tokensRange
to aVec<Change>
Transaction
from those changesGetting an injection layer's comment tokens
Syntax
.Syntax
has aMap<LayerId, LanguageId>
and aLoader
Loader
has aMap<LanguageId, LanguageConfiguration>
LanguageConfiguration
has the comment tokensCloses #7364
Closes #11647
Related to to #9425