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

Heredoc syntax highlighting is broken for Ruby #710

Open
dkali opened this issue Nov 28, 2016 · 12 comments
Open

Heredoc syntax highlighting is broken for Ruby #710

dkali opened this issue Nov 28, 2016 · 12 comments
Labels
C: Syntax core-change Requires an update to core to be accepted on hold Something that can't be done, or done correctly, right now T: bug A bug in an existing language feature

Comments

@dkali
Copy link

dkali commented Nov 28, 2016

The regression was introduced by the PR #466

Now all the code in a file is highlighted as a sting after the heredoc formatted method call:
82203a1e3f3a5cd8d147118ff442479e326b5920

This behavior has seriously impacted the SublimeText usage on the projects where heredoc method calls are used oftenly, so I have to revert the change in the Ruby.sublime-syntax file or stay on the build 3114 where it was working.

On build version 3114 syntax highlighting was working slightly better, but still not fully correct. First text variable was highlighted correctly, but rest of them not. But at least it was not ruining the highlighting for the rest of my code.

p.s.: issue discussion on forum: https://forum.sublimetext.com/t/herodoc-text-format-is-broken/24266/2

@wbond
Copy link
Member

wbond commented Nov 28, 2016

Can you post the raw code so I don’t have to re-type it?

@dkali
Copy link
Author

dkali commented Nov 29, 2016


func(<<-var1, <<-var2, <<-var3)
  some text 1
var1
  some text 2
var2
  some text 3
var3

h = {a: 1, c: 2, r: 3}

@wbond wbond added the T: bug A bug in an existing language feature label Nov 30, 2016
@dkali
Copy link
Author

dkali commented May 28, 2018

Could you please elevate the priority for this Bug? It greatly impacts user experiense.

@flatrocks
Copy link

flatrocks commented Jan 11, 2019

Current operation is much better than originally reported in this thread but this problem remains in version 3.1.1, Build 3176:
image
In squiggly heredocs and (regular ones, too,) included #{...} string interpolation syntax is displayed erratically, sometimes as a comment, sometimes not, depending on context within the HEREDOC string.

This example works correctly (that is, it behaves as expected when executed via Ruby 2.5,) interpreting all the interpolations and resulting in the correct string value.

@michaelblyons
Copy link
Collaborator

RE Original report: It's not immediately apparent from the screenshot, but Sublime is trying to pop the HEREDOCs from the stack LIFO.

func(<<-var1, <<-var2, <<-var3)
  some text 1
var1
  some text 2
var2
  some text 3
var3
# still in "var2"
var2
# still in "var1"
var1

# Now we're free

h = {a: 1, c: 2, r: 3}

RE second report: plaintext below

sql = <<~SQL
    #{ITEM_SELECT}
    WHERE sku = '#{sku}'
SQL

@deathaxe
Copy link
Collaborator

With regards to the original error report:

Sublime Text's syntax engine can't handle multiple HEREDOCs at a line. I tried to implement it for Perl before, but you just can't do it proberly because HEREDOCs don't push/pop in a linear style.

We'd need a new engine feature for it.

With regards of the secondreport:

This issue is partly fixed by #2054, but might not yet work for all supported embedded syntaxes in any situation. It's tricky (and currently a bit dangerous) to inject the interpolation support into an embedded syntax as the required with_prototype is well known to easily cause recursions.

@skalee
Copy link

skalee commented Apr 10, 2021

How about (un)indented-heredoc-end popping all remaining heredocs contexts, if any? That would be far from perfect, obviously, but at least would fix syntax highlight in the trailing part of file.

@deathaxe deathaxe added the core-change Requires an update to core to be accepted label May 30, 2022
@jjb
Copy link

jjb commented Apr 18, 2024

status in 2024:

Sublime

Screenshot 2024-04-18 at 4 15 29 PM

VS Code

broken for first one, works for second 2, ends correctly 🤷

Screenshot 2024-04-18 at 4 15 19 PM

gist published

Screenshot 2024-04-18 at 4 14 51 PM

gist editor

works better than published 🤷

Screenshot 2024-04-18 at 4 14 37 PM

@deathaxe
Copy link
Collaborator

Not sure, what the intention of those huge screenshots is, but this kind of heredocs is not possible with ST's syntax highlighting engine.

@deathaxe deathaxe added the on hold Something that can't be done, or done correctly, right now label Apr 19, 2024
@jjb
Copy link

jjb commented Apr 19, 2024

Heh, sorry about large images - was just curious myself how they all compare so I thought I would document it, maybe someone in future might have an idea of how logic could be borrowed from one of the other engines.

@deathaxe
Copy link
Collaborator

The logic how to do it has already been out-lined by a former sublimehq dev. It would require a rather specific syntax engine logic and syntax definition syntax for just this single use case. As there are only very few syntaxes left these days making use of heredocs, it seems rather unlikely to be supported anytime soon.

@jjb
Copy link

jjb commented Apr 19, 2024

Gotcha - thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: Syntax core-change Requires an update to core to be accepted on hold Something that can't be done, or done correctly, right now T: bug A bug in an existing language feature
Projects
None yet
Development

No branches or pull requests

7 participants