-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into chore/analytics
- Loading branch information
Showing
7 changed files
with
147 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.vaadin.plugin.symbols | ||
|
||
import com.intellij.model.Pointer | ||
import com.intellij.model.Symbol | ||
import com.intellij.navigation.NavigatableSymbol | ||
import com.intellij.navigation.SymbolNavigationService | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.platform.backend.navigation.NavigationTarget | ||
import com.intellij.psi.PsiElement | ||
|
||
class HillaSymbol(private val target: PsiElement) : NavigatableSymbol { | ||
|
||
override fun createPointer(): Pointer<out Symbol> { | ||
return Pointer.hardPointer(this) | ||
} | ||
|
||
override fun getNavigationTargets(project: Project): Collection<NavigationTarget> { | ||
if (target.project != project) return emptyList() | ||
return listOf(SymbolNavigationService.getInstance().psiElementNavigationTarget(target)) | ||
} | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (javaClass != other?.javaClass) return false | ||
|
||
other as HillaSymbol | ||
|
||
return target == other.target | ||
} | ||
|
||
override fun hashCode(): Int { | ||
return target.hashCode() | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
src/main/kotlin/com/vaadin/plugin/symbols/HillaSymbolReference.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.vaadin.plugin.symbols | ||
|
||
import com.intellij.model.Symbol | ||
import com.intellij.model.psi.PsiSymbolReference | ||
import com.intellij.openapi.util.TextRange | ||
import com.intellij.psi.JavaPsiFacade | ||
import com.intellij.psi.PsiElement | ||
import com.intellij.psi.search.GlobalSearchScope | ||
import com.intellij.psi.search.ProjectScope | ||
import com.intellij.psi.search.searches.AnnotatedElementsSearch | ||
import com.vaadin.plugin.endpoints.HILLA_BROWSER_CALLABLE | ||
|
||
class HillaSymbolReference(private val element: PsiElement) : PsiSymbolReference { | ||
|
||
override fun resolveReference(): Collection<Symbol> { | ||
val hillaBrowserCallableClass = | ||
JavaPsiFacade.getInstance(element.project) | ||
.findClass(HILLA_BROWSER_CALLABLE, ProjectScope.getLibrariesScope(element.project)) ?: return emptySet() | ||
|
||
val scope = GlobalSearchScope.allScope(element.project) | ||
|
||
var className = element.text | ||
var methodName: String? = null | ||
|
||
// both ClassName and ClassName.methodName are JSReferenceExpressions | ||
if (element.textContains('.')) { | ||
element.text.split('.').let { | ||
className = it[0] | ||
methodName = it[1] | ||
} | ||
} | ||
|
||
val psiClasses = | ||
AnnotatedElementsSearch.searchPsiClasses(hillaBrowserCallableClass, scope).filter { | ||
it.name?.endsWith(className) == true | ||
} | ||
|
||
if (psiClasses.isEmpty()) { | ||
return emptySet() | ||
} | ||
|
||
if (methodName != null) { | ||
return psiClasses | ||
.mapNotNull { it.findMethodsByName(methodName, true).firstOrNull() } | ||
.map { HillaSymbol(it) } | ||
} | ||
|
||
return psiClasses.map { HillaSymbol(it) } | ||
} | ||
|
||
override fun getElement(): PsiElement { | ||
return element | ||
} | ||
|
||
override fun getRangeInElement(): TextRange { | ||
val indexOfDot = element.text.indexOf('.') | ||
if (indexOfDot != -1) { | ||
return TextRange.from(indexOfDot + 1, element.text.length - indexOfDot) | ||
} | ||
return TextRange.allOf(element.text) | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/kotlin/com/vaadin/plugin/symbols/HillaSymbolReferenceProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.vaadin.plugin.symbols | ||
|
||
import com.intellij.lang.javascript.psi.JSReferenceExpression | ||
import com.intellij.model.Symbol | ||
import com.intellij.model.psi.PsiExternalReferenceHost | ||
import com.intellij.model.psi.PsiSymbolReference | ||
import com.intellij.model.psi.PsiSymbolReferenceHints | ||
import com.intellij.model.psi.PsiSymbolReferenceProvider | ||
import com.intellij.model.search.SearchRequest | ||
import com.intellij.openapi.project.Project | ||
|
||
internal class HillaSymbolReferenceProvider : PsiSymbolReferenceProvider { | ||
|
||
override fun getReferences( | ||
host: PsiExternalReferenceHost, | ||
hints: PsiSymbolReferenceHints | ||
): Collection<PsiSymbolReference> { | ||
if (host !is JSReferenceExpression) { | ||
return emptyList() | ||
} | ||
|
||
return listOf(HillaSymbolReference(host)) | ||
} | ||
|
||
override fun getSearchRequests(project: Project, symbol: Symbol): Collection<SearchRequest> { | ||
return emptyList() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<idea-plugin> | ||
|
||
<extensions defaultExtensionNs="com.intellij"> | ||
<psi.symbolReferenceProvider hostLanguage="TypeScript" | ||
hostElementClass="com.intellij.lang.javascript.psi.JSReferenceExpression" | ||
referenceClass="com.vaadin.plugin.symbols.HillaSymbolReference" | ||
targetClass="com.vaadin.plugin.symbols.HillaSymbol" | ||
implementationClass="com.vaadin.plugin.symbols.HillaSymbolReferenceProvider"/> | ||
</extensions> | ||
|
||
</idea-plugin> |