-
Notifications
You must be signed in to change notification settings - Fork 752
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
Feature Request: Go Templates Support #609
Comments
The prior discussion history is here microsoft/vscode-go#228 We hope How to provide syntax highlighting based on textmate or semantic highlighting provided through LSP future release - that still need to be figured out. /cc @stamblerre |
I wonder if we could do this through LSP's upcoming semantic tokens feature: https://microsoft.github.io/language-server-protocol/specifications/specification-3-16/#textDocument_semanticTokens. |
@hyangah: Should this be in the |
Change https://golang.org/cl/284095 mentions this issue: |
https://go-review.googlesource.com/c/vscode-go/+/281392 is a prep work for template support. However, the handling is not available in gopls yet, and LSP registration is activated only in the preview mode (per https://go-review.googlesource.com/c/vscode-go/+/283639) This CL is the remaining task from cl/283639 to disable the experimental feature from the stable release. We will revert this change when gopls is ready to handle templates. Update #609 Change-Id: I72d04b11f14fde25b7ad64e6a9a82f7c20e32b4c Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/284095 Trust: Hyang-Ah Hana Kim <hyangah@gmail.com> Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com> TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Suzy Mueller <suzmue@golang.org>
Any reason why |
We are adding incremental support for templates, starting with files with the |
Any way to make |
Change https://golang.org/cl/342069 mentions this issue: |
filenamePatterns allows glob matching. Gopls processes any '.*tmpl' files as go template file. For #609 Change-Id: I73334c1fdb7d23544591bbbdb5a3ad78397fa227 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/342069 Trust: Hyang-Ah Hana Kim <hyangah@gmail.com> Trust: Peter Weinberger <pjw@google.com> Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com> TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Peter Weinberger <pjw@google.com>
Change https://golang.org/cl/371914 mentions this issue: |
And narrow the set of file extensions to match the current gopls default (.tmpl and .gotmpl). We will keep working on settings plumbing. For #609 Change-Id: I8d613e52dc2eeecb072339d53624178a5ed01ecb Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/371914 Trust: Hyang-Ah Hana Kim <hyangah@gmail.com> Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com> Reviewed-by: Peter Weinberger <pjw@google.com> Trust: Peter Weinberger <pjw@google.com> TryBot-Result: kokoro <noreply+kokoro@google.com>
@inliquid in vscode, you can |
@oliverpool I'm aware of this option, but not sure how it helps. Generally I would like to have support of go templates when working on Example: please see how it's done in Goland. |
Sorry, I only replied to this part of your comment:
I agree with you that the supporting a mix of HTML and go template would greatly improve the developer experience (I am using |
It looks like the referenced golang/go#36911 has been closed, does that mean template highlighting should work now? Sorry, I'm new to working with golang, and just trying to figure out how to get syntax highlighting in my html go templates. Whether that means using a specific naming convention or enabling a setting... |
gopls v0.7.5 has template support for files with language id VSCode Go extension v0.31.0 will classify files with extension
We are very close to v0.31.0 - RC1 is available for testing at https://github.com/golang/vscode-go/releases/tag/v0.31.0-rc.1 Supported features are
Templates embedded in .go file, diagnostics beyond the template file itself (e.g. detecting runtime error such as validation of data, associated templates, custom functions, ...) are not in the scope of supported features. |
Change https://golang.org/cl/380615 mentions this issue: |
…pport We already have a section in the advanced.md doc abount default formatting and imports behavior. I hope this additional reference helps users to discover the control knob. Didn't mention completion, diagnostics for Go template files yet. We need to update the diagnostics section to discuss gopls's diagnostics feature. Updates golang#609 Change-Id: Ib2e695d847c56bd4f562d91d2938cb5c1a032764
…pport We already have a section in the advanced.md doc abount default formatting and imports behavior. I hope this additional reference helps users to discover the control knob. Didn't mention completion, diagnostics for Go template files yet. We need to update the diagnostics section to discuss gopls's diagnostics feature. Updates #609 Change-Id: Ib2e695d847c56bd4f562d91d2938cb5c1a032764 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/380615 Trust: Hyang-Ah Hana Kim <hyangah@gmail.com> Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com> TryBot-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: Peter Weinberger <pjw@google.com>
Just curious on how this work is going? I've been messing around with the HTML templating support for Go and have found that I still can't quite get it to work how I want. Given the following basic HTML template: <!-- test.html -->
<!DOCTYPE html>
<head>
</head>
<body>
<div>
{{ .SomeVal }}
</div>
</body>
</html> and the following // .vscode/settings.json
{
"editor.formatOnSave": true,
} upon saving the file, the default HTML formatter runs and works as expected. It even deals with However, once I change my settings as per the documentation: {
"editor.formatOnSave": true,
"files.associations": {
"*.html": "gotmpl"
},
"gopls": {
"build.templateExtensions": [
".html"
],
},
} This happens: Syntax highlighting for the templating handlebars works as expected, but not for the HTML. Also, because its not considered to be an HTML file, none of the formatters run. This also applies to other embedded languages like JS: At the moment I'm stuck not using the go templating features because of this. Usually, I would just accept this and continue to use a regular HTML formatter as it works with most templating features. However, the default VSCode beautifier has its own issues when it comes to formatting template handlebars in embedded Javascript: I'd be grateful if you're able to share any existing solutions to any of the above and if not, whether these are known problems and whether they are on the roadmap. Thanks! :) |
I don't understand what vscode does when there are conflicting rules about
what language a file is (in this case you want both 'gotmpl' and 'html').
I'll try to find someone more expert than I am.
…On Wed, Mar 16, 2022 at 9:18 AM Pete Davison ***@***.***> wrote:
Just curious on how this work is going? I've been messing around with the
HTML templating support for Go and have found that I still can't quite get
it to work how I want.
Given the following basic HTML template:
<!-- test.html --><!DOCTYPE html>
<head>
</head>
<body>
<div>
{{ .SomeVal }}
</div>
</body></html>
and the following settings.json file:
// .vscode/settings.json{
"editor.formatOnSave": true,}
upon saving the file, the default HTML formatter runs and works as
expected. It even deals with {{ x }} correctly. (Also works for any other
template syntax I can throw at it):
[image: image]
<https://user-images.githubusercontent.com/9294862/158594024-4431f27a-d8c3-462f-960a-5aab54409372.png>
However, once I change my settings as per the documentation
<https://github.com/golang/tools/blob/master/gopls/doc/features.md#template-files>
:
{
"editor.formatOnSave": true,
"files.associations": {
"*.html": "gotmpl"
},
"gopls": {
"build.templateExtensions": [
".html"
],
},
}
This happens:
[image: image]
<https://user-images.githubusercontent.com/9294862/158594981-bbf85910-8dea-4d7e-8353-b487ca72554d.png>
Syntax highlighting for the templating handlebars works as expected, but
not for the HTML. Also, because its not considered to be an HTML file, none
of the formatters run. This also applies to other embedded languages like
JS:
[image: image]
<https://user-images.githubusercontent.com/9294862/158595631-b66e67b1-1c0d-44a6-aa41-edac5d0780da.png>
At the moment I'm stuck not using the go templating features because of
this. Usually, I would just accept this and continue to use a regular HTML
formatter as it works with most templating features. However, the default
VSCode beautifier has its own issues when it comes to formatting template
handlebars in embedded Javascript:
[image: image]
<https://user-images.githubusercontent.com/9294862/158597438-7eb79cdb-8769-4098-abee-ee4f63c4778a.png>
I'd be grateful if you're able to share any existing solutions to any of
the above and if not, whether these are known problems and whether they are
on the roadmap. Thanks! :)
—
Reply to this email directly, view it on GitHub
<#609 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABJIAI32P57HKSO5ILKJJLTVAHNR5ANCNFSM4QX6A2YA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
In VSCode, I toggle between languages using the language tab at the bottom of the window rather than the settings.json. |
I do not know if this can help but I'm using successfully this VSCode extension: https://github.com/jinliming2/vscode-go-template. I had a problem today: jinliming2/vscode-go-template#16. |
Since this is some support for this in gopls now, can this be worked on (or documented, if it's just a matter of documentation?) https://github.com/golang/tools/blob/master/gopls/doc/features.md#template-files |
That's already documented. It is under syntax highlighting, but some completion or simple diagnostics are offered. The only reason we left this issue open was some users wanted to see the go template support coexist along with other languages (for example html? in #609 (comment)), outlined in https://code.visualstudio.com/api/language-extensions/embedded-languages#language-services or ideas discussed in microsoft/vscode#1751. But none of them seem like a trivial project. Will close this issue since we don't have a plan to work on this. If a new easy way to handle this universal language injection from the extension side, please let us know by opening a new issue with the details. Thanks. |
It doesn't seem like the state of integration supports intelligent autocomplete, I think another issue to improve the quality of completions in templates would be appropriate. |
I just published a vscode plugin for go templates that supports autocomplete, to some degree, by transpiling go templates to go: https://github.com/mortenson/go-template-transpiler-extension |
checking back again in 2024... any update on this feature? |
Would it be possible to add formatting, autocomplete, and colorization for Go templates? (.tmpl)
The text was updated successfully, but these errors were encountered: