nvim-treesitter/tests/query/injections/dockerfile/bash-on-run-instructions.dockerfile
Valentin Krasontovitsch b760eef0ba
fix(dockerfile): correct bash syntax highlighting
when a dockerfile contains several RUN statements, the syntax
highlighting would sometimes run over and encompass dockerfile
statements after the RUN command (typically everything between the first
and last RUN statement, though the bash syntax bleed can be broken by
terminating a RUN statement with a semicolon, or a space 🙄)

we fix this by using a slightly different approach to recognizing /
grouping (the content of) RUN commands:

- instead of having shell_command at the top level of the block we
  changed, we're using run_instruction - so parsing happens per `RUN`
  statement, which is really what we want
- inseade of `injection.combined`, we use `injection.include-children`,
  which combines all the shell fragments (the text parts of a shell
  command, including after newline continuations), which is really what
  we want, as that's all the text of a RUN statement

that fixes the highlight bleed, and preserves correct highlighting for
each RUN statement.

we also add a regression test for highlighting.

Closes #6530, #6975
2026-03-12 23:30:55 +01:00

11 lines
105 B
Docker

FROM foo
RUN bar
# ^ @bash
FROM haha
# ^ @!bash
RUN \
baz
# ^ @bash
COPY apt apt
# ^ @!bash