You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
tree-sitter-css does a naive thing here: since descendant combinators can technically tolerate a line break as their whitespace (I think?), it assumes it's finding a selector called padding display, and doesn't reassess its conclusion when it hits the : (colon plus space, which rules out a pseudoclass).
In Pulsar, this results in distracting re-highlighting of input, as illustrated below:
tree-sitter-css-inside-block-parsing.mp4
Unfortunately, it applies to every property after the cursor until : is inserted — they're all incorrectly reinterpreted as tag names.
The fix
In general, I think it's a good goal for incomplete input on one line to generate an ERROR node but to somehow recover before the valid input on the next line. Easier said than done, of course.
It used to be easier to rule out this scenario, but CSS nesting makes it so that you really could have valid CSS like the following:
div {
padding display {
display: flex;
}
}
It's implausible in this specific case, but I don't think the solution is to try to whitelist tag names or property names (we'd always be playing catch-up).
Maybe this is a job for conflictssomehow? Conceptually, it seems like the best way to proceed is on two parallel paths. If { is encountered first, the “interpret as a selector” path wins. If ; is encountered first (or something else that rules out a selector, like : , then the “interpret as an incomplete property-value pair” path wins.
Did you check existing issues?
Tree-Sitter CLI Version, if relevant (output of
tree-sitter --version
)No response
Describe the bug
The problem
Consider this selector:
Now suppose I want to add a new declaration above
display: none;
. I insert a line break and start typing:tree-sitter-css
does a naive thing here: since descendant combinators can technically tolerate a line break as their whitespace (I think?), it assumes it's finding a selector calledpadding display
, and doesn't reassess its conclusion when it hits the:
(colon plus space, which rules out a pseudoclass).If you add a colon, the tree changes:
Luckily, if you type a
;
, the error goes away (which is maybe too aggressive, considering it's not valid CSS):In Pulsar, this results in distracting re-highlighting of input, as illustrated below:
tree-sitter-css-inside-block-parsing.mp4
Unfortunately, it applies to every property after the cursor until
:
is inserted — they're all incorrectly reinterpreted as tag names.The fix
In general, I think it's a good goal for incomplete input on one line to generate an
ERROR
node but to somehow recover before the valid input on the next line. Easier said than done, of course.It used to be easier to rule out this scenario, but CSS nesting makes it so that you really could have valid CSS like the following:
It's implausible in this specific case, but I don't think the solution is to try to whitelist tag names or property names (we'd always be playing catch-up).
Maybe this is a job for
conflicts
somehow? Conceptually, it seems like the best way to proceed is on two parallel paths. If{
is encountered first, the “interpret as a selector” path wins. If;
is encountered first (or something else that rules out a selector, like:
, then the “interpret as an incomplete property-value pair” path wins.Steps To Reproduce/Bad Parse Tree
Expected Behavior/Parse Tree
Repro
The text was updated successfully, but these errors were encountered: