Skip to content

Commit 89d6310

Browse files
committed
fix(/dev): source folder modification now allows any sub-folder
1 parent ae9e097 commit 89d6310

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/controller/FeatureDevController.kt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ class FeatureDevController(
193193
when (sessionState) {
194194
is PrepareCodeGenerationState -> {
195195
runInEdt {
196-
val existingFile = VfsUtil.findRelativeFile(message.filePath, session.context.projectRoot)
196+
val existingFile = VfsUtil.findRelativeFile(message.filePath, session.context.currentRoot)
197197

198198
val leftDiffContent = if (existingFile == null) {
199199
EmptyContent()
@@ -606,7 +606,8 @@ class FeatureDevController(
606606

607607
private suspend fun modifyDefaultSourceFolder(tabId: String) {
608608
val session = getSessionInfo(tabId)
609-
val uri = session.context.projectRoot
609+
val currentRoot = session.context.currentRoot
610+
val projectRoot = session.context.projectRoot
610611
val fileChooserDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor()
611612

612613
val modifyFolderFollowUp = FollowUp(
@@ -619,7 +620,7 @@ class FeatureDevController(
619620
var reason: String? = null
620621

621622
withContext(EDT) {
622-
val selectedFolder = FileChooser.chooseFile(fileChooserDescriptor, context.project, uri)
623+
val selectedFolder = FileChooser.chooseFile(fileChooserDescriptor, context.project, currentRoot)
623624

624625
// No folder was selected
625626
if (selectedFolder == null) {
@@ -635,7 +636,7 @@ class FeatureDevController(
635636
}
636637

637638
// The folder is not in the workspace
638-
if (selectedFolder.parent.path != uri.path) {
639+
if (!selectedFolder.path.startsWith(projectRoot.path)) {
639640
logger.info { "Selected folder not in workspace: ${selectedFolder.path}" }
640641

641642
messenger.sendAnswer(
@@ -655,7 +656,7 @@ class FeatureDevController(
655656

656657
logger.info { "Selected correct folder inside workspace: ${selectedFolder.path}" }
657658

658-
session.context.projectRoot = selectedFolder
659+
session.context.currentRoot = selectedFolder
659660
result = Result.Succeeded
660661

661662
messenger.sendAnswer(

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/session/Session.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,16 @@ class Session(val tabID: String, val project: Project) {
9696
* Triggered by the Insert code follow-up button to apply code changes.
9797
*/
9898
fun insertChanges(filePaths: List<NewFileZipInfo>, deletedFiles: List<DeletedFileInfo>, references: List<CodeReferenceGenerated>) {
99-
val projectRootPath = context.projectRoot.toNioPath()
99+
val currentRootPath = context.currentRoot.toNioPath()
100100

101-
filePaths.forEach { resolveAndCreateOrUpdateFile(projectRootPath, it.zipFilePath, it.fileContent) }
101+
filePaths.forEach { resolveAndCreateOrUpdateFile(currentRootPath, it.zipFilePath, it.fileContent) }
102102

103-
deletedFiles.forEach { resolveAndDeleteFile(projectRootPath, it.zipFilePath) }
103+
deletedFiles.forEach { resolveAndDeleteFile(currentRootPath, it.zipFilePath) }
104104

105105
ReferenceLogController.addReferenceLog(references, project)
106106

107107
// Taken from https://intellij-support.jetbrains.com/hc/en-us/community/posts/206118439-Refresh-after-external-changes-to-project-structure-and-sources
108-
VfsUtil.markDirtyAndRefresh(true, true, true, context.projectRoot)
108+
VfsUtil.markDirtyAndRefresh(true, true, true, context.currentRoot)
109109
}
110110

111111
suspend fun send(msg: String): Interaction {

plugins/amazonq/chat/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/session/SessionTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ class SessionTest : FeatureDevTestBase() {
9191
val mockNewFile = listOf(NewFileZipInfo("test.ts", "testContent", false))
9292
val mockDeletedFile = listOf(DeletedFileInfo("deletedTest.ts", false))
9393

94-
session.context.projectRoot = mock()
95-
whenever(session.context.projectRoot.toNioPath()).thenReturn(Path(""))
94+
session.context.currentRoot = mock()
95+
whenever(session.context.currentRoot.toNioPath()).thenReturn(Path(""))
9696

9797
session.insertChanges(mockNewFile, mockDeletedFile, emptyList())
9898

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/FeatureDevSessionContext.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ class FeatureDevSessionContext(val project: Project) {
6161
"dist/"
6262
).map { Regex(it) }
6363

64-
private var _projectRoot = project.guessProjectDir() ?: error("Cannot guess base directory for project ${project.name}")
64+
val projectRoot = project.guessProjectDir() ?: error("Cannot guess base directory for project ${project.name}")
65+
private var _currentRoot = projectRoot
6566
private var ignorePatternsWithGitIgnore = emptyList<Regex>()
66-
private val gitIgnoreFile = File(projectRoot.path, ".gitignore")
67+
private val gitIgnoreFile = File(currentRoot.path, ".gitignore")
6768

6869
init {
6970
ignorePatternsWithGitIgnore = (ignorePatterns + parseGitIgnore().map { Regex(it) }).toList()
@@ -72,7 +73,7 @@ class FeatureDevSessionContext(val project: Project) {
7273
fun getProjectZip(): ZipCreationResult {
7374
val zippedProject = runBlocking {
7475
withBackgroundProgress(project, message("amazonqFeatureDev.create_plan.background_progress_title")) {
75-
zipFiles(projectRoot)
76+
zipFiles(currentRoot)
7677
}
7778
}
7879
val checkSum256: String = Base64.getEncoder().encodeToString(DigestUtils.sha256(FileInputStream(zippedProject)))
@@ -152,11 +153,11 @@ class FeatureDevSessionContext(val project: Project) {
152153
.replace("*", ".*")
153154
.let { if (it.endsWith("/")) "$it?" else it } // Handle directory-specific patterns by optionally matching trailing slash
154155

155-
var projectRoot: VirtualFile
156+
var currentRoot: VirtualFile
156157
set(newRoot) {
157-
_projectRoot = newRoot
158+
_currentRoot = newRoot
158159
}
159-
get() = _projectRoot
160+
get() = _currentRoot
160161
}
161162

162163
data class ZipCreationResult(val payload: File, val checksum: String, val contentLength: Long)

0 commit comments

Comments
 (0)