@@ -10,6 +10,9 @@ import com.intellij.diff.requests.SimpleDiffRequest
1010import com.intellij.diff.util.DiffUserDataKeys
1111import com.intellij.ide.BrowserUtil
1212import 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
1316import com.intellij.openapi.vfs.VfsUtil
1417import com.intellij.openapi.wm.ToolWindowManager
1518import kotlinx.coroutines.withContext
@@ -68,6 +71,7 @@ import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.session.NewFil
6871import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.session.SessionStatePhase
6972import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.util.CancellationTokenSource
7073import software.aws.toolkits.resources.message
74+ import java.nio.file.Paths
7175import java.util.UUID
7276
7377enum 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