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

Ruby indented heredoc styles final newline character as delimiter, not heredoc #66

Closed
nyamatongwe opened this issue Mar 25, 2022 · 2 comments
Labels
ruby Caused by the ruby lexer

Comments

@nyamatongwe
Copy link
Member

nyamatongwe commented Mar 25, 2022

In this example, the first item is a standard heredoc and the second is an indented heredoc because of the - although it is not actually indented.

<<T
X
T

<<-T
X
T

The content line is X\n or X\r\n. Ruby defines that a heredoc includes the ending newline.
https://ruby-doc.org/core-2.3.1/doc/syntax/literals_rdoc.html#label-Here+Documents

The lexer correctly styles the \n for the standard heredoc as SCE_RB_HERE_Q but as SCE_RB_HERE_DELIM for the indented heredoc. This causes incorrect visuals when line ends are visible or an eolfilled style is specified. It also causes \r and \n to be styled differently causing problems with the automated tests.

This can be fixed with

diff --git a/lexers/LexRuby.cxx b/lexers/LexRuby.cxx
index b1bebb34..0fc04707 100644
--- a/lexers/LexRuby.cxx
+++ b/lexers/LexRuby.cxx
@@ -1321,7 +1321,7 @@ static void ColouriseRbDoc(Sci_PositionU startPos, Sci_Position length, int init
                                                 i - HereDoc.DelimiterLength + 1,
                                                 lengthDoc,
                                                 HereDoc.Delimiter)) {
-                styler.ColourTo(i - 1 - HereDoc.DelimiterLength, state);
+                styler.ColourTo(i - HereDoc.DelimiterLength, state);
                 styler.ColourTo(i, SCE_RB_HERE_DELIM);
                 state = SCE_RB_DEFAULT;
                 preferRE = false;
@nyamatongwe nyamatongwe added the ruby Caused by the ruby lexer label Mar 25, 2022
@zufuliu
Copy link
Contributor

zufuliu commented Mar 26, 2022

Good catch.

nyamatongwe added a commit that referenced this issue Mar 26, 2022
This fixes incorrect visuals and enables automated tests.
@nyamatongwe
Copy link
Member Author

Committed fix.

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

No branches or pull requests

2 participants