-
Notifications
You must be signed in to change notification settings - Fork 11
Make parsing a whole lot better #31
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
base: main
Are you sure you want to change the base?
Conversation
…inds of stuff). Just need to figure out whitespace so that things get passed sanely.
…h to avoid basic issues.
…few new testcases (and some way to check the other PSIs)
|
Thanks! I'll take a look. I'm also not very practiced in Kotlin/Java so this repo probably isn't a shining light of code quality anyway lol! If @myrjola has time to review you might get some better feedback but I'll see what I can do! |
|
This looks good, seems that the main feature is implementing the new rawgo feature. I'll do some manual testing then merge. |
|
Don't merge just yet, this isn't quite done (tho I will try and wrap it up later today). I just needed a second pair of eyes to review. |
|
Additionally, it seems I maybe should have a look at https://plugins.jetbrains.com/docs/intellij/implementing-lexer.html#embedded-language. It probably would cover at least some of the crazy tricks I'm pulling. |
|
Okay, this is at a point where I need more eyes on it. I need some help figuring out how to add tests for the GO and HTML PSI files. I need people to find where this breaks, I don't use templ enough to really find that (I used it a drop recently and the experience was poor enough that I'm working on this now). |
|
There are still a bunch of certain errors from Go Inspections, if anyone has any idea how to appease those, please lmk. |
|
@chabad360 can you compile a "latest" version and upload the zip? Here myrjola did the same so we could test his version. |
|
Templ-0.0.14.zip Here you go |
|
@bastianwegge I just realized I uploaded an old version, here's the correct one: |
|
/e: Will probably come back later and try again 👍 Here's the first badge of feedback, I'll come back later with more as I'm on the train and have to leave now 😅 . All regarding the version you posted 1 hour ago.
|
…ocks to fix the brace tracking problem
|
@bastianwegge fixed that issue.
Thanks. I'm actually not entirely sure why highlighting doesn't work in more areas, trying to figure it out. |
|
Great progress! Thanks for taking a stab at this ❤️ I didn't know it was possible to add support for multiple languages through the How did you come up with this approach? Are there any existing plugins you're taking inspiration from? They might be helpful in figuring out the missing parts. A testing tip that was helpful for me was to try the plugin against all the templ files in the Templ repository. There's many examples inside the generator directory. Here's some issues I encountered besides the ones reported above. I'm afraid I won't have time to dive into the rabbit hole to understand the issues better but I hope they can be fixed before merging these changes. Multiple notNullChild crashes in Go pluginI'm getting crashes any time there's string expressions in the templ component. I believe this is caused by the Go parser's PSI tree not populating identifiers for the string expressions. I can see that we're prepending Notice that the VAR_DEFINITION is empty in the PSI Viewer
But not when I write a similar statement in the raw Go code outside templ components.
I don't know what's causing this. I tried working around it by creating a Go statement by wrapping the string expression with Could be interesting to see if it behaves the same with MultiHostInjector. Do you encounter this Autoimport corrupts the fileWhen I autocomplete new libraries to a Templ file like this:
The package and import statements sometime become corrupted
I'm suspecting this is caused by adding the |
Brute force.
This is a good idea. Honestly tho, it would be a lot more useful if I had some sort of tooling that could show me what's being sent to the Go PSI and HTML PSI and show me errors that it throws (rn I need to set some specific breakpoints and have only one file open when I start the debug session, it's annoying).
Ah yes, that's been bugging me and I haven't bothered enough yet to pursue it, so thanks for tracking it down.
Hmm, this approach certainly seems like it might be a bit saner than the way I'm doing things currently, although, I'm not entirely certain it can actually do everything I need it to...
I was worried about that. I can probably make a quick fix that prevents the corruption (change the lexer to include the new line), but this would still be an issue. It's probably possible to disable Go plugin auto-imports, but I'll need to do some digging to figure it out. |
I think I have fixed the bugs here.
Hrm, I only specifically blocked EDIT: Figured out the specific issue you ran into, and blocked Go from seeing varidics in general.
I'm not able to test that I actually fixed this atm, but if you can give it a try on your end and let me know if it's corrupting the file that would be great. |
|
Fixed a regression. |
|
Is there a roadmap/plan for releasing this as a new version? |
|
@up1io I think that's up to the maintainers ultimately. But I would like to finish this up. I got a bit busy with work and some other stuff recently. But I will get some more stuff done here between this week and next week. |
|
Okay, thanks @chabad360 for the update and thanks x10 for your efforts. Your latest build is a real improvement for me. |
So I did try, however, I'm running against the limits of my java knowledge, and tbh, I'm not quite sure how to fix this as the code examples they give don't give any hints ( package com.templ.templ.injector;
import com.goide.GoLanguage;
import com.intellij.lang.injection.MultiHostInjector;
import com.intellij.lang.injection.MultiHostRegistrar;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiLanguageInjectionHost;
import com.templ.templ.psi.TemplExpr;
import com.templ.templ.psi.TemplTypes;
import org.jetbrains.annotations.NotNull;
import java.util.List;
final class GolangToTemplInjector implements MultiHostInjector {
@Override
public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement context) {
if (context instanceof TemplExpr) {
registrar.startInjecting(GoLanguage.INSTANCE);
registrar.addPlace("var _ string =", ";", (PsiLanguageInjectionHost)context, getBodyRange(context));
registrar.doneInjecting();
}
}
private TextRange getBodyRange(@NotNull PsiElement context) {
return context.getChildren()[1].getTextRange();
}
@Override
public @NotNull List<? extends Class<? extends PsiElement>> elementsToInjectIn() {
return List.of(TemplExpr.class);
}
}Results in a very long exception that starts: I think I'm going to assume there's a bug somewhere in-between the Go Parser and the template injector. I'm gonna see if I can track it down (but honestly it's a bit hard to figure out where exactly it gets passed to the Go parser) and file a bug/figure out a workaround. |
|
@chabad360 any news ? :) |
|
Ha! No. I'm travelling at the moment, but when I'm back home I'm gonna try again against the latest intellij, and if the bug is still present I'm just gonna write up a bug report (which I should have done months ago). |
|
Any news on this? |
|
Hello! Any updates? |













This PR allows for a bunch of errors to be detected by the built-in Go inspections, and by proxy, it adds support for highlighting as well as some other stuff. It's not perfect by any means (in fact, there are a number of glaring issues), but this is what happened when I went down the rabbit hole that started with #30.
Effectively fixes #26