Skip to content

Add syntax highlighting and LSP for Dockerfiles#6905

Closed
everettraven wants to merge 2 commits intozed-industries:mainfrom
everettraven:feature/dockerfile-syntax-lsp
Closed

Add syntax highlighting and LSP for Dockerfiles#6905
everettraven wants to merge 2 commits intozed-industries:mainfrom
everettraven:feature/dockerfile-syntax-lsp

Conversation

@everettraven
Copy link
Contributor

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:
Screenshot 2024-01-27 at 8 28 25 PM

Release Notes:

  • Added syntax highlighting and LSP for Dockerfiles

@cla-bot
Copy link

cla-bot bot commented Jan 28, 2024

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'.

@everettraven
Copy link
Contributor Author

@cla-bot check

@cla-bot
Copy link

cla-bot bot commented Jan 28, 2024

The cla-bot has been summoned, and re-checked this pull request!

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Jan 28, 2024
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

async_maybe!({

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh nice, thanks for letting me know :) - done in the latest force push: e4e2b22

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the full language server name I think we'll want to use the name of the "binary":

Suggested change
LanguageServerName("dockerfile".into())
LanguageServerName("docker-langserver".into())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good point! Updated in the latest force push: e4e2b22

@d1y
Copy link
Contributor

d1y commented Jan 28, 2024

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
image

@maxdeviant maxdeviant changed the title (feat): Add syntax highlighting and LSP for Dockerfiles Add syntax highlighting and LSP for Dockerfiles Jan 28, 2024
@SomeoneToIgnore
Copy link
Contributor

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.

@everettraven everettraven force-pushed the feature/dockerfile-syntax-lsp branch from e0b409d to e4e2b22 Compare January 29, 2024 14:33
@everettraven
Copy link
Contributor Author

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 image

@d1y I updated the tree-sitter highlighting to get as close to this as I could. The new highlighting looks like this:
Screenshot 2024-01-29 at 9 32 04 AM

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 RUN instruction) and no shell command syntax highlighting (it was either the whole shell command is highlighted or none, although this limitation could be due to me being more novice in messing with this tooling). That being said, I think this PR is "good enough" as is regarding the syntax highlighting and it could be incrementally improved in the future.

Signed-off-by: everettraven <everettraven@gmail.com>
Signed-off-by: everettraven <everettraven@gmail.com>
@everettraven everettraven force-pushed the feature/dockerfile-syntax-lsp branch from e4e2b22 to 12a5fb3 Compare January 29, 2024 14:45
@everettraven
Copy link
Contributor Author

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.

@SomeoneToIgnore Thanks for pointing that out! Rebased and added!

@everettraven
Copy link
Contributor Author

@maxdeviant @SomeoneToIgnore Anything else needed to get this merged?

Copy link
Contributor

@SomeoneToIgnore SomeoneToIgnore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I looked at https://github.com/neondatabase/neon/blob/main/Dockerfile with this and looks solid, thank you for bringing this up.

One minor thing I see is this
image

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)
image

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 },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want syntax highlights for those, we need brackets.scm

@SomeoneToIgnore
Copy link
Contributor

This needs a rebase, but otherwise I see no blocking issues, the comments are welcome to be fixed in follow-up PRs.

@d1y
Copy link
Contributor

d1y commented Feb 18, 2024

Do you have any further questions about this PR? Can we merge? I really need this

@SomeoneToIgnore
Copy link
Contributor

SomeoneToIgnore commented Feb 18, 2024

Can we merge?

Would be nice, but GH does not allow this for the PRs with conflicts. Neither can I push into the branch, so one small step has to be done by somebody.

#6905 (comment)

image

SomeoneToIgnore added a commit that referenced this pull request Feb 18, 2024
Release Notes:

- Added Dockerfile syntax highlighting and LSP support

---------

Co-authored-by: Bryce Palmer <bpalmer@redhat.com>
Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
@SomeoneToIgnore
Copy link
Contributor

#7977 made that happen thanks to @d1y , hence closing this stale one.

@everettraven
Copy link
Contributor Author

@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!

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

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docker & Docker Compose support

5 participants