Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return source path information per module #156

Merged
merged 8 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CopilotPluginUtil {
REDO("redo"),
REFRESH("refresh"),
SHOW_IN_IDE("showInIde"),
GET_SOURCE_PATHS("getSourcePaths"),
GET_MODULE_PATHS("getModulePaths"),
}

private val pluginVersion = PluginManagerCore.getPlugin(PluginId.getId("com.vaadin.intellij-plugin"))?.version
Expand All @@ -64,7 +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)
HANDLERS.GET_MODULE_PATHS.command -> return GetModulePathsHandler(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,59 @@
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.project.guessProjectDir
import com.intellij.openapi.roots.CompilerModuleExtension
import com.intellij.openapi.roots.ModuleRootManager
import io.netty.handler.codec.http.HttpResponseStatus
import org.jetbrains.jps.model.java.JavaResourceRootType
import org.jetbrains.jps.model.java.JavaSourceRootType

class GetModulePathsHandler(project: Project) : AbstractHandler(project) {

@JvmRecord data class ProjectInfo(val basePath: String?, val modules: List<ModuleInfo>)

@JvmRecord
data class ModuleInfo(
val name: String,
val contentRoots: Array<String>,
val javaSourcePaths: Array<String>,
val javaTestSourcePaths: Array<String>,
val resourcePaths: Array<String>,
val testResourcePaths: Array<String>,
val outputPath: String?
)

override fun run(): HandlerResponse {
val modules = ArrayList<ModuleInfo>()
ModuleManager.getInstance(project).modules.forEach { module: Module ->
val moduleRootManager = ModuleRootManager.getInstance(module)
val contentRoots = moduleRootManager.contentRoots.map { it.path }

val compilerModuleExtension = CompilerModuleExtension.getInstance(module)
val outputPath = compilerModuleExtension?.compilerOutputPath

// Note that the JavaSourceRootType.SOURCE also includes Kotlin source folders
// Only include folder if is is not in the output path
val javaSourcePaths = moduleRootManager.getSourceRoots(JavaSourceRootType.SOURCE).map({ it.path })
val javaTestSourcePaths = moduleRootManager.getSourceRoots(JavaSourceRootType.TEST_SOURCE).map({ it.path })

val resourcePaths = moduleRootManager.getSourceRoots(JavaResourceRootType.RESOURCE).map { it.path }
val testResourcePaths = moduleRootManager.getSourceRoots(JavaResourceRootType.TEST_RESOURCE).map { it.path }

modules.add(
ModuleInfo(
module.name,
Artur- marked this conversation as resolved.
Show resolved Hide resolved
contentRoots.toTypedArray(),
javaSourcePaths.toTypedArray(),
javaTestSourcePaths.toTypedArray(),
resourcePaths.toTypedArray(),
testResourcePaths.toTypedArray(),
outputPath?.path))
}
val projectInfo = ProjectInfo(project.guessProjectDir()?.path, modules)
val data = mapOf("project" to projectInfo)
return HandlerResponse(HttpResponseStatus.OK, data)
}
}

This file was deleted.