@@ -10,6 +10,9 @@ import com.intellij.diff.requests.SimpleDiffRequest
10
10
import com.intellij.diff.util.DiffUserDataKeys
11
11
import com.intellij.ide.BrowserUtil
12
12
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
13
16
import com.intellij.openapi.vfs.VfsUtil
14
17
import com.intellij.openapi.wm.ToolWindowManager
15
18
import kotlinx.coroutines.withContext
@@ -68,6 +71,7 @@ import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.session.NewFil
68
71
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.session.SessionStatePhase
69
72
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.util.CancellationTokenSource
70
73
import software.aws.toolkits.resources.message
74
+ import java.nio.file.Paths
71
75
import java.util.UUID
72
76
73
77
enum class DocGenerationStep {
@@ -565,7 +569,7 @@ class DocController(
565
569
tabId = tabId,
566
570
followUp = listOf (
567
571
FollowUp (
568
- pillText = message(" amazonqFeatureDev.follow_up.modify_source_folder " ),
572
+ pillText = message(" amazonqDoc.prompt.folder.change " ),
569
573
type = FollowUpTypes .MODIFY_DEFAULT_SOURCE_FOLDER ,
570
574
status = FollowUpStatusType .Info ,
571
575
)
@@ -895,30 +899,53 @@ class DocController(
895
899
}
896
900
}
897
901
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
+
898
911
private suspend fun modifyDefaultSourceFolder (tabId : String ) {
899
912
val session = getSessionInfo(tabId)
900
913
val currentSourceFolder = session.context.selectedSourceFolder
901
914
val projectRoot = session.context.projectRoot
902
915
903
916
withContext(EDT ) {
904
917
val selectedFolder = selectFolder(context.project, currentSourceFolder)
918
+
905
919
// No folder was selected
906
920
if (selectedFolder == null ) {
907
921
logger.info { " Cancelled dialog and not selected any folder" }
908
922
return @withContext
909
923
}
910
924
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) {
913
928
logger.info { " Selected folder not in workspace: ${selectedFolder.path} " }
914
929
915
930
messenger.sendAnswer(
916
931
tabId = tabId,
917
932
messageType = DocMessageType .Answer ,
918
933
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
919
942
)
943
+
944
+ messenger.sendChatInputEnabledMessage(tabId, enabled = false )
945
+
920
946
return @withContext
921
947
}
948
+
922
949
if (selectedFolder.path == projectRoot.path) {
923
950
docGenerationTask.folderLevel = DocGenerationFolderLevel .ENTIRE_WORKSPACE
924
951
} else {
0 commit comments