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

Add heredoc support #38

Open
href opened this issue Jan 17, 2022 · 6 comments
Open

Add heredoc support #38

href opened this issue Jan 17, 2022 · 6 comments

Comments

@href
Copy link

href commented Jan 17, 2022

Not sure if experimental features are of interest for this project, but I would assume Buildkit's heredoc support is here to stay:
https://www.docker.com/blog/introduction-to-heredocs-in-dockerfiles/

This would be especially nice for the bash flavor of the syntax.

@ggari-robotnik
Copy link

I made this first try, but I'm far from undestanding how works everything,
It still have issues but you can try on my fork
https://github.com/ggari-robotnik/Docker.tmbundle

Any help will be appreciated

@fenollp
Copy link

fenollp commented Dec 10, 2024

Came here from https://github.com/jaytaylor/Dockerfile.sublime-syntax for the Sublime Text 3 support. (note the same issue is still open over at vscode: microsoft/vscode-docker#4183)

I'm not familiar with how to define tmbundle syntaxes but after trying @ggari-robotnik's fork (it's not working for me), maybe someone would like to try to use this definition of HEREDOC syntax from the Bash tmbundle?

https://github.com/sublimehq/Packages/blob/52c3ca948b2f0fae986bf8f6ae006b7ef3bc1437/ShellScript/Bash.sublime-syntax#L1698-L1807

@princemaple
Copy link
Collaborator

@iamkroot
Copy link

iamkroot commented Jan 4, 2025

We already have this: master/Syntaxes/Dockerfile-bash.sublime-syntax

That's not enough unfortunately. Here's an example of docker's heredoc syntax:

RUN <<EOF
  echo hello
  cowsay moo
EOF

RUN echo this is a normal command

The current syntax of Dockerfile-bash assumes that anything that follows a directive (like RUN) is automatically in a JSON or bash scope. So in the above example, all of

<<EOF
  echo hello
  cowsay moo
EOF

gets parsed in bash scope. Since <<EOF is also bash heredoc syntax, the lines inside get marked as simple bash strings rather than full commands.

We need something similar to what @ggari-robotnik has done above (a special case for <<) to get proper support.

@iamkroot
Copy link

iamkroot commented Jan 4, 2025

Here's my attempt at this (building on https://github.com/ggari-robotnik/Docker.tmbundle from before)-

        - match: \s*(<<)\s*([A-Za-z][A-Za-z0-9_]*)\s+
          captures:
            1: keyword.other.dockerfile
            2: entity.name.tag.dockerfile
          set: scope:source.shell.bash
          with_prototype:
            - include: scope:source.shell.bash#prototype
            - match: ^\2
              captures:
                0: entity.name.tag.dockerfile
              pop: true

This works for the most part-

image

But for whatever reason, it works incorrectly when the inner lines are not indented-

image

I suspect it has something to do with how we are including the bash syntax, but I'm not too familiar with the format to fix this.

@princemaple
Copy link
Collaborator

Happy to accept the change. Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants