valyala / quicktemplate

Fast, powerful, yet easy to use template engine for Go. Optimized for speed, zero memory allocations in hot paths. Up to 20x faster than html/template
MIT License
3.12k stars 150 forks source link

Syntax Highlighting? #19

Open escholtz opened 8 years ago

escholtz commented 8 years ago

Do you know if anyone has started adding syntax highlighting support for various text editors? My personal interest is for Sublime Text.

escholtz commented 8 years ago

Here is a syntax file I came up with for ST3. Requires GoSublime.

%YAML 1.2
---
# http://www.sublimetext.com/docs/3/syntax.html
name: "QuickTemplate"
file_extensions:
  - qtpl
scope: source.qtpl
contexts:
  main:
    - include: scope:text.html.basic
    - match: "{%"
      push: "Packages/GoSublime/syntax/GoSublime-Go.tmLanguage"
      with_prototype:
        - match: "(?=%})"
          pop: true
        - match: "(code|space|elseif|endif|endfor|endfunc|comment|endcomment|plain|endplain|stripspace|endstripspace|collapsespace|endcollapsespace|endswitch)"
          scope: "keyword.other.go"

I'm a Sublime syntax newbie so probably lots of improvements to be made but the basics seem to work (highlighting html, go, and quicktemplate keywords all in the same file).

valyala commented 8 years ago

@escholtz , thanks for the contribution! Just added a link to this issue from the FAQ in the README.md

tobstarr commented 8 years ago

How about something for vim?

valyala commented 8 years ago

@tobstarr , I'm not familiar with vim syntax highlighting, so contributions are welcome :)

valyala commented 8 years ago

btw, I use vim, so will be very glad if qtpl syntax highlighting for vim is implemented.

warbear0129 commented 7 years ago

@valyala hi i like quicktemplate so much i made a simple syntax highlighter for vim. https://github.com/warbear0129/vim-qtpl

codelitt commented 7 years ago

@valyala, @warbear0129's package wasn't working for me and a couple other people. I've submitted a PR that should get it working for most vim runtimes. Also now it works with Vundle and Pathogen.

Thanks to warbear for the syntax file. It just needed some tweaks. If anyone is having issues they can take a look at my fork (if the PR below is not merged)

https://github.com/warbear0129/vim-qtpl/pull/2

codelitt commented 7 years ago

@valyala Actually a quick update. The other vim-qtpl package was pretty bare on features and html syntax support. I found it better to take the well written and supported vim-go plugin and add support quicktemplate syntax. I've been testing it out and this is a much better approach.

The PR I submitted to vim-go is here: https://github.com/fatih/vim-go/pull/1241

My fork here (until @fatih) merges it in: https://github.com/codelitt/vim-go

Hopefully this is much more helpful.

tobstarr commented 7 years ago

@codelitt that looks pretty cool!

codelitt commented 7 years ago

@tobstarr Thanks! I've been testing it out and it's working very well. Plus it brings all of the awesome things from vim-go to these filetypes (like go fmt)

valyala commented 7 years ago

Re-opened the issue in order to make it more prominent (and it is incomplete yet).

codelitt commented 7 years ago

@valyala My fork of vim-go provides this very completely: https://github.com/codelitt/vim-go

~Unfortunately though~, it was not accepted into the main vim-go repo as a PR as the maintainer doesn't ~want to bother with it~ feel like it's a good fit for vim-go and needs to be a separate plugin. ~I'm not sure if anyone has any other ideas.~

fatih commented 7 years ago

Unfortunately though, it was not accepted into the main vim-go repo as a PR as the maintainer doesn't want to bother with it.

I've suggested to you that you can provide it as a separate plugin. You didn't and then say you forked vim-go (which I think is unreliable as well, but that's not my business)

I have limited time,a family, work to do, and many other things. I can't just merge every single feature out there in the universe. it's 5-10 lines. Just create a vim-quicktemplate plugin and there you go. Anyone who uses vim-go can use that as well. It's not hard to create such a plugin. Hope you understand this.

codelitt commented 7 years ago

@fatih Perhaps that was poorly worded. I meant unfortunate in the sense of "Now we'll have to sort out something else" and not as a criticism of you. I agree it's a poor choice to try to maintain a separate fork, it's just what I've been doing until I have more time. I completely understand your position as a maintainer and understand you don't feel like this is a good fit for vim-go. Apologies if my original comment made that seem otherwise.

I just went back and re-read the comments on the PR. I'm not sure what it takes to make a plugin that integrates with another plugin like vim-go as I'm not overly familiar with vim plugins, but I'll take a look over the next week or so.

fatih commented 7 years ago

@codelitt no worries. I apologize if my words were harsh as well. Didn't meant it. Thanks for your understanding.

codelitt commented 7 years ago

@fatih No worries on my end either. I'd welcome any docs about creating a plugin which integrates with/relies on another plugin (in this case vim-go)

TuralAsgar commented 7 years ago

Is there any syntax highlighter for Intellij based IDEs?

nezorflame commented 7 years ago

Would love to see someone do the VSCode extension.

atomi commented 7 years ago

I missed this thread when I opened an issue earlier, but here is basic syntax highlighting for vs code:

https://marketplace.visualstudio.com/items?itemName=vsatomi.vscode-quicktemplate

stereosteve commented 6 years ago

@tural-esger for IntelliJ GoLand I created this issue, which you can upvote: https://youtrack.jetbrains.com/issue/GO-4810

encku commented 6 years ago

@stereosteve Can we create our syntax highlighting with this jetbrains create filetype ?

b0o commented 6 years ago

Better vim support would be great. The warbear0129/vim-qtpl plugin sorta works, but breaks as soon as I edit the file. It also doesn't have embedded HTML support which is a big letdown.

b0o commented 6 years ago

I've begun working on my own Vim Quicktemplate syntax plugin: b0o/quicktemplate.vim.

I'm a complete noob when it comes to creating syntax rules for Vim, and the Quicktemplate grammar is rather complex when you take into account the fact that it essentially has 2+ other languages embedded within it (go, html, [js, css]).

It took me quite a while to get anything working at all, but I think at this point my version offers a bit more room for improvement than warbear0129/vim-qtpl. My main issue with vim-qtpl was that it's a 'dumb' syntax highlighting plugin - it doesn't attempt to utilize the existing syntax definitions for Go and HTML, so there's only so much it can do.

I would welcome contributions from anyone who is better with VimL or Vim syntax parsing than me, but I'll be attempting to make this plugin semi-complete over the next few weeks.

2018-01-14-20-41-28


Update 02-11-2018:

I've been working on this plugin quite a bit, and it's now to the point where most things work quite well. Here's an updated screenshot:

Screenshot

frederikhors commented 5 years ago

Any news for VSCode or Goland?

m00nyONE commented 5 years ago

Any news for VSCode or Goland?

Yes. take a look inside the README.md file

Is there a syntax highlighting for qtpl files?

Yes - see this issue for details. If you are using JetBrains products (syntax highlighting and autocomplete):

cd JetBrains settings directory
mkdir -p filetypes && cd filetypes
curl https://raw.githubusercontent.com/valyala/quicktemplate/master/QuickTemplate.xml >> QuickTemplate.xml
Restart your IDE

But i have to say it is not very good and no it does not have the type of autocompletion you may expect. its ... lets say .... simple

SharanSharathi commented 2 years ago

Hello @escholtz, @valyala, I've added a package in packagecontrol.io for SublimeText - Quick​Template (Go) It supports syntax highlighting, code completion, and a build system to run qtc with a keyboard shortcut.

please give it a try, and share your feedback. we can add about this package in README.md - https://github.com/valyala/quicktemplate#faq