-
Notifications
You must be signed in to change notification settings - Fork 514
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
Add semantic highlighting support via the LSP #1899
Add semantic highlighting support via the LSP #1899
Conversation
Registers the proposed LSP APIs to enable semantic highlighting support for Dockerfiles. Signed-off-by: Remy Suen <remy.suen@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested out some scenarios, it looks good. A couple of questions for @rcjsuen:
-
Not sure how solvable this is, but images from not-Docker-Hub offer a link that will 404 when you open it, for example, the following links to https://hub.docker.com/r/dotnet/core/aspnet/ (which will 404)
-
"bar"
is just a string here, right? Shouldn't it get the orange-ish highlighting? (Or is that the bug # 2 you mention?)
-
Specifically in your example Dockerfile showing some of the bugs, tab completion seems to stop working at the bottom; for example,
HEALTHCHECK
doesn't offer tab-completion until the entireHEALTHCHECK
word is typed in. In other Dockerfiles, it does still work.
(You can see the spaces at the end where I hit tab)
@bwateratmsft Thanks for taking a look.
|
@bwateratmsft Another interesting thing is that if you type Looks like there might be something else that may be amiss...? |
I guess also, # 1 is not a new issue, and nobody has complained yet... |
@bwateratmsft I was able to reproduce the issue with a simple piece of code using the Monaco Editor so I think it may be related to the grammar of file? The system seems convinced that the text cursor is inside a string so it doesn't appear to want to invoke code completion.
const content =
`# type on line 4, it works
# type on line 6, it fails
# type on line 7, it works
RUN \\'e\\'
`;
const language = "dockerfile";
monaco.languages.registerCompletionItemProvider(language, {
provideCompletionItems: function(_model, position) {
console.log(`provideCompletionItems called on line ${position.lineNumber} character ${position.column}`)
return {
suggestions: []
};
}
});
monaco.editor.create(document.getElementById("container"), {
value: content,
language: language
}); |
Correct, it's not a new issue and it has been like that since I first implemented Docker Hub linking support. Regarding the code completion issue, I have opened microsoft/vscode#95924 and microsoft/monaco-editor#1935. |
Improves the support for semantic tokens with some small fixes for strings and variables. Signed-off-by: Remy Suen <remy.suen@gmail.com>
@bwateratmsft I decided to just pull the trigger and cut a release so the three aforementioned semantic highlighting bugs should be fixed now. |
Awesome, thanks! I verified and all three are fixed. |
@bwateratmsft FYI regarding the code completion bug you discovered. |
@rcjsuen Thanks! |
* Add semantic highlighting support via the LSP Registers the proposed LSP APIs to enable semantic highlighting support for Dockerfiles. Signed-off-by: Remy Suen <remy.suen@gmail.com> * Upgrade to language server 0.0.24 for semantic token fixes Improves the support for semantic tokens with some small fixes for strings and variables. Signed-off-by: Remy Suen <remy.suen@gmail.com>
This is a preliminary implementation of semantic highlighting for Dockerfiles. This pull request intends to address #1840 which in a way is itself a collection of many long standing bug reports about malformed syntax highlighting in Dockerfiles.
To test this feature, simply enable semantic highlighting via the settings (or if you're using the JSON settings editor, the key is
"editor.semanticHighlighting.enabled"
).Known issues:
There are a few issues that will be fixed in the next release of the language server. You can copy/paste the Dockerfile below into VS Code to see what I mean.
Q&A:
How do I enable/disable semantic highlighting only for Dockerfiles?
From what I understand, you must use the JSON settings editor for this. Use the following JSON snippet to toggle the setting as you please. I'm not sure how you can achieve this with the GUI editor.
Why does your online Dockerfile editor seem to colour more things than VS Code?
I specifically made changes to my own editor so that it would provide custom colours for various situations. Based on the semantic highlighting wiki page, there appears to be a way to add custom colour mappings though I may be misunderstanding what is written on the page. I think this will require more investigation and can be addressed in a different pull request so I hope that is not a blocker for this pull request.
What is the ETA for the next release of the Dockerfile language server that will address the aforementioned bugs?
I don't have a timeline to share at the moment.