override suspend fun processFileClicked()

in plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonqFeatureDev/controller/FeatureDevController.kt [296:373]


    override suspend fun processFileClicked(message: IncomingFeatureDevMessage.FileClicked) {
        val fileToUpdate = message.filePath
        val session = getSessionInfo(message.tabId)
        val messageId = message.messageId
        val action = message.actionName

        var filePaths: List<NewFileZipInfo> = emptyList()
        var deletedFiles: List<DeletedFileInfo> = emptyList()
        var references: List<CodeReferenceGenerated> = emptyList()
        when (val state = session.sessionState) {
            is PrepareCodeGenerationState -> {
                filePaths = state.filePaths
                deletedFiles = state.deletedFiles
                references = state.references
            }
        }

        fun insertAction(): InsertAction =
            if (filePaths.all { it.changeApplied } && deletedFiles.all { it.changeApplied }) {
                InsertAction.AUTO_CONTINUE
            } else if (filePaths.all { it.changeApplied || it.rejected } && deletedFiles.all { it.changeApplied || it.rejected }) {
                InsertAction.CONTINUE
            } else if (filePaths.any { it.changeApplied || it.rejected } || deletedFiles.any { it.changeApplied || it.rejected }) {
                InsertAction.REMAINING
            } else {
                InsertAction.ALL
            }

        val prevInsertAction = insertAction()

        if (action == "accept-change") {
            session.insertChanges(
                filePaths = filePaths.filter { it.zipFilePath == fileToUpdate },
                deletedFiles = deletedFiles.filter { it.zipFilePath == fileToUpdate },
                references = references, // Add all references (not attributed per-file)
            )

            AmazonqTelemetry.isAcceptedCodeChanges(
                amazonqNumberOfFilesAccepted = 1.0,
                amazonqConversationId = session.conversationId,
                enabled = true,
                credentialStartUrl = getStartUrl(project = context.project)
            )
        } else {
            // Mark the file as rejected or not depending on the previous state
            filePaths.find { it.zipFilePath == fileToUpdate }?.let { it.rejected = !it.rejected }
            deletedFiles.find { it.zipFilePath == fileToUpdate }?.let { it.rejected = !it.rejected }
        }

        messenger.updateFileComponent(message.tabId, filePaths, deletedFiles, messageId)

        // Then, if the accepted file is not a deletion, open a diff to show the changes are applied:
        if (action == "accept-change" && deletedFiles.none { it.zipFilePath == fileToUpdate }) {
            var pollAttempt = 0
            val pollDelayMs = 10L
            while (pollAttempt < 5) {
                val file = VfsUtil.findRelativeFile(message.filePath, session.context.addressableRoot)
                // Wait for the file to be created and/or updated to the new content:
                if (file != null && file.content() == filePaths.find { it.zipFilePath == fileToUpdate }?.fileContent) {
                    // Open a diff, showing the changes have been applied and the file now has identical left/right state:
                    this.processOpenDiff(IncomingFeatureDevMessage.OpenDiff(message.tabId, fileToUpdate, false))
                    break
                } else {
                    pollAttempt++
                    delay(pollDelayMs)
                }
            }
        }

        val nextInsertAction = insertAction()
        if (nextInsertAction == InsertAction.AUTO_CONTINUE) {
            // Insert remaining changes (noop, as there are none), and advance to the next prompt:
            insertCode(message.tabId)
        } else if (nextInsertAction != prevInsertAction) {
            // Update the action displayed to the customer based on the current state:
            messenger.sendSystemPrompt(message.tabId, getFollowUpOptions(session.sessionState.phase, nextInsertAction))
        }
    }