microsoft / vscode-go

An extension for VS Code which provides support for the Go language. We have moved to https://github.com/golang/vscode-go
Other
5.93k stars 648 forks source link

"text/template" & "html/template" support #228

Closed gobijan closed 4 years ago

gobijan commented 8 years ago

Vscode-go is a really nice IDE for working with Go. Great job!

I would be super happy if vscode would support "text/template" & "html/template" as an edit mode for template editing. Is this feature planned?

Kind regards Bijan

lukehoban commented 8 years ago

Good idea - not planned yet - but should be something we can add.

gobijan commented 8 years ago

Any status update on this? Here someone tried to implement it but failed: https://marketplace.visualstudio.com/items?itemName=casualjim.gotemplate

GoSublime for Sublime Text has this kind of template support: https://github.com/DisposaBoy/GoSublime

Maybe you could get some inspiration from these on how to do it in your extension?

nullbio commented 8 years ago

I'd love to see this feature. Would be even better if it did merged syntax highlighting, i.e. if you had file.go.tmpl it did both template line highlighting AND Go syntax highlighting. This would be very useful for generation apps like https://github.com/vattle/sqlboiler -- example of some templates: https://github.com/vattle/sqlboiler/tree/master/templates -- note these are currently just using .tpl because no other editors seem to support merged syntax highlighting yet unfortunately.

depado commented 7 years ago

I'd love to see this feature too.

ramya-rao-a commented 7 years ago

This feature request has gotten quite a few up votes. Can someone provide a gif or a video of what is the expected behavior? I can then look into what is needed to get this implemented.

gertcuykens commented 7 years ago

image

renamed to .html image

So in short use the vscode html engine and just add parameters like, hey html engine all that non html stuff like {{...}} don't worry about that, here are the syntax and autocomplete rules for it.

You have to think the other way around. Extend your html api so the go plugin can just push in a chunk of html code and return the same output as shown in the screenshot + some extra syntax highlighting provided by the plugin as extra html parameter so the html engine can learn what all that non html stuff means.

depado commented 7 years ago

That's quite the same as the Jinja support actually. That would be so cool 👍

andreis commented 6 years ago

Working with xo and editing a lot of .tpl.go files, I'd absolutely love this feature!

kmanley commented 6 years ago

Would be handy for ego templates too

oneslash commented 5 years ago

I am taking this

oneslash commented 5 years ago

Hey guys, I am not sure how to implement it correctly.

Problem

I need to implement support of go templates inside ``. It is possible to do, however the upstream for vscode golang syntax support is in https://github.com/atom/language-go. I would need to make a change request first to the upstream repo and then pull it downstream into vscode (not to this project).

The atoms languge-go has three modes for golang:

The reason I am stuck is, what should I do, there are several options which comes first to my head:

I would be happy to hear your suggestions.

Screenshots

Screenshot 1

screenshot 2018-12-05 at 07 24 53

Screenshot 2

screenshot 2018-12-05 at 07 27 38
oneslash commented 5 years ago

@ramya-rao-a, what do you think would be better?

gertcuykens commented 5 years ago

Personnaly I would try upstream first and create a reference link to it here to avoid code fragmentation. I assume you build it trying minImal code change? That said if upstream fails I would maybe reinvent the wheel here. I dont really know how everthing is tied togther but it sounds that current design is a bit hacky? Maybe we need more core features first from the vscode api itself?

ramya-rao-a commented 5 years ago

@oneslash From what I understood by your comment, the HTML (Go) (file: gohtml.cson) in the https://github.com/atom/language-go already supports what we want here.

The question then is whether we update our current Go grammar (which is upstream in VS Code repo) to use this or have a separate language mode that uses this grammar.

Did I get that right?

@gertcuykens What core features are you referring to in the vscode api?

gertcuykens commented 5 years ago

How do other languages do it? For example does vscode-php use https://github.com/atom/language-php? Is current vscode core template design consistent with other languages? Or does each language plugin has there own way of template support? For me it makes sense to make sure a template system is done the way all other language plugins are doing it. If my go file contains html php or c code I can recycle other plugins work to highlight that part. Now we are fixing just go templates but then there is cgo where you have a mix of c code https://golang.org/cmd/cgo/ in the end if we don't look how other languages are doing it then vscode-go will be more lines of code then vscode itself :)

gertcuykens commented 5 years ago

@oneslash not sure if this can be done I am just trying to come up with ideas. What if you made 2 separate plugins also completely separate from vscode-go. One for *.html.go files and one for*.txt.go files? I make the assumption that multiple plugins can be activated for the same file. If not then we definitely need to create a ticket for vscode to just do that. Can you imagine where every plugin needs to reinvent let say a spell checker, that just unacceptable. Let me know if it makes sense

