@@ -15,6 +15,9 @@ import com.intellij.openapi.command.WriteCommandAction
1515import com.intellij.openapi.editor.Caret
1616import com.intellij.openapi.editor.Editor
1717import 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
1821import com.intellij.openapi.vfs.VfsUtil
1922import com.intellij.openapi.wm.ToolWindowManager
2023import kotlinx.coroutines.withContext
@@ -81,6 +84,7 @@ import software.aws.toolkits.jetbrains.utils.notifyError
8184import software.aws.toolkits.resources.message
8285import software.aws.toolkits.telemetry.AmazonqTelemetry
8386import software.aws.toolkits.telemetry.Result
87+ import java.nio.file.Paths
8488import java.util.UUID
8589
8690enum 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