tree-sitter-dockerfile
tree-sitter-dockerfile copied to clipboard
Incorrect highlighting for certain RUN directives in nvim
Hi, I'm seeing some incorrect highlighting for some of the RUN directives in this Dockerfile in Neovim;
FROM node:20-alpine AS builder
WORKDIR /staging
COPY . /staging/
RUN corepack enable
RUN pnpm install --frozen-lockfile
RUN pnpm build
RUN pnpm prune --prod
FROM node:20-alpine
WORKDIR /app
COPY --from=builder /staging/package.json /staging/pnpm-lock.yaml /app/
COPY --from=builder /staging/node_modules /app/node_modules
COPY --from=builder /staging/build /app/build
EXPOSE 3000
CMD ["node", "/app/build"]
Output of :InspectTree;
(command) ; [7:5 - 10:21]
name: (command_name) ; [7:5 - 12]
(word) ; [7:5 - 12]
argument: (word) ; [7:14 - 8:8]
argument: (word) ; [8:10 - 16]
argument: (word) ; [8:18 - 9:8]
argument: (word) ; [9:10 - 10:8]
argument: (word) ; [10:10 - 14]
argument: (word) ; [10:16 - 21]
(from_instruction) ; [1:1 - 30]
(image_spec) ; [1:6 - 19]
name: (image_name) ; [1:6 - 9]
tag: (image_tag) ; [1:10 - 19]
as: (image_alias) ; [1:24 - 30]
(workdir_instruction) ; [3:1 - 16]
(path) ; [3:9 - 16]
(copy_instruction) ; [5:1 - 16]
(path) ; [5:6 - 6]
(path) ; [5:8 - 16]
(run_instruction) ; [7:1 - 19]
(shell_command) ; [7:5 - 19]
(shell_fragment) ; [7:5 - 19]
(run_instruction) ; [8:1 - 34]
(shell_command) ; [8:5 - 34]
(shell_fragment) ; [8:5 - 34]
(run_instruction) ; [9:1 - 14]
(shell_command) ; [9:5 - 14]
(shell_fragment) ; [9:5 - 14]
(run_instruction) ; [10:1 - 21]
(shell_command) ; [10:5 - 21]
(shell_fragment) ; [10:5 - 21]
(from_instruction) ; [12:1 - 19]
(image_spec) ; [12:6 - 19]
name: (image_name) ; [12:6 - 9]
tag: (image_tag) ; [12:10 - 19]
(workdir_instruction) ; [14:1 - 12]
(path) ; [14:9 - 12]
(copy_instruction) ; [16:1 - 72]
(param) ; [16:6 - 19]
(path) ; [16:21 - 41]
(path) ; [16:43 - 65]
(path) ; [16:68 - 72]
(copy_instruction) ; [17:1 - 59]
(param) ; [17:6 - 19]
(path) ; [17:21 - 41]
(path) ; [17:43 - 59]
(copy_instruction) ; [18:1 - 45]
(param) ; [18:6 - 19]
(path) ; [18:21 - 34]
(path) ; [18:36 - 45]
(expose_instruction) ; [20:1 - 11]
(expose_port) ; [20:8 - 11]
(cmd_instruction) ; [21:1 - 26]
(json_string_array) ; [21:5 - 26]
(json_string) ; [21:6 - 11]
(json_string) ; [21:14 - 25]
Screenshot of highlighting I'm seeing;
Build info;
- Neovim version: 0.9.5
- nvim-treesitter commit:
3ef8d25df2d8eca6f15a6889cb2bc9d4c6101096 dockerfile.soparser commit:439c3e7b8a9bfdbf1f7d7c2beaae4173dc484cbf
It seems the top most command node in the treesitter output is incorrectly catching the corepack command onwards, until the end of the 4th and final RUN directive, with everything after being treated as an argument to corepack
I think I'm experiencing the same problem going off your explanation. Its considering everything after python3 as an argument.
FROM alpine:edge
USER root
ENV PYTHONUNBUFFERED=1
RUN apk add python3
#RUN pip3 install --no-cache --upgrade pip setuptools
RUN apk add curl
WORKDIR /app
copy . .
CMD python3 main.py
(source_file ; [0, 0] - [16, 0]
(program ; [5, 4] - [15, 19]
(command ; [5, 4] - [15, 19]
name: (command_name ; [5, 4] - [5, 7]
(word)) ; [5, 4] - [5, 7]
argument: (word) ; [5, 8] - [5, 11]
argument: (concatenation ; [5, 12] - [9, 7]
(word) ; [5, 12] - [5, 19]
(word)) ; [9, 4] - [9, 7]
argument: (word) ; [9, 8] - [9, 11]
argument: (word) ; [9, 12] - [15, 11]
argument: (word))) ; [15, 12] - [15, 19]
(from_instruction ; [0, 0] - [0, 16]
(image_spec ; [0, 5] - [0, 16]
name: (image_name) ; [0, 5] - [0, 11]
tag: (image_tag))) ; [0, 11] - [0, 16]
(user_instruction ; [2, 0] - [2, 9]
user: (unquoted_string)) ; [2, 5] - [2, 9]
(env_instruction ; [3, 0] - [3, 22]
(env_pair ; [3, 4] - [3, 22]
name: (unquoted_string) ; [3, 4] - [3, 20]
value: (unquoted_string))) ; [3, 21] - [3, 22]
(run_instruction ; [5, 0] - [5, 19]
(shell_command ; [5, 4] - [5, 19]
(shell_fragment))) ; [5, 4] - [5, 19]
(comment) ; [6, 0] - [6, 53]
(run_instruction ; [9, 0] - [9, 16]
(shell_command ; [9, 4] - [9, 16]
(shell_fragment))) ; [9, 4] - [9, 16]
(workdir_instruction ; [11, 0] - [11, 12]
(path)) ; [11, 8] - [11, 12]
(copy_instruction ; [13, 0] - [13, 8]
(path) ; [13, 5] - [13, 6]
(path)) ; [13, 7] - [13, 8]
(cmd_instruction ; [15, 0] - [15, 19]
(shell_command ; [15, 4] - [15, 19]
(shell_fragment)))) ; [15, 4] - [15, 19]
highlighting
- Neovim version: 0.10.0
- I don't know where treesitter commit or docker.so parser commit is.
same here
- nvim 0.10
- i should be using everything at their latest versions
This appears to be an issue with the bash language injection. program is not a node created by the Dockerfile grammar, and disabling the bash injections gives me correct looking highlighting. I do not actually maintain the injections in nvim-treesitter, so I'm not exactly sure what's going on there, but it seem possible the issue is related to this.