简体   繁体   中英

Go text template syntax highlighting in GoLand

GoLand has syntax support on Go html files with the file extension of .gohtml

So what about Go text files? Does GoLand support that as well? .tmpl is supported by vim-go but not GoLand.

As mkopriva has already hinted and you have described as well in the comments, you can go to Preferences/Editor/File Types and add your custom ending as Registered pattern to the Go Template. But imo the real game changer is that you can also set Go as Template data language there. This way even the Go syntax gets validated, not just the template syntax. It's still wonky, but definitly better than nothing.

在此处输入图片说明

Still, autoformatting does not work properly and can screw up your code. Therefore, you might also want to make sure the Reformat code in the commit dialog is unchecked. Same with Optimize Imports ... better keep it unchecked.

there are two parts to this answer to get both html highlighting and go template highlighting

  1. go template highlighting:

settings > editor > file types > select Go template files from the list > update pattern to the file ending you use for your go templates. I used *.go.html

  1. html highlighting

settings > template data languages > project language (dropdown at the top) > set to html

now you have both html highlighting and go template completion

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM