Skip to content

Commit

Permalink
Merge branch 'main' into chore/include-indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
abdullahtellioglu authored Dec 30, 2024
2 parents 9d46315 + 7ec5cad commit d356d8c
Show file tree
Hide file tree
Showing 11 changed files with 115 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,21 @@ package com.vaadin.plugin.endpoints
import com.intellij.microservices.endpoints.EndpointType
import com.intellij.microservices.endpoints.EndpointsFilter
import com.intellij.microservices.endpoints.EndpointsProvider
import com.intellij.microservices.endpoints.EndpointsProvider.Status
import com.intellij.microservices.endpoints.FrameworkPresentation
import com.intellij.microservices.endpoints.HTTP_SERVER_TYPE
import com.intellij.microservices.endpoints.ModuleEndpointsFilter
import com.intellij.microservices.endpoints.presentation.HttpUrlPresentation
import com.intellij.microservices.url.UrlPath
import com.intellij.navigation.ItemPresentation
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.ModificationTracker
import com.intellij.psi.PsiElement
import com.intellij.uast.UastModificationTracker
import com.vaadin.plugin.utils.VaadinIcons
import com.vaadin.plugin.utils.hasVaadin

internal class VaadinEndpointsProvider : EndpointsProvider<VaadinRoute, VaadinRoute> {
override val endpointType: EndpointType = HTTP_SERVER_TYPE

override val presentation: FrameworkPresentation =
FrameworkPresentation("Vaadin", "Vaadin Flow", VaadinIcons.VAADIN_BLUE)
abstract class VaadinEndpointsProvider : EndpointsProvider<VaadinRoute, VaadinRoute> {

override fun getStatus(project: Project): Status {
if (hasVaadin(project)) return Status.HAS_ENDPOINTS
override val endpointType: EndpointType = HTTP_SERVER_TYPE

return Status.UNAVAILABLE
override fun getStatus(project: Project): EndpointsProvider.Status {
if (hasVaadin(project)) return EndpointsProvider.Status.HAS_ENDPOINTS
return EndpointsProvider.Status.UNAVAILABLE
}

override fun getModificationTracker(project: Project): ModificationTracker {
Expand All @@ -37,7 +28,7 @@ internal class VaadinEndpointsProvider : EndpointsProvider<VaadinRoute, VaadinRo
if (filter !is ModuleEndpointsFilter) return emptyList()
if (!hasVaadin(filter.module)) return emptyList()

return findVaadinRoutes(project, filter.transitiveSearchScope)
return findFlowRoutes(project, filter.transitiveSearchScope)
}

override fun getEndpoints(group: VaadinRoute): Iterable<VaadinRoute> {
Expand All @@ -48,27 +39,7 @@ internal class VaadinEndpointsProvider : EndpointsProvider<VaadinRoute, VaadinRo
return group.isValid()
}

override fun getEndpointPresentation(group: VaadinRoute, endpoint: VaadinRoute): ItemPresentation {
return HttpUrlPresentation(normalizeUrl(group.urlMapping), group.locationString, VaadinIcons.VAADIN_BLUE)
}

private fun normalizeUrl(urlMapping: String): String {
val urlString = run {
if (urlMapping.isBlank()) return@run "/"
if (!urlMapping.startsWith("/")) return@run "/$urlMapping"
return@run urlMapping
}

return parseVaadinUrlMapping(urlString).getPresentation(VaadinUrlRenderer)
}

override fun getDocumentationElement(group: VaadinRoute, endpoint: VaadinRoute): PsiElement? {
return endpoint.anchor.retrieve()
}
}

private object VaadinUrlRenderer : UrlPath.PathSegmentRenderer {
override fun visitVariable(variable: UrlPath.PathSegment.Variable): String {
return "{${variable.variableName}}"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.vaadin.plugin.endpoints

import com.intellij.microservices.endpoints.EndpointsFilter
import com.intellij.microservices.endpoints.FrameworkPresentation
import com.intellij.microservices.endpoints.ModuleEndpointsFilter
import com.intellij.microservices.endpoints.presentation.HttpUrlPresentation
import com.intellij.microservices.url.UrlPath
import com.intellij.navigation.ItemPresentation
import com.intellij.openapi.project.Project
import com.vaadin.plugin.utils.VaadinIcons
import com.vaadin.plugin.utils.hasVaadin

internal class VaadinFlowEndpointsProvider : VaadinEndpointsProvider() {

override val presentation: FrameworkPresentation =
FrameworkPresentation("Vaadin-Flow", "Vaadin Flow", VaadinIcons.VAADIN_BLUE)

override fun getEndpointGroups(project: Project, filter: EndpointsFilter): Iterable<VaadinRoute> {
if (filter !is ModuleEndpointsFilter) return emptyList()
if (!hasVaadin(filter.module)) return emptyList()

return findFlowRoutes(project, filter.transitiveSearchScope)
}

override fun getEndpointPresentation(group: VaadinRoute, endpoint: VaadinRoute): ItemPresentation {
return HttpUrlPresentation(normalizeUrl(group.urlMapping), group.locationString, VaadinIcons.VAADIN_BLUE)
}

private fun normalizeUrl(urlMapping: String): String {
val urlString = run {
if (urlMapping.isBlank()) return@run "/"
if (!urlMapping.startsWith("/")) return@run "/$urlMapping"
return@run urlMapping
}

return parseVaadinUrlMapping(urlString).getPresentation(VaadinUrlRenderer)
}

private object VaadinUrlRenderer : UrlPath.PathSegmentRenderer {
override fun visitVariable(variable: UrlPath.PathSegment.Variable): String {
return "{${variable.variableName}}"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.vaadin.plugin.endpoints

import com.intellij.microservices.endpoints.EndpointsFilter
import com.intellij.microservices.endpoints.FrameworkPresentation
import com.intellij.microservices.endpoints.ModuleEndpointsFilter
import com.intellij.microservices.endpoints.presentation.HttpUrlPresentation
import com.intellij.navigation.ItemPresentation
import com.intellij.openapi.project.Project
import com.vaadin.plugin.utils.VaadinIcons
import com.vaadin.plugin.utils.hasVaadin

internal class VaadinHillaEndpointsProvider : VaadinEndpointsProvider() {

override val presentation: FrameworkPresentation =
FrameworkPresentation("Vaadin-Hilla", "Vaadin Hilla", VaadinIcons.HILLA)

override fun getEndpointGroups(project: Project, filter: EndpointsFilter): Iterable<VaadinRoute> {
if (filter !is ModuleEndpointsFilter) return emptyList()
if (!hasVaadin(filter.module)) return emptyList()

return findHillaEndpoints(project, filter.transitiveSearchScope)
}

override fun getEndpointPresentation(group: VaadinRoute, endpoint: VaadinRoute): ItemPresentation {
return HttpUrlPresentation(group.urlMapping, group.locationString, VaadinIcons.HILLA)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal class VaadinImplicitUsageProvider : ImplicitUsageProvider {
!element.isAnnotationType &&
(AnnotationUtil.isAnnotated(element, VAADIN_ROUTE, 0) ||
AnnotationUtil.isAnnotated(element, VAADIN_TAG, 0) ||
AnnotationUtil.isAnnotated(element, HILLA_BROWSER_CALLABLE, 0) ||
InheritanceUtil.isInheritor(element, VAADIN_APP_SHELL_CONFIGURATOR))
}

Expand Down
27 changes: 26 additions & 1 deletion src/main/kotlin/com/vaadin/plugin/endpoints/VaadinModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ internal const val VAADIN_ROUTE = "com.vaadin.flow.router.Route"
internal const val VAADIN_APP_SHELL_CONFIGURATOR = "com.vaadin.flow.component.page.AppShellConfigurator"
internal const val VAADIN_ID = "com.vaadin.flow.component.template.Id"
internal const val VAADIN_TAG = "com.vaadin.flow.component.Tag"
internal const val HILLA_BROWSER_CALLABLE = "com.vaadin.hilla.BrowserCallable"

internal fun findVaadinRoutes(project: Project, scope: GlobalSearchScope): Collection<VaadinRoute> {
internal fun findFlowRoutes(project: Project, scope: GlobalSearchScope): Collection<VaadinRoute> {
val vaadinRouteClass =
JavaPsiFacade.getInstance(project).findClass(VAADIN_ROUTE, ProjectScope.getLibrariesScope(project))
?: return emptyList()
Expand All @@ -42,3 +43,27 @@ internal fun findVaadinRoutes(project: Project, scope: GlobalSearchScope): Colle

return routes.toList()
}

internal fun findHillaEndpoints(project: Project, scope: GlobalSearchScope): Collection<VaadinRoute> {
val hillaBrowserCallableClass =
JavaPsiFacade.getInstance(project).findClass(HILLA_BROWSER_CALLABLE, ProjectScope.getLibrariesScope(project))
?: return emptyList()

val endpoints = ArrayList<VaadinRoute>()

AnnotatedElementsSearch.searchPsiClasses(hillaBrowserCallableClass, scope)
.forEach(
Processor { psiClass ->
val uClass = psiClass.toUElementOfType<UClass>()
val sourcePsi = uClass?.sourcePsi
val className = psiClass.name

if (sourcePsi == null || className == null) return@Processor true

endpoints.add(VaadinRoute(className, className, PsiAnchor.create(sourcePsi)))

true
})

return endpoints.toList()
}
2 changes: 1 addition & 1 deletion src/main/kotlin/com/vaadin/plugin/endpoints/VaadinRoute.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package com.vaadin.plugin.endpoints

import com.intellij.psi.PsiAnchor

internal class VaadinRoute(val urlMapping: String, val locationString: String, val anchor: PsiAnchor) {
class VaadinRoute(val urlMapping: String, val locationString: String, val anchor: PsiAnchor) {
fun isValid(): Boolean = anchor.retrieve() != null
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ internal class VaadinUrlResolver(private val project: Project) : UrlResolver {
}

internal val VAADIN_ROUTES_SEARCH: SourceLibSearchProvider<List<VaadinRoute>, Module> =
SourceLibSearchProvider("VAADIN_ROUTES") { p, _, scope -> findVaadinRoutes(p, scope).toList() }
SourceLibSearchProvider("VAADIN_ROUTES") { p, _, scope -> findFlowRoutes(p, scope).toList() }

private fun getAllModuleVariants(project: Project): Sequence<VaadinUrlTargetInfo> {
val modules = ModuleManager.getInstance(project).modules
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/com/vaadin/plugin/utils/VaadinIcons.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class VaadinIcons {

val VAADIN = IconLoader.getIcon("$RESOURCE_PATH/vaadin.svg", VaadinIcons::class.java.classLoader)

val HILLA = IconLoader.getIcon("$RESOURCE_PATH/hilla.svg", VaadinIcons::class.java.classLoader)

val DEBUG_HOTSWAP = IconLoader.getIcon("$RESOURCE_PATH/debug.svg", VaadinIcons::class.java.classLoader)

val RERUN_HOTSWAP = IconLoader.getIcon("$RESOURCE_PATH/rerun.svg", VaadinIcons::class.java.classLoader)
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/META-INF/vaadin-with-microservices.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<idea-plugin>

<extensions defaultExtensionNs="com.intellij">
<microservices.endpointsProvider implementation="com.vaadin.plugin.endpoints.VaadinEndpointsProvider"/>
<microservices.endpointsProvider implementation="com.vaadin.plugin.endpoints.VaadinFlowEndpointsProvider"/>
<microservices.endpointsProvider implementation="com.vaadin.plugin.endpoints.VaadinHillaEndpointsProvider"/>
<microservices.urlResolverFactory implementation="com.vaadin.plugin.endpoints.VaadinUrlResolverFactory"/>
<psi.referenceContributor language="UAST" implementation="com.vaadin.plugin.endpoints.VaadinReferenceContributor"/>
<implicitUsageProvider implementation="com.vaadin.plugin.endpoints.VaadinImplicitUsageProvider"/>
</extensions>

Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/META-INF/vaadin-with-ultimate.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<idea-plugin>

<extensions defaultExtensionNs="com.intellij">
<psi.referenceContributor language="UAST" implementation="com.vaadin.plugin.endpoints.VaadinReferenceContributor"/>
</extensions>

</idea-plugin>
1 change: 1 addition & 0 deletions src/main/resources/vaadin/icons/hilla.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d356d8c

Please sign in to comment.