Skip to content

Commit

Permalink
feat: Handler for getting all source paths
Browse files Browse the repository at this point in the history
Fixes #142
  • Loading branch information
Artur- committed Nov 3, 2024
1 parent dbf301f commit d065f40
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String>();
val testPaths = ArrayList<String>();
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<String, Any> = mapOf("sourcePaths" to sourcePaths, "testSourcePaths" to testPaths);
return HandlerResponse(HttpResponseStatus.OK, data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String>? = null)
data class HandlerResponse(val status: HttpResponseStatus, val data: Map<String,Any>? = null)

0 comments on commit d065f40

Please sign in to comment.