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

py does not trigger nested Python tree-sitter to work, but python does #34

Closed
Andrew15-5 opened this issue May 17, 2024 · 3 comments · Fixed by #36
Closed

py does not trigger nested Python tree-sitter to work, but python does #34

Andrew15-5 opened this issue May 17, 2024 · 3 comments · Fixed by #36

Comments

@Andrew15-5
Copy link
Contributor

This doesn't add Python syntax highlighting:

```py
print()
```

But this does:

```python
print()
```

While both work fine with Markdown tree-sitter.

Checked on Neovim and Helix.

@Andrew15-5
Copy link
Contributor Author

With Helix, this fixed the problem: helix-editor/helix#10785. But I have no idea what to do in Neovim/tree-sitter if anything can be done.

@monaqa
Copy link
Contributor

monaqa commented Jul 8, 2024

Instead of https://github.com/uben0/tree-sitter-typst/blob/master/queries/typst/injections.scm#L4-L6,
try the following:

(raw_blck
  lang: (ident) @_lang
  (blob) @injection.content
  (#set-lang-from-info-string! @_lang))

@Andrew15-5
Copy link
Contributor Author

It turns out that for Neovim, this exact code is a part of https://github.com/nvim-treesitter/nvim-treesitter. So I did:

diff --git a/queries/typst/injections.scm b/queries/typst/injections.scm
index 344c6a30..bc75d2b2 100644
--- a/queries/typst/injections.scm
+++ b/queries/typst/injections.scm
@@ -2,5 +2,6 @@
   (#set! injection.language "comment"))
 
 (raw_blck
-  (ident) @injection.language
-  (blob) @injection.content)
+  lang: (ident) @_lang
+  (blob) @injection.content
+  (#set-lang-from-info-string! @_lang))

And now it works! I will have to make 2 PRs, I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants