in src/main/kotlin/org/jetbrains/mcpserverplugin/git/vcsTools.kt [82:120]
override fun handle(project: Project, args: NoArgs): Response {
val projectDir = project.guessProjectDir()?.toNioPathOrNull()
?: return Response(error = "project dir not found")
val changeListManager = ChangeListManager.getInstance(project)
val changes = changeListManager.allChanges
val unversionedFiles = changeListManager.unversionedFilesPaths
val result = mutableListOf<Map<String, String>>()
// Process tracked changes
changes.forEach { change ->
val absolutePath = change.virtualFile?.path ?: change.afterRevision?.file?.path
val changeType = change.type
if (absolutePath != null) {
try {
val relativePath = projectDir.relativize(Path(absolutePath)).toString()
result.add(mapOf("path" to relativePath, "type" to changeType.toString()))
} catch (e: IllegalArgumentException) {
// Skip files outside project directory
}
}
}
// Process unversioned files
unversionedFiles.forEach { file ->
try {
val relativePath = projectDir.relativize(Path(file.path)).toString()
result.add(mapOf("path" to relativePath, "type" to "UNVERSIONED"))
} catch (e: IllegalArgumentException) {
// Skip files outside project directory
}
}
return Response(result.joinToString(",\n", prefix = "[", postfix = "]") {
"""{"path": "${it["path"]}", "type": "${it["type"]}"}"""
})
}