Add syntax highlighting and LSP for Dockerfiles#6905
Add syntax highlighting and LSP for Dockerfiles#6905everettraven wants to merge 2 commits intozed-industries:mainfrom
Conversation
|
We require contributors to sign our Contributor License Agreement, and we don't have @everettraven on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'. |
|
@cla-bot check |
|
The cla-bot has been summoned, and re-checked this pull request! |
There was a problem hiding this comment.
We have an async_maybe! macro in our util crate that can make this a bit nicer than having the IIFE.
Here's an example of it used in another LSP adapter:
zed/crates/zed/src/languages/gleam.rs
Line 104 in 5b9cc26
There was a problem hiding this comment.
Oh nice, thanks for letting me know :) - done in the latest force push: e4e2b22
There was a problem hiding this comment.
For the full language server name I think we'll want to use the name of the "binary":
| LanguageServerName("dockerfile".into()) | |
| LanguageServerName("docker-langserver".into()) |
There was a problem hiding this comment.
Ah, good point! Updated in the latest force push: e4e2b22
|
Awesome, but I noticed that the syntax after PREFIX(run. etc) doesn't seem to be highlighted, I'm very impressed by the vscode plug-in, can you help me take a look: https://marketplace.visualstudio.com/items?itemName=jeff-hykin.better-dockerfile-syntax |
|
This looks close to be done, so it would be great to add a new docs entry to the https://github.com/zed-industries/zed/tree/main/docs/src/languages list before merging. |
e0b409d to
e4e2b22
Compare
@d1y I updated the tree-sitter highlighting to get as close to this as I could. The new highlighting looks like this: There is variable expansion highlighting where possible but there are some limitations as the tree-sitter-dockerfile crate doesn't currently have support for expansion in certain instructions (one is the |
Signed-off-by: everettraven <everettraven@gmail.com>
Signed-off-by: everettraven <everettraven@gmail.com>
e4e2b22 to
12a5fb3
Compare
@SomeoneToIgnore Thanks for pointing that out! Rebased and added! |
|
@maxdeviant @SomeoneToIgnore Anything else needed to get this merged? |
SomeoneToIgnore
left a comment
There was a problem hiding this comment.
I looked at https://github.com/neondatabase/neon/blob/main/Dockerfile with this and looks solid, thank you for bringing this up.
I would expect ARG to be highlighted and both ARG and ENV values to be not highlighted.
I like what Intellij-based IDE do with bash code blocks and --from detection (e.g. recognizing pg-build and allowing to navigate to it)

but that's advanced stuff somebody can work later (presumably, LSP improvements are needed for the navigation part?)
| path_suffixes = ["Dockerfile"] | ||
| line_comments = ["# "] | ||
| brackets = [ | ||
| { start = "{", end = "}", close = true, newline = true }, |
There was a problem hiding this comment.
If we want syntax highlights for those, we need brackets.scm
|
This needs a rebase, but otherwise I see no blocking issues, the comments are welcome to be fixed in follow-up PRs. |
|
Do you have any further questions about this PR? Can we merge? I really need this |
|
@d1y Thanks for taking this over! I had some stuff come up and wasn't able to circle back around to address the comments/conflicts :(. Awesome to see this work get in! |





Looks like it could resolve zed-industries/extensions#504 ? I haven't messed with any docker-compose stuff but seeing as that is YAML based and there is already YAML support this should address the Dockerfile syntax highlighting and LSP support.
I'm also a Rust newbie so if there is anything that looks off please do let me know!
A screenshot showing syntax highlighting when running via

cargo run:Release Notes: