-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
(bash) Language does not highlight heredocs #2622
Comments
Bash is a very simple grammar and could probably use a champion if one wanted to step up. We definitely could improve support for here docs and here strings (if we can detect them).
Operators is something we traditionally do not highlight (on purpose), but there is a separate discussion regarding that: |
@yyyc514 Thanks for the pointers. |
Also noticing numbers/integers aren't highlighted, as in: x=3
phoneNum=5557778888 etc. |
It's not immediately clear to me how or even if subshells should be highlighted... since it's currently not treated specially it'll currently be highlighted exactly the same as the surrounding shell itself, which is what you'd expect (for a subshell)... if the debate is just coloring the |
But if you actually wanted to get involved yourself then some of this might indeed fall under: (As mentioned before) |
To review:
|
I might also back out number support until we have a Bash person willing to work on this and think thru all the implications... it seems there are lots of edge cases where perhaps numbers should not be highlighted, and Bash provides no clues for when something is a Number vs a string, does it? |
I think no. |
Well that's how it's done for here-doc though... so if we don't do it for <<< is that being inconsistent? |
Hm, right, I missed it. I think it's better to not color |
But yet we ALWAYS color Really I think I just persuaded myself that these things are "part of the string". |
Of course if we ever had more nuance we might highlight:
But that's a talk for another day. |
I think we shouldn't do anything about highlighting And if so, we also shouldn't color here-doc's |
I don't really see any justification/logic for your reasoning though, just a preference. (well other than "it complicates") These "bookends" are quite literally string delimiters, which we have always highlighted AFAIK - and also currently highlight in other languages that support here-docs: Ruby, PHP, C++...
Not sure I follow this?
Or it's badly broken... Just highlighting
It's just another variant... some languages have 20 string variants, doesn't seem that much more complex. |
Long-term it seems perhaps we need a |
Those are differently quoted strings:
So it's not just another variant, it's rather variants of BRACED_VAR, QUOTE_STRING, APOS_STRING and maybe some other modes. |
But we do highlight strings differently in bash right now:
I believe we must retain this behavior for here-strings, no matter how we highlight Well, I'm ok with highlighting both |
Oh yeah, of course breaking that would be no good, agreed. :-)
Good to know, and convenient.
But now you've persuaded me that <<< might be different LOL. |
LOL. But doesn't it seem natural to highlight |
That's what we're discussing. I'm seeing them an entirely different now. I'm seeing Making Someone who uses and reads Bash code all day might have their own thoughts. VS Code colors them both as "operators". |
But heredoc is also a sort of piping. Bash manual describes (And in most detailed way we'd highlight |
You're just saying what I just said: 😎
Maybe in Bash it's piping, certainly not how I've ever thought about it in Ruby in 10+ years. :)
No disagreement. Same as VS Code does it.
Consistent with what? Are you indeed saying "Yes, these should be right now highlighted differently in Bash than they are in Ruby?" I'm not sure you answered that. |
Ah, Ruby. I meant consistency of Anyway I think that internal consistency of one language is bit more important than consistency between two quite different languages. So answering
I'd say yes I am. |
@egor-rogov So this? |
Hmm... |
@bric3 Do you have any thoughts here? |
Hi, sorry for the delay. I tend to think a bit, as in I like operator highlithing, as it it's easier to grasp how a code snippet is articulated.
That leads me to says here(doc|string) operators and delimiters should be hightlighted the same way. Since it's yet possible to distinguish string delimiters I think it's ok to highlight them the same as the string and semantically they go together anyway. I have a personal b jshell -s - <<EOF
System.out.printf("Procs: %s%n", Runtime.getRuntime().availableProcessors())
EOF jshell -s - <<-EOF
System.out.printf("Procs: %s%n", Runtime.getRuntime().availableProcessors())
EOF jshell -s - <<< 'System.out.printf("Procs: %s%n", Runtime.getRuntime().availableProcessors())' And maybe later herestring highlighting might be refined as needed. $ (export FOO=pwd; cat <<< 'this is $FOO')
$FOO
$ ( export FOO=pwd; cat <<< "this is $FOO" )
pwd
$ {export FOO=pwd; cat <<< $FOO}
pwd
$ {export FOO=pwd; cat <<< ${FOO}}
pwd
$ { export FOO=pwd; cat <<< `$FOO` }
/home/egor I know it's easy for me to express an "easy" opinion as I am not a highlightjs developer nor a JS developer. Sorry for that. |
I think for now this issue is going to focus on just highlighting heredocs at all [as strings]... highlighting redirection and delimiters is a discussion for another day. In the past we have not highlighted such things and I'm not leaving an issue open per language for "higher fidelity" highlighting. We already have a global issue. If someone comes along that wants to actually do the work themselves then I'm happy to review a PR. The question is between:
and
Should EOF be included as part of the string (it is in Ruby and other languages it's included in the same sense that we include |
Sorry I didn't express well enough my opinion. Heredoc delimiters are delimiters add should be part of the content in my opinion (just like other multiline strings in other languages*). But if for some reason this is tricky then only highlighting the content is ok. * python, groovy, swift, java, ... |
Describe the issue
Is is expected that the
bash
language do no highlight some specific characters. in the screenshot belowI would have expected the following would be highlighted
|
a pipe\
the continue command marker at the end of the line>
<
Stream redirections<<
and<<<
, here doc, and here string$(...)
subshell variable (maybe not what's inside but at least the whole variable or just the parenthesis)shell
bash
Which language seems to have the issue?
I believe it's the
bash
language which is also used by the shell language.Are you using
highlight
orhighlightAuto
?I'm not sure of the question, the script uses :
hljs.initHighlightingOnLoad();
...
Sample Code to Reproduce
Reproducer : https://jsfiddle.net/kcyd487f/
Expected behavior
Highlight the menetionned element above. Maybe other characters elements may be interesting.
For heredoc I'm not sure everything could be highlighted, especially the multiline text, as the EOF marker can be anything.
Additional context
I'm using asciidoctor, but the issue can be reproduced in the JSfiddle too.
The text was updated successfully, but these errors were encountered: