Skip to content

Fix to trigger scans for only active editor text change. #4537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 1, 2024
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
Expand Up @@ -387,7 +387,6 @@ class CodeWhispererCodeScanManager(val project: Project) {
*/
fun addCodeScanUI(setSelected: Boolean = false) = runInEdt {
reset()
EditorFactory.getInstance().eventMulticaster.addDocumentListener(documentListener, project)
val problemsWindow = getProblemsWindow()
if (!problemsWindow.contentManager.contents.contains(codeScanIssuesContent)) {
problemsWindow.contentManager.addContent(codeScanIssuesContent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ package software.aws.toolkits.jetbrains.services.codewhisperer.codescan.listener
import com.intellij.openapi.editor.event.DocumentEvent
import com.intellij.openapi.editor.event.DocumentListener
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.openapi.fileEditor.FileEditorManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.TextRange
import com.intellij.openapi.vfs.isFile
import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.CodeWhispererCodeScanIssue
import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.CodeWhispererCodeScanManager
import software.aws.toolkits.jetbrains.services.codewhisperer.explorer.CodeWhispererExplorerActionManager
Expand All @@ -22,6 +24,9 @@ internal class CodeWhispererCodeScanDocumentListener(val project: Project) : Doc
val scanManager = CodeWhispererCodeScanManager.getInstance(project)
val treeModel = scanManager.getScanTree().model

val fileEditorManager = FileEditorManager.getInstance(project)
val activeEditor = fileEditorManager.selectedEditor

val editedTextRange = TextRange.create(event.offset, event.offset + event.oldLength)
val nodes = scanManager.getOverlappingScanNodes(file, editedTextRange)
nodes.forEach {
Expand All @@ -33,8 +38,8 @@ internal class CodeWhispererCodeScanDocumentListener(val project: Project) : Doc
issue.rangeHighlighter?.textAttributes = null
}
scanManager.updateScanNodes(file)

if (CodeWhispererExplorerActionManager.getInstance().isAutoEnabledForCodeScan() &&
if (activeEditor != null && activeEditor.file == file &&
file.isFile && CodeWhispererExplorerActionManager.getInstance().isAutoEnabledForCodeScan() &&
!CodeWhispererExplorerActionManager.getInstance().isMonthlyQuotaForCodeScansExceeded() &&
!isUserBuilderId(project)
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ package software.aws.toolkits.jetbrains.services.codewhisperer.codescan.listener
import com.intellij.openapi.editor.event.EditorFactoryEvent
import com.intellij.openapi.editor.event.EditorFactoryListener
import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.isFile
import software.aws.toolkits.jetbrains.services.codewhisperer.codescan.CodeWhispererCodeScanManager
import software.aws.toolkits.jetbrains.services.codewhisperer.explorer.CodeWhispererExplorerActionManager
import software.aws.toolkits.jetbrains.services.codewhisperer.explorer.isUserBuilderId
import software.aws.toolkits.jetbrains.services.codewhisperer.util.CodeWhispererConstants

internal class CodeWhispererCodeScanFileListener(val project: Project) : EditorFactoryListener {
override fun editorCreated(event: EditorFactoryEvent) {
if (!CodeWhispererExplorerActionManager.getInstance().isMonthlyQuotaForCodeScansExceeded() && !isUserBuilderId(project)) {
val actionManager = CodeWhispererExplorerActionManager.getInstance()
if (event.editor.virtualFile.isFile && actionManager.isAutoEnabledForCodeScan() &&
!actionManager.isMonthlyQuotaForCodeScansExceeded() && !isUserBuilderId(project)
) {
CodeWhispererCodeScanManager.getInstance(project).createDebouncedRunCodeScan(CodeWhispererConstants.CodeAnalysisScope.FILE)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ResumeCodeScans : DumbAwareAction(
val actionManager = CodeWhispererExplorerActionManager.getInstance()
actionManager.setAutoCodeScan(project, true)
// Run Proactive Code File Scan once toggle is enabled
if (!actionManager.isMonthlyQuotaForCodeScansExceeded() && !isUserBuilderId(project)) {
if (actionManager.isAutoEnabledForCodeScan() && !actionManager.isMonthlyQuotaForCodeScansExceeded() && !isUserBuilderId(project)) {
CodeWhispererCodeScanManager.getInstance(project).createDebouncedRunCodeScan(CodeWhispererConstants.CodeAnalysisScope.FILE)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ResumeCodeScanNode(nodeProject: Project) : CodeWhispererActionNode(
actionManager.setAutoCodeScan(project, true)

// Run Proactive Code File Scan once toggle is enabled
if (!actionManager.isMonthlyQuotaForCodeScansExceeded() && !isUserBuilderId(project)) {
if (actionManager.isAutoEnabledForCodeScan() && !actionManager.isMonthlyQuotaForCodeScansExceeded() && !isUserBuilderId(project)) {
CodeWhispererCodeScanManager.getInstance(project).createDebouncedRunCodeScan(CodeWhispererConstants.CodeAnalysisScope.FILE)
}
}
Expand Down
Loading