Skip to content

Conversation

@mantou132
Copy link

@mantou132 mantou132 commented Jun 10, 2025

Closes #29044

Before:

image

After:

Screenshot 2025-06-11 at 02 11 39

Release Notes:

  • N/A

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Jun 10, 2025
@maxdeviant maxdeviant changed the title Support template string inline css Support template string inline CSS Jun 10, 2025
@maxdeviant maxdeviant changed the title Support template string inline CSS Support template string inline CSS in JavaScript and TypeScript Jun 10, 2025
tree-sitter-c = "0.23"
tree-sitter-cpp = "0.23"
tree-sitter-css = "0.23"
tree-sitter-css = { git = "https://github.com/mantou132/tree-sitter-css", rev = "62bb39a376ee8aa0ceb6cab27474b7c7136913b9" }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Little question, don't you intend to contribute this change to the upstream? 🤔
tree-sitter/tree-sitter-css@master...mantou132:tree-sitter-css:master

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes:

  • Supports ``` at the beginning and end of the document
  • Recognize ${} content as comments and avoid recognizing it as a pseudo-class

These are not part of the CSS spec, so I don't think they should be merged upstream.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And due to that, Zed is supposed to rely on someone's upstream forever and maintain it?
Does not sound exciting.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any better solution besides modifying tree-sitter-css? Although I've tried creating a PR for tree-sitter-css

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I have thought of it more and more and could not find anything clever than "move it to zed-industries org".

I do no think it's a good solution either, maybe @notpeter have ideas?

Copy link
Contributor

@notpeter notpeter Jun 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, not a tree-sitter or CSS/JS/CSS-in-JS expert and haven't looked at the tree-sitter changes, so don't have any immediate suggestion. I do recall that tree-sitter-markdown has wonky two pass approach where they first parse it with the block grammar, then they specify all the inline injections (think ```json and similar). dunno if that's helpful here, please ignore if not.

I just pruned the zed-industries/tree-sitter-* forks and we're down to 6 (was 11). I'd obviously much rather not fork, especially for something as complex as css/js, but it is always a potential option.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a more robust solution would be to make a PR to the js/ts tree sitter to separate the quotes ` from the contents like so (element names made up):

(template-string
  "`"
  (template-string-contents ... )
  "`"
  )

That way you can have a more precise injection (this is probably generally useful). Then separately make a PR against the css grammar to play nice with ${} or see if you can make it work with tree-sitter predicates instead

@mantou132
Copy link
Author

mantou132 commented Jul 5, 2025

It seems that html has the same problem

Screenshot 2025-07-05 at 20 34 38

Screenshot 2025-07-18 at 23 16 50

I submitted pr to support more valid attribute values and has not been merged to the official tree-sitter-html yet

@ConradIrwin
Copy link
Member

Closing for now based on feedback of not wanting to support a fork of the tree-sitter grammar.

@ConradIrwin ConradIrwin closed this Sep 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants