Skip to content

Commit 8093096

Browse files
fix(amazonqDoc): Generate README for modules that are a part of the project (#5247)
Co-authored-by: Matthew McDonald <[email protected]>
1 parent 5fa8e42 commit 8093096

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-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: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import com.intellij.diff.requests.SimpleDiffRequest
1010
import com.intellij.diff.util.DiffUserDataKeys
1111
import com.intellij.ide.BrowserUtil
1212
import com.intellij.openapi.application.runInEdt
13+
import com.intellij.openapi.project.Project
14+
import com.intellij.openapi.roots.ProjectRootManager
15+
import com.intellij.openapi.vfs.LocalFileSystem
1316
import com.intellij.openapi.vfs.VfsUtil
1417
import com.intellij.openapi.wm.ToolWindowManager
1518
import kotlinx.coroutines.withContext
@@ -68,6 +71,7 @@ import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.session.NewFil
6871
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.session.SessionStatePhase
6972
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.util.CancellationTokenSource
7073
import software.aws.toolkits.resources.message
74+
import java.nio.file.Paths
7175
import java.util.UUID
7276

7377
enum class DocGenerationStep {
@@ -565,7 +569,7 @@ class DocController(
565569
tabId = tabId,
566570
followUp = listOf(
567571
FollowUp(
568-
pillText = message("amazonqFeatureDev.follow_up.modify_source_folder"),
572+
pillText = message("amazonqDoc.prompt.folder.change"),
569573
type = FollowUpTypes.MODIFY_DEFAULT_SOURCE_FOLDER,
570574
status = FollowUpStatusType.Info,
571575
)
@@ -895,30 +899,53 @@ class DocController(
895899
}
896900
}
897901

902+
private fun isFolderPathInProjectModules(project: Project, folderPath: String): Boolean {
903+
val path = Paths.get(folderPath)
904+
val virtualFile = LocalFileSystem.getInstance().findFileByIoFile(path.toFile()) ?: return false
905+
906+
val projectFileIndex = ProjectRootManager.getInstance(project).fileIndex
907+
908+
return projectFileIndex.isInProject(virtualFile)
909+
}
910+
898911
private suspend fun modifyDefaultSourceFolder(tabId: String) {
899912
val session = getSessionInfo(tabId)
900913
val currentSourceFolder = session.context.selectedSourceFolder
901914
val projectRoot = session.context.projectRoot
902915

903916
withContext(EDT) {
904917
val selectedFolder = selectFolder(context.project, currentSourceFolder)
918+
905919
// No folder was selected
906920
if (selectedFolder == null) {
907921
logger.info { "Cancelled dialog and not selected any folder" }
908922
return@withContext
909923
}
910924

911-
// The folder is not in the workspace
912-
if (!selectedFolder.path.startsWith(projectRoot.path)) {
925+
val isFolderPathInProject = isFolderPathInProjectModules(context.project, selectedFolder.path)
926+
927+
if (!isFolderPathInProject) {
913928
logger.info { "Selected folder not in workspace: ${selectedFolder.path}" }
914929

915930
messenger.sendAnswer(
916931
tabId = tabId,
917932
messageType = DocMessageType.Answer,
918933
message = message("amazonqFeatureDev.follow_up.incorrect_source_folder"),
934+
followUp = listOf(
935+
FollowUp(
936+
pillText = message("amazonqDoc.prompt.folder.change"),
937+
type = FollowUpTypes.MODIFY_DEFAULT_SOURCE_FOLDER,
938+
status = FollowUpStatusType.Info,
939+
)
940+
),
941+
snapToTop = true
919942
)
943+
944+
messenger.sendChatInputEnabledMessage(tabId, enabled = false)
945+
920946
return@withContext
921947
}
948+
922949
if (selectedFolder.path == projectRoot.path) {
923950
docGenerationTask.folderLevel = DocGenerationFolderLevel.ENTIRE_WORKSPACE
924951
} else {

0 commit comments

Comments
 (0)