oneslash commented 5 years ago

@ramya-rao-a, yes you got it correct.

@gertcuykens, the thing is, from what I understood, for PHP there are two modes, text.html.php and source.php. text.html.php - includes source.php inside, and it detects if it can use php syntax by <?php or <?. Go is a bit different, `` inside can be anything, not just HTML or Go templates.

gertcuykens commented 5 years ago

And can we make a distinction based on file extention that dictates what to expect inside `...` like if file extention is *.html.go use html mode + template mode ? If not step one open feature request in vscode :)

oneslash commented 5 years ago

@gertcuykens yes we can, and I can do it then if it is a common practice to name files. I usually develop services which are not exposed to a user so I am cannot decide.

ramya-rao-a commented 5 years ago

Or does each language plugin has there own way of template support?

Thats how it is today.

I make the assumption that multiple plugins can be activated for the same file.

Yes that is true

And can we make a distinction based on file extention that dictates what to expect inside ... like if file extention is *.html.go use html mode + template mode

Yes

gertcuykens commented 5 years ago

Ok then I suggest to do each language template syntax in a separate plugin: .hml.go, .txt.go, … other people can then easily add more template plugins like c etc without submitting a vscode-go pull request. Now wat all does plugins do have in common is the go template autocomplete part {{ if else .something }} That going to be the hart part and needs to be in vscode-go. For example when I push . I would like to see a list of available variables in the template

ramya-rao-a commented 4 years ago

Hello all,

As mentioned in https://github.com/microsoft/vscode-go/issues/464#issuecomment-580093228, the syntax highlighting request for html template code in Go files is out of scope for this extension.

@stamblerre, Would gopls consider adding some kind of embedded language feature support for the Go code in the template?

stamblerre commented 4 years ago

Yes absolutely, though it won't be for quite some time, as it's fairly low priority. Filed golang/go#36911 to track it.

ramya-rao-a commented 4 years ago

Thanks @stamblerre!

Everyone else, Closing this issue in favor of the upstream issue logged for gopls in https://github.com/golang/go/issues/36911

Once this feature is implemented upstream, language server users in VS Code will be able to use the Go language features inside html template code.

inliquid commented 4 years ago

What does it mean? gopls will implement syntax highlighting? Or will make Vs Code support autocompletion in *.html go templates along with html language features?

/cc @ramya-rao-a /cc @stamblerre

stamblerre commented 4 years ago

What does it mean? gopls will implement syntax highlighting?

Syntax highlighting is not in the LSP, and is usually implemented in a grammar used by VS Code directly. I am not sure where exactly this would fit, but it may be worth filing a feature request with https://github.com/microsoft/vscode.

Or will make Vs Code support autocompletion in *.html go templates along with html language features?

This is what golang/go#36911 is tracking. I don't expect it to be implemented for a while, but we may prioritize it after gopls reaches v1.0.0.

inliquid commented 4 years ago

I am not sure where exactly this would fit, but it may be worth filing a feature request with https://github.com/microsoft/vscode.

I think it is a responsibility of vscode-go extension, particularly this exact issue has already got all requirements and inputs. And was closed. I can't understand why it's been all thrown to gopls side.

stamblerre commented 4 years ago

To be clear, syntax highlighting is typically not the job of a VS Code extension (for example, here is the syntax for Go). I agree with Ramya that it doesn't make sense to have the syntaxes live in different repositories. The only language that this extension has added support for is go.mod files, which are significantly simpler.

With respect to language features, it is much easier to support autocompletion, definition, etc. through gopls than it is to add it to this extension. This extension relies mostly on command-line tools to provide features, and it seems like a tool does not exist to satisfy this use case.

inliquid commented 4 years ago

Ok, let me ask again, will we have syntax highlighting with language features on *.html template files after it's implemented on gopls side, no? I expect both html/css and go templates to be working, otherwise it will all have close to zero sense.

stamblerre commented 4 years ago

No, gopls will not implement syntax highlighting, as that is not part of the language server protocol.

hyangah commented 4 years ago

I think for syntax highlighting, it's better to start discussion in https://github.com/jeff-hykin/better-go-syntax (upstream of Go syntax highlighting VS Code uses) and check if changes to use https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide#embedded-languages make sense.

inliquid commented 4 years ago

Will I need to switch *.html file language to go or smth like gotemplate for gopls to work on it?

stamblerre commented 4 years ago

When features are implemented in gopls, we will make the necessary changes in the extension so that gopls works automatically, as one would expect. As of right now, this feature is not prioritized for gopls/v1.0.0, so I would not expect any progress on it for the near future.

inliquid commented 4 years ago

I see. Thank you for clarification.