From d065f40fe37ffb35fe3f7e22fc3edb60902543f5 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Sun, 3 Nov 2024 12:21:12 +0200 Subject: [PATCH] feat: Handler for getting all source paths Fixes #142 --- .../plugin/copilot/CopilotPluginUtil.kt | 2 ++ .../copilot/handler/GetSourcePathsHandler.kt | 23 +++++++++++++++++++ .../plugin/copilot/handler/HandlerResponse.kt | 2 +- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/com/vaadin/plugin/copilot/handler/GetSourcePathsHandler.kt diff --git a/src/main/kotlin/com/vaadin/plugin/copilot/CopilotPluginUtil.kt b/src/main/kotlin/com/vaadin/plugin/copilot/CopilotPluginUtil.kt index afc35fd..f100b43 100644 --- a/src/main/kotlin/com/vaadin/plugin/copilot/CopilotPluginUtil.kt +++ b/src/main/kotlin/com/vaadin/plugin/copilot/CopilotPluginUtil.kt @@ -40,6 +40,7 @@ class CopilotPluginUtil { REDO("redo"), REFRESH("refresh"), SHOW_IN_IDE("showInIde"), + GET_SOURCE_PATHS("getSourcePaths"), } private val pluginVersion = PluginManagerCore.getPlugin(PluginId.getId("com.vaadin.intellij-plugin"))?.version @@ -63,6 +64,7 @@ class CopilotPluginUtil { HANDLERS.REDO.command -> return RedoHandler(project, data) HANDLERS.SHOW_IN_IDE.command -> return ShowInIdeHandler(project, data) HANDLERS.REFRESH.command -> return RefreshHandler(project) + HANDLERS.GET_SOURCE_PATHS.command -> return GetSourcePathsHandler(project) else -> { LOG.warn("Command $command not supported by plugin") return object : Handler { diff --git a/src/main/kotlin/com/vaadin/plugin/copilot/handler/GetSourcePathsHandler.kt b/src/main/kotlin/com/vaadin/plugin/copilot/handler/GetSourcePathsHandler.kt new file mode 100644 index 0000000..3557c08 --- /dev/null +++ b/src/main/kotlin/com/vaadin/plugin/copilot/handler/GetSourcePathsHandler.kt @@ -0,0 +1,23 @@ +package com.vaadin.plugin.copilot.handler + +import com.intellij.openapi.module.Module +import com.intellij.openapi.module.ModuleManager +import com.intellij.openapi.project.Project +import com.intellij.openapi.roots.ModuleRootManager +import io.netty.handler.codec.http.HttpResponseStatus +import org.jetbrains.jps.model.java.JavaSourceRootType + +class GetSourcePathsHandler(project: Project) : AbstractHandler(project) { + + override fun run(): HandlerResponse { + val sourcePaths = ArrayList(); + val testPaths = ArrayList(); + ModuleManager.getInstance(project).modules.forEach { module: Module -> + val moduleRootManager = ModuleRootManager.getInstance(module); + sourcePaths.addAll(moduleRootManager.getSourceRoots(JavaSourceRootType.SOURCE).map { it.path }); + testPaths.addAll(moduleRootManager.getSourceRoots(JavaSourceRootType.TEST_SOURCE).map { it.path }); + } + val data: Map = mapOf("sourcePaths" to sourcePaths, "testSourcePaths" to testPaths); + return HandlerResponse(HttpResponseStatus.OK, data); + } +} diff --git a/src/main/kotlin/com/vaadin/plugin/copilot/handler/HandlerResponse.kt b/src/main/kotlin/com/vaadin/plugin/copilot/handler/HandlerResponse.kt index 1706167..1d6e941 100644 --- a/src/main/kotlin/com/vaadin/plugin/copilot/handler/HandlerResponse.kt +++ b/src/main/kotlin/com/vaadin/plugin/copilot/handler/HandlerResponse.kt @@ -2,4 +2,4 @@ package com.vaadin.plugin.copilot.handler import io.netty.handler.codec.http.HttpResponseStatus -data class HandlerResponse(val status: HttpResponseStatus, val data: Map? = null) +data class HandlerResponse(val status: HttpResponseStatus, val data: Map? = null)