templ-go / templ-jetbrains

Intellij language support for templ
MIT License
71 stars 11 forks source link

templ server will not start in Jetbrains Language Services #40

Closed jaredweinfurtner closed 1 month ago

jaredweinfurtner commented 1 month ago

Hello,

In Jetbrains 2024.2.3 using Templ plugin version 0.0.14, my templ server will not start and receives the following error everytime:

java.lang.Throwable: Too many element types registered. Out of (short) range. Most of element types (4751) were registered for 'Language: templ': TemplElementType.COMPONENT, TemplElementType.COMPONENT_CHILDREN, TemplElementType.COMPONENT_PARAMS, TemplElementType.COMPONENT_STRUCT_LITERAL, TemplElementType.CSS_DECL, TemplElementType.ELSE, TemplElementType.ELSE_IF, TemplElementType.EXPR, TemplElementType.FOR_LOOP, TemplElementType.GO_ROOT, Templ...
    at com.intellij.openapi.diagnostic.Logger.error(Logger.java:376)
    at com.intellij.psi.tree.IElementType.<init>(IElementType.java:115)
    at com.intellij.psi.tree.IElementType.<init>(IElementType.java:92)
    at com.intellij.psi.tree.ILazyParseableElementType.<init>(ILazyParseableElementType.java:30)
    at com.intellij.psi.tree.IFileElementType.<init>(IFileElementType.java:20)
    at com.intellij.psi.templateLanguages.TemplateDataElementType.<init>(TemplateDataElementType.java:51)
    at com.templ.templ.file.TemplFileViewProvider$htmlElementType$1.<init>(TemplFileViewProvider.kt:22)
    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:265)
    at com.intellij.psi.impl.DocumentCommitThread.commitUnderProgress(DocumentCommitThread.java:130)
    at com.intellij.psi.impl.DocumentCommitThread.lambda$commitAsynchronously$0(DocumentCommitThread.java:81)
    at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$OTelMonitor.callWrapped(NonBlockingReadActionImpl.java:840)
    at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$OTelMonitor$MonitoredComputation.call(NonBlockingReadActionImpl.java:872)
    at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.insideReadAction(NonBlockingReadActionImpl.java:604)
    at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.lambda$attemptComputation$4(NonBlockingReadActionImpl.java:567)
    at com.intellij.openapi.application.impl.AnyThreadWriteThreadingSupport.tryRunReadAction(AnyThreadWriteThreadingSupport.kt:291)
    at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:965)
    at com.intellij.openapi.progress.util.ProgressIndicatorUtils.lambda$runInReadActionWithWriteActionPriority$0(ProgressIndicatorUtils.java:93)
    at com.intellij.openapi.progress.util.ProgressIndicatorUtilService.runActionAndCancelBeforeWrite(ProgressIndicatorUtilService.java:66)
    at com.intellij.openapi.progress.util.ProgressIndicatorUtils.runActionAndCancelBeforeWrite(ProgressIndicatorUtils.java:155)
    at com.intellij.openapi.progress.util.ProgressIndicatorUtils.lambda$runWithWriteActionPriority$1(ProgressIndicatorUtils.java:138)
    at com.intellij.openapi.progress.ProgressManager.lambda$runProcess$0(ProgressManager.java:98)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:217)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$13(CoreProgressManager.java:660)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:735)
    at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:691)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:659)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:79)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:202)
    at com.intellij.openapi.progress.ProgressManager.runProcess(ProgressManager.java:98)
    at com.intellij.openapi.progress.util.ProgressIndicatorUtils.runWithWriteActionPriority(ProgressIndicatorUtils.java:135)
    at com.intellij.openapi.progress.util.ProgressIndicatorUtils.runInReadActionWithWriteActionPriority(ProgressIndicatorUtils.java:93)
    at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.attemptComputation(NonBlockingReadActionImpl.java:567)
    at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.lambda$transferToBgThread$1(NonBlockingReadActionImpl.java:466)
    at com.intellij.openapi.application.impl.NonBlockingReadActionImpl$Submission.lambda$transferToBgThread$2(NonBlockingReadActionImpl.java:481)
    at com.intellij.util.concurrency.BoundedTaskExecutor.doRun(BoundedTaskExecutor.java:249)
    at com.intellij.util.concurrency.BoundedTaskExecutor.access$200(BoundedTaskExecutor.java:30)
    at com.intellij.util.concurrency.BoundedTaskExecutor$1.executeFirstTaskAndHelpQueue(BoundedTaskExecutor.java:227)
    at com.intellij.util.ConcurrencyUtil.runUnderThreadName(ConcurrencyUtil.java:218)
    at com.intellij.util.concurrency.BoundedTaskExecutor$1.run(BoundedTaskExecutor.java:212)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:735)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:732)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:400)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:732)
    at java.base/java.lang.Thread.run(Thread.java:1583)

I appreciate any help or guidance in solving this issue.

jaredweinfurtner commented 1 month ago

I was able to resolve the issue and will document it for others:

quick fix:

go install golang.org/x/tools/gopls@latest

details:

The templ server error output was:

StdIO connection closed
Exit code: 1
Command line: /Users/xxx/go/bin/templ lsp

when getting the logs of templ lsp, I see:

{"level":"info","ts":"2024-10-16T10:45:32+02:00","caller":"lspcmd/main.go:76","msg":"lsp: starting up..."}
{"level":"info","ts":"2024-10-16T10:45:32+02:00","caller":"lspcmd/main.go:83","msg":"lsp: starting gopls..."}
{"level":"error","ts":"2024-10-16T10:45:32+02:00","caller":"lspcmd/main.go:89","msg":"failed to start gopls","error":"cannot find gopls on the path (\"/usr/local/go/bin:/..."}
joerdav commented 1 month ago

Thanks for updating! This should also be made easier when #39 is complete, it should find the go version that's used by goland.