Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type" : "bugfix",
"description" : "Fix doc generation for modules that are a part of the project"
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import com.intellij.diff.util.DiffUserDataKeys
import com.intellij.ide.BrowserUtil
import com.intellij.openapi.application.runInEdt
import com.intellij.openapi.project.Project
import com.intellij.openapi.roots.ProjectRootManager
import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.openapi.vfs.VfsUtil
import com.intellij.openapi.wm.ToolWindowManager
import kotlinx.coroutines.withContext
Expand Down Expand Up @@ -68,6 +71,7 @@
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.session.SessionStatePhase
import software.aws.toolkits.jetbrains.services.amazonqFeatureDev.util.CancellationTokenSource
import software.aws.toolkits.resources.message
import java.nio.file.Paths
import java.util.UUID

enum class DocGenerationStep {
Expand Down Expand Up @@ -565,7 +569,7 @@
tabId = tabId,
followUp = listOf(
FollowUp(
pillText = message("amazonqFeatureDev.follow_up.modify_source_folder"),
pillText = message("amazonqDoc.prompt.folder.change"),
type = FollowUpTypes.MODIFY_DEFAULT_SOURCE_FOLDER,
status = FollowUpStatusType.Info,
)
Expand Down Expand Up @@ -635,7 +639,7 @@
listOf(
FollowUp(
pillText = message("amazonqDoc.prompt.review.accept"),
prompt = message("amazonqDoc.prompt.review.accept"),

Check warning on line 642 in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqDoc/controller/DocController.kt

View workflow job for this annotation

GitHub Actions / qodana

Usage of redundant or deprecated syntax or deprecated symbols

'message(String, vararg Any): String' is deprecated. Use extension-specific localization bundle instead
status = FollowUpStatusType.Success,
type = FollowUpTypes.ACCEPT_CHANGES,
icon = FollowUpIcons.Ok,
Expand Down Expand Up @@ -895,30 +899,53 @@
}
}

private fun isFolderPathInProjectModules(project: Project, folderPath: String): Boolean {
val path = Paths.get(folderPath)
val virtualFile = LocalFileSystem.getInstance().findFileByIoFile(path.toFile()) ?: return false

val projectFileIndex = ProjectRootManager.getInstance(project).fileIndex

return projectFileIndex.isInProject(virtualFile)
}

private suspend fun modifyDefaultSourceFolder(tabId: String) {
val session = getSessionInfo(tabId)
val currentSourceFolder = session.context.selectedSourceFolder
val projectRoot = session.context.projectRoot

withContext(EDT) {
val selectedFolder = selectFolder(context.project, currentSourceFolder)

// No folder was selected
if (selectedFolder == null) {
logger.info { "Cancelled dialog and not selected any folder" }
return@withContext
}

// The folder is not in the workspace
if (!selectedFolder.path.startsWith(projectRoot.path)) {
val isFolderPathInProject = isFolderPathInProjectModules(context.project, selectedFolder.path)

if (!isFolderPathInProject) {
logger.info { "Selected folder not in workspace: ${selectedFolder.path}" }

messenger.sendAnswer(
tabId = tabId,
messageType = DocMessageType.Answer,
message = message("amazonqFeatureDev.follow_up.incorrect_source_folder"),
followUp = listOf(
FollowUp(
pillText = message("amazonqDoc.prompt.folder.change"),
type = FollowUpTypes.MODIFY_DEFAULT_SOURCE_FOLDER,
status = FollowUpStatusType.Info,
)
),
snapToTop = true
)

messenger.sendChatInputEnabledMessage(tabId, enabled = false)

return@withContext
}

if (selectedFolder.path == projectRoot.path) {
docGenerationTask.folderLevel = DocGenerationFolderLevel.ENTIRE_WORKSPACE
} else {
Expand Down
Loading