jeff-hykin / better-shell-syntax

💾 📦 ♻️ An improvement to the shell syntax for VS Code
MIT License
52 stars 4 forks source link

Highlighting other languages inside of HEREDOC's #64

Open balupton opened 1 year ago

balupton commented 1 year ago

The code with a problem is:

https://github.com/discourse/discourse_docker/blob/313f86feffe996349ec83877ccc57f6e12849446/launcher#L348-L368

#!/usr/bin/env bash

read -r -d '' env_ruby << 'RUBY'
    require 'yaml'

    input=STDIN.readlines.join
    # default to UTF-8 for the dbs sake
    env = {'LANG' => 'en_US.UTF-8'}
    input.split('_FILE_SEPERATOR_').each do |yml|
       yml.strip!
       begin
         env.merge!(YAML.load(yml)['env'] || {})
       rescue Psych::SyntaxError => e
        puts e
        puts "*ERROR."
       rescue => e
        puts yml
        p e
       end
    end
    env.each{|k,v| puts "*ERROR." if v.is_a?(Hash)}
    puts env.map{|k,v| "-e\n#{k}=#{v}" }.join("\n")
RUBY

It looks like:

image

It should look like:

https://github.com/discourse/discourse_docker/blob/313f86feffe996349ec83877ccc57f6e12849446/launcher#L348-L368

image

Suggestion

Instead of simply using EOF one should be able to use a language identifier, such as RUBY, JAVASCRIPT, TYPESCRIPT, etc, to highlighting the contents inside the heredoc as the language.

For myself that will provide a much better experience for pieces of code like: https://github.com/bevry/dorothy/blob/b467c8e2ecedadb5cbc41c1c778b420a91c60454/commands/brew-installed#L119-L162

Which is typescript code being sent to deno

jeff-hykin commented 1 year ago

I agree it would be nice, I do a lot of heredocs like this. I've also embedded nested languages like this in other syntaxes. It's not the easiest thing to do right, but I'll see what I can do, it might take me a bit to get around to implementing it. It must be done for every language manually.

Also it's always nice to meet another Deno developer :wave:

balupton commented 1 year ago

Good to hear, take your time.

PS. If you can, you should activate GitHub Sponsors, I try to sponsor everything I use at $1/month (under the belief that if everyone does so too, then paying it forward would also pay the bills).

balupton commented 1 year ago

While it isn't much, I've posted a $20USD bounty for this: https://app.bountysource.com/issues/123759829-syntax-highlighting-of-heredoc-statements

macwarriorwow commented 1 year ago

What editor are you using ?

balupton commented 1 year ago

vscode

makeasnek commented 1 year ago

Please do not use bountysource. Many devs have had trouble getting paid there. You can check out this lemmy community as an alternative https://lemmy.ml/c/bugbounties

For statements from devs who have been unable to cash out from bountysource see: https://github.com/bountysource/core/issues

balupton commented 1 year ago

@makeasnek thanks for the heads up, I've submitted disputes to paypal — any thoughts on https://www.gitcoin.co and https://fundrequest.io/requests?phase=open - never heard of lemmy before.

/ref https://github.com/bountysource/core/issues/1586

makeasnek commented 1 year ago

Lemmy is like reddit but it's OSS and federated. Gitcoin no longer does bounties, only "hackathons" unfortunately. I haven't used fundrequest but looks interesting.

jeff-hykin commented 7 months ago

Some progress; the example now has a string.quoted.heredoc.no-indent.RUBY tag instead of just string.quoted.heredoc.no-indent. And this works for any language/delimiter.

So, now, anyone can make a VS Code extension that targets, for example string.quoted.heredoc.no-indent.RUBY and have that section be highlighted with the grammar of their choice (ex: the ruby grammar).