Skip to content
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

LaTeX language injection #20

Closed
steffenhaug opened this issue Sep 5, 2024 · 5 comments · Fixed by #24
Closed

LaTeX language injection #20

steffenhaug opened this issue Sep 5, 2024 · 5 comments · Fixed by #24
Labels
enhancement New feature or request queries Tree-sitter queries

Comments

@steffenhaug
Copy link
Contributor

Just like we currently inject regex syntax into regexes, and SQL syntax into SQLStrings, I think it would be nice to have LaTeX language injection into LaTeXStrings.

I tried to implement this before, but couldn't make it as nice as i wanted, because the TeX grammar can't deal with the surrounding L" and L""". For the Markdown, Regex and SQL injections, it just so happens that those parsers deal with the surrounding quotations reasonably well, but in general we can't expect parsers of other languages to robustly handle quotation in Julia.

It would be nice if the tree-sitter parser created a child-node for string literals that contained just the content of the string, so it could be reparsed more easily.

I'm making this issue to gauge interest in this feature, make it searchable in case someone wonders why LaTeX strings are not highlighted, and to reference if we decide we need to bug the tree-sitter people about it.

@Pangoraw
Copy link
Member

Pangoraw commented Sep 5, 2024

Other string macros to inject:

  • md for markdown.
  • html for html.
    I suppose Pycall has py_str.

For the single/triple string problem, neovim has the handy offset! primitive in tree-sitter queries but zed does not have it.

@steffenhaug
Copy link
Contributor Author

Those are good calls.

I didn't know about offset!, that's cool!

Maybe the Zed devs would be willing to provide offset!? I'm not sure what is best. On the one hand, tweaking the grammar would fix it for every editor ever, but on the other hand adding unnecessary nodes to the tree just to facilitate language injection, instead of representing the syntax of the language "as is", is kinda ugly if there are options.

@piechologist piechologist added enhancement New feature or request queries Tree-sitter queries labels Sep 5, 2024
@piechologist
Copy link
Collaborator

tree-sitter-julia v0.23.1 comes with a new (content) node that returns the string without the surrounding quotes.

That should allow injections for LaTeXStrings.

I've added md (that ignores quotes out of the box). Does anybody know what html and py_str expect?

@steffenhaug
Copy link
Contributor Author

That's good news! I'm happy to work on some queries, but I'm fairly busy in the immediate future so if anyone else is eager they can go ahead.

@piechologist
Copy link
Collaborator

@steffenhaug: zed-julia 0.1.3 is out and you can update within Zed. All string macros mentioned above are available. L"""\latex""" works fine with the Zed LaTeX extension. (BTW, check out the docstrings 🎉.)

Feel free to open a new issue or PR if you miss something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request queries Tree-sitter queries
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants