-
Notifications
You must be signed in to change notification settings - Fork 145
Heredoc strings no longer syntax highlighted #249
Comments
Thanks @andremleblanc! Reproduced on macOS 10.12.6 with 1.34.0-nightly10. |
The bug report contains a clause, differing from the title, that I believe makes it more specific than the problem is. Apologies if this has been tested and found to be specific in your case. I'm using HEREDOC (tilde, though dash is the same) with Ruby syntax, as reported, however I don't have tree-sitter. Also noticed that if the ending HEREDOC is typed, at the correct indentation level, after the message (as opposed to the likely more standard practice of typing opening/closing HEREDOC and populating) the syntax parser fails to match the closing HEREDOC, leaving it colored grey. |
I'm hitting both issues:
Anyway, the syntax highlighting is a huge feature for me, depending on what I'm doing, I might go to Atom just b/c of this feature (eg when I'm playing with SQL). |
Oh, that second one is interesting, it seems to be related to the letter Put this into your editor, select the def m
<<~ABCD
msg
ABCD
end |
Oh, okay, so it's going wonky on the highlighting because it applies "C" language syntax highlighting to it. So syntax highlighting does still get applied, but only sometimes. Maybe there's an issue with how it looks up the language? Eg here it sees |
I think this commit is part of the problem. I don't think that change does what it is presumably intended to do. Eg it looks like the author thought it was shorthand for mapping multiple keys to the same value, but instead it created a single key whose name was a conjunction of all the keys. I don't know how tree-sitter works, maybe it treats keys like this as the original, but WRT cson, the new syntax is not translated to the old syntax. Here, I convert it to JSON and we see that the key is not broken out into multiple key/value pairs: |
Followed the instructions to make changes locally (here to put atom into dev mode, and here to link local changes into the dev-mode). Ran a This is the commit where it breaks. Here's the output of the 🐠 git bisect start
🐠 git bisect bad
🐠 git bisect good 0909a11557725f117dea6f39aa2b08241a887ff2
Bisecting: 31 revisions left to test after this (roughly 5 steps)
[726281fc9d9fe4e9e3e20a61f5912b062625edcb] Merge pull request #236 from atom/mb-compatible-scope-descriptors
🐠 git bisect bad
Bisecting: 14 revisions left to test after this (roughly 4 steps)
[e5a8d8e66728c013e1a009bcdb2facfd044270f9] Merge pull request #225 from atom/mb-tree-sitter-parser
🐠 git bisect bad
Bisecting: 7 revisions left to test after this (roughly 3 steps)
[701ad5d744e23090655f1c2e725f18cfe6f4ae7c] Add tree-sitter Ruby grammar
🐠 git bisect bad
Bisecting: 4 revisions left to test after this (roughly 2 steps)
[73ec57162fb7eb0035dedc0026911e3d2a8aee4b] :racehorse: Improve the regexp pattern
🐠 git bisect good
Bisecting: 2 revisions left to test after this (roughly 1 step)
[ef4eb5691842a369b83f6465defaad8b82ad191a] Merge pull request #215 from stevenpetryk/variables-ending-in-do-are-not-blocks
🐠 git bisect good
Bisecting: 0 revisions left to test after this (roughly 1 step)
[d88a4cfb32876295ec5b090a2994957e62130f4a] Prepare 0.71.4 release
🐠 git bisect good
701ad5d744e23090655f1c2e725f18cfe6f4ae7c is the first bad commit
commit 701ad5d744e23090655f1c2e725f18cfe6f4ae7c
Author: Max Brunsfeld <maxbrunsfeld@gmail.com>
Date: Fri Dec 8 09:28:08 2017 -0800
Add tree-sitter Ruby grammar
:040000 040000 32ce74581b8f1777099d63e11f36f2625814dd82 adcea68aa1e140b88926e33c0f3849582360dce9 M grammars
:100644 100644 0db247528eaa512b24d4a033c36835c164453f75 c88b06b4fee6a4c54319b0c8b1ae1107037a249a M package.json Additionally, I put print statements into the injection point language registration (line 6): Lines 4 to 8 in ea3824d
For |
There are apparently multiple grammars which are loaded, and the one that is used is determined by a configuration value. This package uses this feature to test against the old parser (textmate's?), which means that the tree-sitter stuff doesn't get tested by this lib. On the bright side, it reveals an easy solution: atom.config.set('core.useTreeSitterParsers', false) If you enter it into the debug console ( |
I can reproduce this issue with Atom 1.35.1 and Ubuntu 18.04; however, #249 (comment) is useful. |
Thanks for reporting this issue. I think I see what's causing the behavior that you're observing. I'll try to explain what I've found so far and a path toward resolving this issue. tl;dr: When using Tree-sitter, the Ruby heredoc's inner text will be syntax highlighted if (1) there is Tree-sitter grammar for the language of the inner text and (2) that grammar provides an injection regex. Currently, JavaScript, Bash, C, and a handful of other languages meet these requirements, but SQL does not yet meet these requirements. Tree-sitter support for syntax highlighting within Ruby heredocsTree-sitter refers to this topic as "language injection" and describes it as follows:
The Tree-sitter Ruby grammar satisfies the first requirement described above: the grammar defines an injection point for heredocs. 😅 Some languages already support syntax highlighting within Ruby heredocsSeveral languages satisfy the second requirement described above: they define an SQL doesn't yet support syntax highlighting within Ruby heredocsAt the moment, language-sql does not yet provide a Tree-sitter grammar, so Atom cannot provide SQL syntax highlighting inside a Ruby heredoc: Fixing this issueTo fix this issue, we'll need to update Atom's other A workaround in the meantimeThe fix above will be a rather time consuming endeavor, so folks may want a workaround in the meantime. As @JoshCheek notes above, you can disable Tree-sitter for now. To do so, open Atom's settings UI, and uncheck the "Use Tree Sitter Parsers" checkbox. This will cause Atom to fall back to using the TextMate grammars, which currently provide broader support for syntax highlighting within Ruby heredocs. |
TL;DR there is nothing wrong with |
Isn't that already a bug on its own or should really any HEREDOC that contains a capital C cause the content to be interpreted as C code? Sounds a bit like a |
Another possibly resolution would be to support injecting legacy first-mate grammars into regions of files that are otherwise parsed via TreeSitter. This would need to occur in Atom rather than TreeSitter, and I'm not sure how complicated it would be. |
Is this a dead issue? I remember this working at some point... |
Description
Heredocs used to use the syntax highlighting for that language, but it appears that isn't currently working with Tree Sitter Parsers enabled.
Before:
Current:
Steps to Reproduce
Expected behavior:
It highlights the content of the heredoc in that language's syntax.
Actual behavior:
No syntax highlighting.
Reproduces how often:
Consistently.
Additional Information:
Running on macOS Mojave.
Versions
1.32.1
1.33.0-beta1
The text was updated successfully, but these errors were encountered: