Skip to content
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

Goland templ plugin crash #1015

Open
davix opened this issue Dec 17, 2024 · 5 comments
Open

Goland templ plugin crash #1015

davix opened this issue Dec 17, 2024 · 5 comments

Comments

@davix
Copy link

davix commented Dec 17, 2024

Sorry I didn't collect all the info requested in the bug report. The ticket can be deleted if it doesn't help resolve the bug.

Before you begin
Please make sure you're using the latest version of the templ CLI (go install github.com/a-h/templ/cmd/templ@latest), and have upgraded your project to use the latest version of the templ runtime (go get -u github.com/a-h/templ@latest)

Describe the bug
A clear and concise description of what the bug is.

Plugin Templ is 0.0.15
Crash happened when I was writing a func in templ file.

java.lang.ArrayIndexOutOfBoundsException: Index -32768 out of bounds for length 40457
	at com.intellij.psi.tree.IElementType.<init>(IElementType.java:116)
	at com.intellij.psi.tree.IElementType.<init>(IElementType.java:93)
	at com.templ.templ.psi.TemplLeafElementType.<init>(TemplLeafElementType.kt:9)
	at com.templ.templ.file.TemplFileViewProvider.<init>(TemplFileViewProvider.kt:22)
	at com.templ.templ.file.TemplFileViewProvider.cloneInner(TemplFileViewProvider.kt:58)
	at com.intellij.psi.MultiplePsiFilesPerDocumentFileViewProvider.createCopy(MultiplePsiFilesPerDocumentFileViewProvider.java:126)
	at com.intellij.psi.MultiplePsiFilesPerDocumentFileViewProvider.createCopy(MultiplePsiFilesPerDocumentFileViewProvider.java:29)
	at com.intellij.psi.impl.BlockSupportImpl.makeFullParse(BlockSupportImpl.java:278)
	at com.intellij.psi.impl.BlockSupportImpl.reparse(BlockSupportImpl.java:91)
	at com.intellij.psi.impl.DocumentCommitThread.doCommit(DocumentCommitThread.java:267)
	at com.intellij.psi.impl.DocumentCommitThread.commitUnderProgress(DocumentCommitThread.java:134)
	at com.intellij.psi.impl.DocumentCommitThread.commitSynchronously(DocumentCommitThread.java:103)
	at com.intellij.psi.impl.PsiDocumentManagerBase.lambda$doCommit$10(PsiDocumentManagerBase.java:531)
	at com.intellij.psi.impl.PsiDocumentManagerBase.executeInsideCommit(PsiDocumentManagerBase.java:546)
	at com.intellij.psi.impl.PsiDocumentManagerBase.doCommit(PsiDocumentManagerBase.java:531)
	at com.intellij.psi.impl.PsiDocumentManagerBase.lambda$doCommit$9(PsiDocumentManagerBase.java:520)
	at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.runWriteAction$lambda$5(AnyThreadWriteThreadingSupport.kt:379)
	at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.runWriteAction(AnyThreadWriteThreadingSupport.kt:389)
	at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.runWriteAction(AnyThreadWriteThreadingSupport.kt:379)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:896)
	at com.intellij.psi.impl.PsiDocumentManagerBase.doCommit(PsiDocumentManagerBase.java:520)
	at com.intellij.psi.impl.PsiDocumentManagerBase.lambda$commitAllDocuments$0(PsiDocumentManagerBase.java:234)
	at com.intellij.openapi.application.WriteIntentReadAction.lambda$run$0(WriteIntentReadAction.java:24)
	at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.runWriteIntentReadAction(AnyThreadWriteThreadingSupport.kt:128)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteIntentReadAction(ApplicationImpl.java:916)
	at com.intellij.openapi.application.WriteIntentReadAction.compute(WriteIntentReadAction.java:55)
	at com.intellij.openapi.application.WriteIntentReadAction.run(WriteIntentReadAction.java:23)
	at com.intellij.psi.impl.PsiDocumentManagerBase.commitAllDocuments(PsiDocumentManagerBase.java:220)
	at com.intellij.codeInsight.lookup.impl.LookupImpl.fireItemSelected(LookupImpl.java:1028)
	at com.intellij.codeInsight.lookup.impl.LookupImpl.finishLookupInWritableFile(LookupImpl.java:636)
	at com.intellij.codeInsight.lookup.impl.LookupImpl.lambda$finishLookup$4(LookupImpl.java:592)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:217)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:178)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:168)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:154)
	at com.intellij.codeInsight.lookup.impl.LookupImpl.finishLookup(LookupImpl.java:590)
	at com.intellij.codeInsight.lookup.impl.LookupImpl.finishLookup(LookupImpl.java:575)
	at com.intellij.codeInsight.lookup.impl.actions.ChooseItemAction$Handler.doExecute(ChooseItemAction.java:57)
	at com.intellij.openapi.editor.actionSystem.DynamicEditorActionHandler.doExecute(DynamicEditorActionHandler.java:63)
	at com.intellij.openapi.editor.actionSystem.EditorActionHandler.lambda$execute$4(EditorActionHandler.java:211)
	at com.intellij.openapi.editor.actionSystem.EditorActionHandler.doIfEnabled(EditorActionHandler.java:95)
	at com.intellij.openapi.editor.actionSystem.EditorActionHandler.execute(EditorActionHandler.java:210)
	at com.intellij.openapi.editor.actionSystem.EditorAction.executeHandler(EditorAction.java:120)
	at com.intellij.openapi.editor.actionSystem.EditorAction.lambda$actionPerformed$0(EditorAction.java:107)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:226)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:178)
	at com.intellij.openapi.editor.actionSystem.EditorAction.actionPerformed(EditorAction.java:106)
	at com.intellij.openapi.editor.actionSystem.EditorAction.actionPerformed(EditorAction.java:83)
	at com.intellij.openapi.actionSystem.ex.ActionUtil.doPerformActionOrShowPopup(ActionUtil.kt:374)
	at com.intellij.openapi.keymap.impl.ActionProcessor.performAction(ActionProcessor.java:32)
	at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher$actionProcessor$1.performAction(IdeKeyEventDispatcher.kt:499)
	at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcherKt.doPerformActionInner$lambda$8$lambda$7(IdeKeyEventDispatcher.kt:850)
	at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:109)
	at com.intellij.openapi.application.TransactionGuardImpl.performUserActivity(TransactionGuardImpl.java:98)
	at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcherKt.doPerformActionInner$lambda$8(IdeKeyEventDispatcher.kt:850)
	at com.intellij.openapi.actionSystem.impl.ActionManagerImpl.performWithActionCallbacks(ActionManagerImpl.kt:1173)
	at com.intellij.openapi.actionSystem.ex.ActionUtil.performDumbAwareWithCallbacks(ActionUtil.kt:396)
	at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcherKt.doPerformActionInner(IdeKeyEventDispatcher.kt:848)
	at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcherKt.access$doPerformActionInner(IdeKeyEventDispatcher.kt:1)
	at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.kt:577)
	at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processAction(IdeKeyEventDispatcher.kt:512)
	at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.processActionOrWaitSecondStroke(IdeKeyEventDispatcher.kt:451)
	at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.inInitState(IdeKeyEventDispatcher.kt:444)
	at com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher.dispatchKeyEvent(IdeKeyEventDispatcher.kt:306)
	at com.intellij.ide.IdeEventQueue.dispatchKeyEvent(IdeEventQueue.kt:606)
	at com.intellij.ide.IdeEventQueue._dispatchEvent$lambda$22(IdeEventQueue.kt:565)
	at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.runWriteIntentReadAction(AnyThreadWriteThreadingSupport.kt:128)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.kt:565)
	at com.intellij.ide.IdeEventQueue.dispatchEvent$lambda$18$lambda$17$lambda$16$lambda$15(IdeEventQueue.kt:355)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:857)
	at com.intellij.ide.IdeEventQueue.dispatchEvent$lambda$18$lambda$17$lambda$16(IdeEventQueue.kt:354)
	at com.intellij.ide.IdeEventQueueKt.performActivity$lambda$2$lambda$1(IdeEventQueue.kt:1045)
	at com.intellij.openapi.application.WriteIntentReadAction.lambda$run$0(WriteIntentReadAction.java:24)
	at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.runWriteIntentReadAction(AnyThreadWriteThreadingSupport.kt:128)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteIntentReadAction(ApplicationImpl.java:916)
	at com.intellij.openapi.application.WriteIntentReadAction.compute(WriteIntentReadAction.java:55)
	at com.intellij.openapi.application.WriteIntentReadAction.run(WriteIntentReadAction.java:23)
	at com.intellij.ide.IdeEventQueueKt.performActivity$lambda$2(IdeEventQueue.kt:1045)
	at com.intellij.ide.IdeEventQueueKt.performActivity$lambda$3(IdeEventQueue.kt:1054)
	at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:117)
	at com.intellij.ide.IdeEventQueueKt.performActivity(IdeEventQueue.kt:1054)
	at com.intellij.ide.IdeEventQueue.dispatchEvent$lambda$18(IdeEventQueue.kt:349)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.kt:395)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)

To Reproduce
A small, self-container, complete reproduction, uploaded to a Github repo, containing the minimum amount of files required to reproduce the behaviour, along with a list of commands that need to be run. Keep it simple.

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots or screen captures to help explain your problem.

Logs
If the issue is related to IDE support, run through the LSP troubleshooting section at https://templ.guide/commands-and-tools/ide-support/#troubleshooting-1 and include logs from templ

templ info output
Run templ info and include the output.

Desktop (please complete the following information):

  • OS: [e.g. MacOS, Linux, Windows, WSL]
  • templ CLI version (templ version)
  • Go version (go version)
  • gopls version (gopls version)

Additional context
Add any other context about the problem here.

@epicbytes
Copy link

This is the most annoying issue. I've been struggling with it since the very beginning when the templ plugin appeared, regardless of the Goland or templ version.

At some point, Goland's control crashes, and all unsaved files are lost into oblivion. This isn't exclusive to Goland — VSCode and Zed behave similarly, though instead of freezing, they stop launching the language server and lose autocomplete. I have a feeling the problem isn't in the environment but lies somewhere within templ itself.

@a-h
Copy link
Owner

a-h commented Jan 26, 2025

Do you have a solid reproduction of the issue, or any logs that might point to the cause?

There's a log option that writes log entries to disk, and a verbose option to increase log verbosity.

Usual causes of unresponsive programs are deadlocks, memory leaks, infinite loops, bad regexp, running out of handles etc. Adding a profile endpoint could help in those cases.

@epicbytes
Copy link

In general, there is nothing particularly special in the usage cases. The only thing I do not run is the --watch mode because I build a binary, and my build system handles this; it simply runs a command before building the binary.

At some random point during project work, an error occurs in Goland (in this context), and it stops responding to input, with the interface freezing. Neither local file history nor copying is available, and I lose what I have written.

In other editors, the ability to highlight *.templ files simply disappears.

The error points to a problem with the plugin, but I feel that the issue might be with gopls, or with configuring templ to work with it, because there are many releases of gopls.

@a-h
Copy link
Owner

a-h commented Jan 30, 2025

In the upcoming release, I've switched out the logging library and JSON marshalling library to use stdlib (slog instead of zap and stdlib json instead).

I've also vendored the LSP code so we can make changes freely.

However these are unlikely to be major changes in stability.

We could have issues between data structure shapes not being properly marshalled / unmarshalled, but without logs it's hard to say what the issue could be.

@a-h
Copy link
Owner

a-h commented Jan 30, 2025

Here's the docs on how to enable logging: https://templ.guide/developer-tools/ide-support#enable-lsp-logging

Note that you can enable gopls and templ logs.

It's quite a lot of data, so it can be hard to see what's going on. I like to try and work out if there's a specific command related to it hanging.

I was thinking about updating the templ LSP web server to include a nicer way to look at / filter recent logs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants