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

[Feature request] support syntax highlighting in heredoc RUN instructions #4183

Open
Igetin opened this issue Dec 1, 2023 · 4 comments
Open

Comments

@Igetin
Copy link

Igetin commented Dec 1, 2023

The gist

When using the RUN instruction with the heredoc notation, that section should use the appropriate syntax highlighting for the language used.

An example of how it looks like now for a shell (Bash) script:


How the same code is highlighted in a shell file, and how I would like it to look in the Dockerfile:


Description

Basically, I’m asking for something similar to how Markdown files in VS Code are highlighted. Normally the file has Markdown highlighting, but for code blocks, those sections are highlighted for a different syntax (e.g. shell syntax if the code block starts with ```bash).

The extension should look at the SHELL instruction, the RUN instruction arguments, and the shebang for determining the correct highlighting for the RUN block. For example, the extension should properly highlight the Python code in all of the three examples below:

Example 1:

SHELL ["/usr/bin/python3", "-c"]
RUN <<EOF
def hello():
  print("hello world")
EOF

Example 2:

RUN /usr/bin/python3 <<EOF
def hello():
  print("hello world")
EOF

Example 3:

RUN <<EOF
#! /usr/bin/python3
def hello():
  print("hello world")
EOF
@dbreshears dbreshears added this to the Future milestone Dec 6, 2023
@JewelsBee

This comment was marked as spam.

@Igetin Igetin changed the title [Feature request] support shell syntax highlighting in heredoc RUN instructions [Feature request] support syntax highlighting in heredoc RUN instructions Jan 22, 2024
@rcjsuen
Copy link
Contributor

rcjsuen commented Mar 26, 2024

It's not clear to me how this can be achieved. I do not believe the language server protocol supports this kind of use case. If someone knows how the LSP can enable this use case, please let me know.

@thnee
Copy link

thnee commented Jun 14, 2024

It would definitely be nice to have support for this highly anticipated feature. We are using this syntax extensively now, and I am definitely missing syntax highlighting there.

Perhaps it is possible to get some inspiration from these links?
https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide#embedded-languages
https://code.visualstudio.com/api/language-extensions/embedded-languages
neovim/neovim#26783
camdencheek/tree-sitter-dockerfile#45

@awilkins
Copy link

awilkins commented Dec 9, 2024

Or we could use something like the triple-tick hints you have in Markdown ; use a heredoc marker that conveys what the inner language is

e.g.

In markdown
```sh
echo "Hello World!"
```
RUN <<sh
echo "export TERM=linux" >> /opt/mypackage/terminfo.sh
sh

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

7 participants