Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -15,6 +15,9 @@
import com.intellij.openapi.editor.Caret
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.fileEditor.FileEditorManager
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 @@ -81,6 +84,7 @@
import software.aws.toolkits.resources.message
import software.aws.toolkits.telemetry.AmazonqTelemetry
import software.aws.toolkits.telemetry.Result
import java.nio.file.Paths
import java.util.UUID

enum class DocGenerationStep {
Expand Down Expand Up @@ -674,7 +678,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 @@ -773,7 +777,7 @@
if (isDenyListedError || retriesRemaining(session) > 0) {
message("amazonqFeatureDev.code_generation.error_message")
} else {
message("amazonqFeatureDev.code_generation.no_retries.error_message")

Check warning on line 780 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
}
}

Expand Down Expand Up @@ -1002,6 +1006,15 @@
}
}

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
Expand All @@ -1012,6 +1025,7 @@

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

// No folder was selected
if (selectedFolder == null) {
logger.info { "Cancelled dialog and not selected any folder" }
Expand All @@ -1020,19 +1034,31 @@
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)

reason = ModifySourceFolderErrorReason.NotInWorkspaceFolder
return@withContext
}

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