Skip to content
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

x/tools/gopls: support language features for text/template, html/template #36911

Closed
stamblerre opened this issue Jan 30, 2020 · 13 comments
Closed
Labels
FeatureRequest Issues asking for a new feature that does not need a proposal. FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@stamblerre
Copy link
Contributor

See discussion on microsoft/vscode-go#228.

@stamblerre stamblerre added the FeatureRequest Issues asking for a new feature that does not need a proposal. label Jan 30, 2020
@stamblerre stamblerre added this to the gopls/v1.0.0 milestone Jan 30, 2020
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Jan 30, 2020
@stamblerre stamblerre modified the milestones: gopls/v1.0.0, Unreleased Feb 2, 2020
@stamblerre stamblerre removed this from the Unreleased milestone Jul 23, 2020
@stamblerre stamblerre added this to the gopls/unplanned milestone Oct 21, 2020
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/301493 mentions this issue: text/template/parse: add mode to skip func-check on parsing

@gopherbot
Copy link
Contributor

Change https://golang.org/cl/301493 mentions this issue: text/template/parse: add a mode to skip func-check on parsing

@a-h
Copy link
Contributor

a-h commented Apr 4, 2021

I was looking into this and noticed that Goland has IDE-level support for this. It requires the use of a comment to specify the embedded type.

{{- /*gotype: package/import/path.type_name*/ -}}.

I can't see a way to support language features without some sort of "type hint" for template files, so maybe this is something to consider making standard.

https://blog.jetbrains.com/go/2018/12/14/go-templates-made-easy/

@inliquid
Copy link

inliquid commented Apr 4, 2021

@a-h it actually works quite nice even without these magic comments. I never used them. It has almost everything you expect when working with html templating languages out of the box.

gopherbot pushed a commit that referenced this issue Apr 19, 2021
Following the discussion on #34652 and the proposal of #36911 (gopls),
this CL adds an option to skip the function declartion check on parsing,
in order to make it possible to parse arbitrary template text files and
get their AST.

Fixed #38627

Change-Id: Id1e0360fc726b49dcdd49716ce25563ebaae6c10
Reviewed-on: https://go-review.googlesource.com/c/go/+/301493
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Trust: Ian Lance Taylor <iant@golang.org>
@harvastum
Copy link

Has there been any discussion what the default template file extensions should be?

I currently see the following suggestions in VS Code:

  • Go Template File - tmpl
  • Golang GO Template - gogo
  • Golang HTML Template - gohtml
  • Golang Java Template - gojava
  • Golang JavaScript Template - gojs
  • Golang JSON Template - gojson
  • Golang PHP Template - gojava
  • Golang Text Template - gotemplate
  • Golang TypeScript Template - gots
  • Golang YAML Template - goyaml

I think this is not the optimal approach. It would be more flexible to use a single extension to indicate that a file is a Go template with a pattern like filename.ext.gotmpl.

AFAIK all template files are text templates for Go with the exception of html. Extension scheme I proposed makes it obvious what the template filename should be and identifies go template files uniquely - .tmpl extension has other uses.

@inliquid
Copy link

inliquid commented Nov 4, 2021

It should be configurable. In most of projects we used *.html for go templates. Once I saw .gohtml. And absolutely never .tmpl.

There actually was an issue where I mentioned these concerns @harvastum. It was quite some time ago, it may also be in old repo (which was owned by Microsoft at the moment).

@eberkund
Copy link

eberkund commented Nov 4, 2021

Has there been any discussion what the default template file extensions should be?

I currently see the following suggestions in VS Code:

* Go Template File - `tmpl`

* Golang GO Template - `gogo`

* Golang HTML Template - `gohtml`

* Golang Java Template - `gojava`

* Golang JavaScript Template - `gojs`

* Golang JSON Template - `gojson`

* Golang PHP Template - `gojava`

* Golang Text Template - `gotemplate`

* Golang TypeScript Template - `gots`

* Golang YAML Template - `goyaml`

I think this is not the optimal approach. It would be more flexible to use a single extension to indicate that a file is a Go template with a pattern like filename.ext.gotmpl.

AFAIK all template files are text templates for Go with the exception of html. Extension scheme I proposed makes it obvious what the template filename should be and identifies go template files uniquely - .tmpl extension has other uses.

I agree this is certainly the most flexible, but can VS Code do something like layered syntax parsing where it is able to work with Go template syntax and YAML at the same time without creating a new language definition?

@harvastum
Copy link

It should be configurable. In most of projects we used *.html for go templates. Once I saw .gohtml. And absolutely never .tmpl.

Yes, it obviously should be configurable. But defaults are powerful. People will use them, they will become convention and at some point, standard. This choice is pretty important.

@findleyr
Copy link
Member

findleyr commented Nov 5, 2021

This has soaked for a while as an experimental feature, and we should make it default.

But it sounds like we should expose some additional configuration before turning it on by default. @pjweinb WDYT?

@pjweinb
Copy link

pjweinb commented Nov 5, 2021 via email

@findleyr
Copy link
Member

findleyr commented Nov 6, 2021

what extra configuration?

Just the file extension(s). Per @inliquid's #36911 (comment):

It should be configurable. In most of projects we used *.html for go templates. Once I saw .gohtml. And absolutely never .tmpl.

FWIW, I've seen all of those, including .tmpl. I think .tmpl or .gohtml is probably fine as a default, but it should be possible for users to configure it for codebases using different file extensions.

I suppose this doesn't need to block templates being enabled by default, since users can always disable if it doesn't work for them.

@pjweinb does that make sense? Any other concerns before moving this out of experimental?

@pjweinb
Copy link

pjweinb commented Nov 6, 2021 via email

@hyangah hyangah removed this from the gopls/unplanned milestone Nov 12, 2021
@hyangah hyangah added this to the gopls/v0.7.4 milestone Nov 12, 2021
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/363360 mentions this issue: gopls: template suffix flags and documentation

@rsc rsc unassigned pjweinb Jun 23, 2022
@golang golang locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FeatureRequest Issues asking for a new feature that does not need a proposal. FrozenDueToAge gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

10 participants