TypeScript object method call psi element not found
Answered
Having simple TypeScript file:
I'm creating reference contributor:
<psi.referenceContributor language="TypeScript" implementation="com.vaadin.plugin.endpoints.VaadinTypeScriptReferenceContributor"/>
As:
internal class VaadinTypeScriptReferenceContributor : PsiReferenceContributor() {
override fun registerReferenceProviders(registrar: PsiReferenceRegistrar) {
registrar.registerReferenceProvider(
PlatformPatterns.psiElement(JSReferenceExpression::class.java),
object : PsiReferenceProvider() {
override fun getReferencesByElement(element: PsiElement, context: ProcessingContext): Array<PsiReference> {
println(element)
println(element.text)
return emptyArray()
}
}
)
}
}
It does find any element. What I'm doing wrong?
After changing pattern to PlatformPatterns.psiElement()
I've got only printed:
JSLiteralExpression
‘asd’
Test project:
IntelliJ IDEA 2023.3 (Ultimate Edition)
Build #IU-233.11799.241, built on December 2, 2023
Runtime version: 17.0.9+7-b1087.7 aarch64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 15.1.1
GC: G1 Young Generation, G1 Old Generation
Memory: 2048M
Cores: 8
Metal Rendering is ON
Registry:
markdown.open.vcs.log.link=true
Non-Bundled Plugins:
com.vaadin.intellij-plugin (1.0-SNAPSHOT)
Kotlin: 233.11799.241-IJ
My development IDE
IntelliJ IDEA 2024.3.1 Preview (Ultimate Edition)
Build #IU-243.22562.13, built on November 20, 2024
Runtime version: 21.0.5+8-b631.19 aarch64 (JCEF 122.1.9)
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Toolkit: sun.lwawt.macosx.LWCToolkit
macOS 15.1.1
Kotlin analyzer version: 2.1.20-ij243-27
GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation
Memory: 8600M
Cores: 8
Metal Rendering is ON
Registry:
debugger.new.tool.window.layout=true
ide.experimental.ui=true
i18n.locale=
Non-Bundled Plugins:
com.vaadin.intellij-plugin (1.0-SNAPSHOT)
org.asciidoctor.intellij.asciidoc (0.43.3)
com.github.copilot (1.5.29.7524)
Kotlin: 243.22562.13-IJ
Please sign in to leave a comment.
Hi Marcin,
JSReferenceExpression
extendsPsiExternalReferenceHost
, which is a part of Symbol API.Please try implementing
com.intellij.model.psi.PsiSymbolReferenceProvider
.Switching to:
and then
Seems to work, now it finds method calls, thank you!
Thanks Karol Lewandowski , I want to implement TypeScript service call reference to annotated Java class. Using above I stuck at:
Whatever I do I end up with:
How to create proper reference?
Hi Marcin,
Please share the full stacktrace.
Made it work in https://intellij-support.jetbrains.com/hc/en-us/community/posts/23602349818514-TypeScript-to-Java-using-symbol-reference-on-JSReferenceExpression-problem