-
Notifications
You must be signed in to change notification settings - Fork 150
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
Discussion about IDE integration #80
Comments
Did you get anywhere with this? One of the things I like about quicktemplate is that you just write Go code, rather than having to have a custom loop syntax etc. I tried out two plugins for vim and VS Code, but they just provide syntax highlighting. On the Go side of things, I'd like autocomplete, error checking, go to definition, automatic package imports etc., and on the HTML side, tag validation, attribute autocomplete etc.
I think your suggestion of building a Language Server to translate requests back to HTML and Go LSPs ( Without the editor support, editing isn't as slick as you'd get in something like JSX in JavaScript. For example, this looks right, but will fail at compile time, because the
Here, I wouldn't get autocomplete on the type Data struct {
A string
B string
}
|
Looking into this a bit further, I think the best approach might be to create an LSP for quicktemplate and to add the required features one-by-one.
While the sourcegraph example is good, it had loads of configuration and so it was a bit complicated: https://github.com/sourcegraph/go-langserver/blob/4b49d01c8a692968252730d45980091dcec7752e/main.go#L173 So, I cut it down to be a minimal example and hooked it up to Neovim with the CoC plugin (https://github.com/neoclide/coc.nvim) for testing. To get Neovim to send commands to my LSP binary, I had to update my CoC config to add in my {
"languageserver": {
"qtpl": {
"command": "/Users/adrian/github.com/a-h/qt-lsp/qt-lsp",
"filetypes": ["qtpl"]
}
} Next, I had to tell Neovim that the file I was working on was a Then, I could read the logs the LSP left behind:
From here, I think I could work out how to add an autocomplete for functions that are in scope, to suggest imports etc., and to enable snippets. |
I got a "Hello World" running in Neovim. It doesn't actually do anything useful, just returns a constant for autocomplete requests. Here's what that looks like: https://asciinema.org/a/D0efR6Inmel9JHEZiqHxbCSuR Here's the demo language server: |
I had a look at implementing the idea in quicktemplate, but the templating language felt a bit too complex to bite off adding the features in one go (things like the spacing operators, support for outputs other than HTML, inclusion of arbitrary files etc.). Also, wasn't sure how the way that the generator emitted code would work, was hoping there would be an object model to parse into, then generate from that. So I took some things that I liked about quicktemplate, and built something that would be easy to add IDE support, and that targets HTML only. I built a parser that parses to an object model, a Go code generator (compiler) that maintains a sourcemap during code generation, and an LSP that is able to proxy to The proxy can present autocomplete suggestions so far, but it's not currently possible to use them because I've only rewritten the LSP requests on the way to https://asciinema.org/a/JEiVL1AJOro2OgXDsBtkX0cCb The syntax highlighting in the demo comes from a vim plugin my friend made. I think the same approach I've used could work for quicktemplate, by maintaining the source map and using an LSP proxy. What do you think @valyala? |
I use quicktemplate because I love the static type checking, and the blazing fast performance is a very pleasant side-effect.
How much work it would be to create a full featured IDE integration (intellij-idea/vscode)
I really miss it, and also make some research how this could work.
The functionality should be:
Beside the separation, I hoped to implement a template plugin which use the inbuilt HTML processor for all the HTML, then define the parts which are go code.
In the background the current file gets compile on every change. The cursor position in the template file is translated to the generated go template file (I saw that all the compiled lines are nicely inlined so there is definitly some information arround ;) or can be extended). The golang language server in queried for the translated cursor position for autocompletion results or whatever. This would work it 90% the time, and that would be great!
Have somebody time to work with me on this in a separate repo or have inputs, docs etc. Then post it here.
The text was updated successfully, but these errors were encountered: