From 8d88b31e48658a70a88ca0a18b7365b2074c3649 Mon Sep 17 00:00:00 2001 From: Matthew McDonald Date: Fri, 10 Jan 2025 10:39:16 -0500 Subject: [PATCH] fix(amazonqDoc): Generate README for modules that are a part of the project --- ...-6362e624-b4c5-4a7a-80c7-5d52fcb4d78f.json | 4 +++ .../amazonqDoc/controller/DocController.kt | 32 +++++++++++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 .changes/next-release/bugfix-6362e624-b4c5-4a7a-80c7-5d52fcb4d78f.json diff --git a/.changes/next-release/bugfix-6362e624-b4c5-4a7a-80c7-5d52fcb4d78f.json b/.changes/next-release/bugfix-6362e624-b4c5-4a7a-80c7-5d52fcb4d78f.json new file mode 100644 index 00000000000..62cb2655191 --- /dev/null +++ b/.changes/next-release/bugfix-6362e624-b4c5-4a7a-80c7-5d52fcb4d78f.json @@ -0,0 +1,4 @@ +{ + "type" : "bugfix", + "description" : "Fix doc generation for modules that are a part of the project" +} \ No newline at end of file diff --git a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/controller/DocController.kt b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/controller/DocController.kt index 3788e8449e5..42ea5943e2a 100644 --- a/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/controller/DocController.kt +++ b/plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/controller/DocController.kt @@ -15,6 +15,9 @@ import com.intellij.openapi.command.WriteCommandAction import com.intellij.openapi.editor.Caret import com.intellij.openapi.editor.Editor import com.intellij.openapi.fileEditor.FileEditorManager +import com.intellij.openapi.project.Project +import com.intellij.openapi.roots.ProjectRootManager +import com.intellij.openapi.vfs.LocalFileSystem import com.intellij.openapi.vfs.VfsUtil import com.intellij.openapi.wm.ToolWindowManager import kotlinx.coroutines.withContext @@ -81,6 +84,7 @@ import software.aws.toolkits.jetbrains.utils.notifyError import software.aws.toolkits.resources.message import software.aws.toolkits.telemetry.AmazonqTelemetry import software.aws.toolkits.telemetry.Result +import java.nio.file.Paths import java.util.UUID enum class DocGenerationStep { @@ -674,7 +678,7 @@ class DocController( tabId = tabId, followUp = listOf( FollowUp( - pillText = message("amazonqFeatureDev.follow_up.modify_source_folder"), + pillText = message("amazonqDoc.prompt.folder.change"), type = FollowUpTypes.MODIFY_DEFAULT_SOURCE_FOLDER, status = FollowUpStatusType.Info, ) @@ -1002,6 +1006,15 @@ class DocController( } } + private fun isFolderPathInProjectModules(project: Project, folderPath: String): Boolean { + val path = Paths.get(folderPath) + val virtualFile = LocalFileSystem.getInstance().findFileByIoFile(path.toFile()) ?: return false + + val projectFileIndex = ProjectRootManager.getInstance(project).fileIndex + + return projectFileIndex.isInProject(virtualFile) + } + private suspend fun modifyDefaultSourceFolder(tabId: String) { val session = getSessionInfo(tabId) val currentSourceFolder = session.context.selectedSourceFolder @@ -1012,6 +1025,7 @@ class DocController( withContext(EDT) { val selectedFolder = selectFolder(context.project, currentSourceFolder) + // No folder was selected if (selectedFolder == null) { logger.info { "Cancelled dialog and not selected any folder" } @@ -1020,19 +1034,31 @@ class DocController( return@withContext } - // The folder is not in the workspace - if (!selectedFolder.path.startsWith(projectRoot.path)) { + val isFolderPathInProject = isFolderPathInProjectModules(context.project, selectedFolder.path) + + if (!isFolderPathInProject) { logger.info { "Selected folder not in workspace: ${selectedFolder.path}" } messenger.sendAnswer( tabId = tabId, messageType = DocMessageType.Answer, message = message("amazonqFeatureDev.follow_up.incorrect_source_folder"), + followUp = listOf( + FollowUp( + pillText = message("amazonqDoc.prompt.folder.change"), + type = FollowUpTypes.MODIFY_DEFAULT_SOURCE_FOLDER, + status = FollowUpStatusType.Info, + ) + ), + snapToTop = true ) + messenger.sendChatInputEnabledMessage(tabId, enabled = false) + reason = ModifySourceFolderErrorReason.NotInWorkspaceFolder return@withContext } + if (selectedFolder.path == projectRoot.path) { docGenerationTask.folderLevel = DocGenerationFolderLevel.ENTIRE_WORKSPACE } else {