Skip to content

Commit 8d88b31

Browse files
committed
fix(amazonqDoc): Generate README for modules that are a part of the project
1 parent 0e4a1d7 commit 8d88b31

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "bugfix",
3+
"description" : "Fix doc generation for modules that are a part of the project"
4+
}

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/controller/DocController.kt

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import com.intellij.openapi.command.WriteCommandAction
1515
import com.intellij.openapi.editor.Caret
1616
import com.intellij.openapi.editor.Editor
1717
import com.intellij.openapi.fileEditor.FileEditorManager
18+
import com.intellij.openapi.project.Project
19+
import com.intellij.openapi.roots.ProjectRootManager
20+
import com.intellij.openapi.vfs.LocalFileSystem
1821
import com.intellij.openapi.vfs.VfsUtil
1922
import com.intellij.openapi.wm.ToolWindowManager
2023
import kotlinx.coroutines.withContext
@@ -81,6 +84,7 @@ import software.aws.toolkits.jetbrains.utils.notifyError
8184
import software.aws.toolkits.resources.message
8285
import software.aws.toolkits.telemetry.AmazonqTelemetry
8386
import software.aws.toolkits.telemetry.Result
87+
import java.nio.file.Paths
8488
import java.util.UUID
8589

8690
enum class DocGenerationStep {
@@ -674,7 +678,7 @@ class DocController(
674678
tabId = tabId,
675679
followUp = listOf(
676680
FollowUp(
677-
pillText = message("amazonqFeatureDev.follow_up.modify_source_folder"),
681+
pillText = message("amazonqDoc.prompt.folder.change"),
678682
type = FollowUpTypes.MODIFY_DEFAULT_SOURCE_FOLDER,
679683
status = FollowUpStatusType.Info,
680684
)
@@ -1002,6 +1006,15 @@ class DocController(
10021006
}
10031007
}
10041008

1009+
private fun isFolderPathInProjectModules(project: Project, folderPath: String): Boolean {
1010+
val path = Paths.get(folderPath)
1011+
val virtualFile = LocalFileSystem.getInstance().findFileByIoFile(path.toFile()) ?: return false
1012+
1013+
val projectFileIndex = ProjectRootManager.getInstance(project).fileIndex
1014+
1015+
return projectFileIndex.isInProject(virtualFile)
1016+
}
1017+
10051018
private suspend fun modifyDefaultSourceFolder(tabId: String) {
10061019
val session = getSessionInfo(tabId)
10071020
val currentSourceFolder = session.context.selectedSourceFolder
@@ -1012,6 +1025,7 @@ class DocController(
10121025

10131026
withContext(EDT) {
10141027
val selectedFolder = selectFolder(context.project, currentSourceFolder)
1028+
10151029
// No folder was selected
10161030
if (selectedFolder == null) {
10171031
logger.info { "Cancelled dialog and not selected any folder" }
@@ -1020,19 +1034,31 @@ class DocController(
10201034
return@withContext
10211035
}
10221036

1023-
// The folder is not in the workspace
1024-
if (!selectedFolder.path.startsWith(projectRoot.path)) {
1037+
val isFolderPathInProject = isFolderPathInProjectModules(context.project, selectedFolder.path)
1038+
1039+
if (!isFolderPathInProject) {
10251040
logger.info { "Selected folder not in workspace: ${selectedFolder.path}" }
10261041

10271042
messenger.sendAnswer(
10281043
tabId = tabId,
10291044
messageType = DocMessageType.Answer,
10301045
message = message("amazonqFeatureDev.follow_up.incorrect_source_folder"),
1046+
followUp = listOf(
1047+
FollowUp(
1048+
pillText = message("amazonqDoc.prompt.folder.change"),
1049+
type = FollowUpTypes.MODIFY_DEFAULT_SOURCE_FOLDER,
1050+
status = FollowUpStatusType.Info,
1051+
)
1052+
),
1053+
snapToTop = true
10311054
)
10321055

1056+
messenger.sendChatInputEnabledMessage(tabId, enabled = false)
1057+
10331058
reason = ModifySourceFolderErrorReason.NotInWorkspaceFolder
10341059
return@withContext
10351060
}
1061+
10361062
if (selectedFolder.path == projectRoot.path) {
10371063
docGenerationTask.folderLevel = DocGenerationFolderLevel.ENTIRE_WORKSPACE
10381064
} else {

0 commit comments

Comments
 (0)