From d2ed25119f4147b764d0bba4c8cf7f93c0d74a9e Mon Sep 17 00:00:00 2001 From: Rik Nauta Date: Mon, 26 Aug 2024 15:56:46 +0200 Subject: [PATCH 1/3] Lower Cody CodeActions priority as a temporary workaround --- .../cody/inspections/CodeActionQuickFix.kt | 26 ++++++++++++------- .../cody/inspections/CodyFixHighlightPass.kt | 2 +- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/com/sourcegraph/cody/inspections/CodeActionQuickFix.kt b/src/main/kotlin/com/sourcegraph/cody/inspections/CodeActionQuickFix.kt index 6825b9a5f3..21034ad34a 100644 --- a/src/main/kotlin/com/sourcegraph/cody/inspections/CodeActionQuickFix.kt +++ b/src/main/kotlin/com/sourcegraph/cody/inspections/CodeActionQuickFix.kt @@ -2,34 +2,36 @@ package com.sourcegraph.cody.inspections import com.intellij.codeInsight.intention.IntentionAction import com.intellij.codeInsight.intention.PriorityAction +import com.intellij.codeInspection.HintAction import com.intellij.openapi.editor.Editor import com.intellij.openapi.project.Project import com.intellij.psi.PsiFile import com.sourcegraph.cody.agent.CodyAgentService import com.sourcegraph.cody.agent.protocol_generated.CodeActions_ProvideParams import com.sourcegraph.cody.agent.protocol_generated.CodeActions_TriggerParams +import com.sourcegraph.cody.agent.protocol_generated.ProtocolCodeAction import com.sourcegraph.cody.agent.protocol_generated.ProtocolLocation import com.sourcegraph.cody.edit.actions.EditCodeAction data class CodeActionQuickFixParams( - val title: String, - val kind: String?, + val action: ProtocolCodeAction, val location: ProtocolLocation, ) class CodeActionQuickFix(private val params: CodeActionQuickFixParams) : - IntentionAction, PriorityAction { + IntentionAction, HintAction, PriorityAction { companion object { const val FAMILY_NAME = "Cody Code Action" } override fun getPriority(): PriorityAction.Priority { return if (isFixAction()) { - PriorityAction.Priority.TOP + PriorityAction.Priority.NORMAL } else if (isExplainAction()) { PriorityAction.Priority.LOW } else { - PriorityAction.Priority.HIGH + if (params.action.isPreferred == true) PriorityAction.Priority.NORMAL + else PriorityAction.Priority.LOW } } @@ -39,17 +41,17 @@ class CodeActionQuickFix(private val params: CodeActionQuickFixParams) : } override fun getText(): String { - return params.title + return params.action.title } private fun isFixAction(): Boolean { // TODO: Ideally we have some flag indicating the semantic action type - return params.title.lowercase() == "ask cody to fix" + return params.action.title.lowercase() == "ask cody to fix" } private fun isExplainAction(): Boolean { // TODO: Ideally we have some flag indicating the semantic action type - return params.title.lowercase() == "ask cody to explain" + return params.action.title.lowercase() == "ask cody to explain" } private fun isKnownAction(): Boolean { @@ -94,7 +96,9 @@ class CodeActionQuickFix(private val params: CodeActionQuickFixParams) : CodeActions_ProvideParams(location = params.location, triggerKind = "Invoke")) .get() val action = - provideResponse.codeActions.find { it.title == params.title && it.kind == params.kind } + provideResponse.codeActions.find { + it.title == params.action.title && it.kind == params.action.kind + } if (action == null) { // TODO: handle this with a user notification throw Exception("Could not find action") @@ -104,4 +108,8 @@ class CodeActionQuickFix(private val params: CodeActionQuickFixParams) : EditCodeAction.completedEditTasks[result.id] = result } } + + override fun showHint(editor: Editor): Boolean { + return true + } } diff --git a/src/main/kotlin/com/sourcegraph/cody/inspections/CodyFixHighlightPass.kt b/src/main/kotlin/com/sourcegraph/cody/inspections/CodyFixHighlightPass.kt index 270111f082..911c63ec4f 100644 --- a/src/main/kotlin/com/sourcegraph/cody/inspections/CodyFixHighlightPass.kt +++ b/src/main/kotlin/com/sourcegraph/cody/inspections/CodyFixHighlightPass.kt @@ -122,7 +122,7 @@ class CodyFixHighlightPass(val file: PsiFile, val editor: Editor) : .get() myRangeActions[range] = provideResponse.codeActions.map { - CodeActionQuickFixParams(title = it.title, kind = it.kind, location = location) + CodeActionQuickFixParams(action = it, location = location) } } done.complete(Unit) From 855f043b04b7c52df31d5d423087d0c98a1ea0d2 Mon Sep 17 00:00:00 2001 From: Piotr Kukielka Date: Tue, 27 Aug 2024 17:44:09 +0200 Subject: [PATCH 2/3] Update recordings --- .../recording.har.yaml | 142 +++++++++--------- 1 file changed, 71 insertions(+), 71 deletions(-) diff --git a/src/integrationTest/resources/recordings/integration-test_2927926756/recording.har.yaml b/src/integrationTest/resources/recordings/integration-test_2927926756/recording.har.yaml index 31b26cc7e3..594b14b121 100644 --- a/src/integrationTest/resources/recordings/integration-test_2927926756/recording.har.yaml +++ b/src/integrationTest/resources/recordings/integration-test_2927926756/recording.har.yaml @@ -47,7 +47,7 @@ log: cookies: [] headers: - name: date - value: Mon, 26 Aug 2024 10:05:41 GMT + value: Tue, 27 Aug 2024 16:11:35 GMT - name: content-type value: text/plain; charset=utf-8 - name: transfer-encoding @@ -78,7 +78,7 @@ log: redirectURL: "" status: 200 statusText: OK - startedDateTime: 2024-08-26T10:05:40.912Z + startedDateTime: 2024-08-27T16:11:35.513Z time: 0 timings: blocked: -1 @@ -105,7 +105,7 @@ log: - name: user-agent value: JetBrains / 6.0-localbuild - name: traceparent - value: 00-b653d1c65c87be9d81056ad71062af9b-89635f314a35f7a1-01 + value: 00-c16d52d9ac2338da14cde4f385fc347a-e5fe4e0f5c243153-01 - name: connection value: keep-alive - name: host @@ -206,14 +206,14 @@ log: value: 6.0-localbuild url: https://sourcegraph.com/.api/completions/stream?api-version=1&client-name=jetbrains&client-version=6.0-localbuild response: - bodySize: 1966 + bodySize: 1837 content: mimeType: text/event-stream - size: 1966 + size: 1837 text: >+ event: completion - data: {"completion":"\n/**\n * This import statement brings in the Java Standard Library classes for working with Lists and other collection types.\n */\n","stopReason":"stop_sequence"} + data: {"completion":"/**\n * Imports the necessary Java utility classes, including {@link java.util.List} and {@link java.util.ArrayList}.\n */","stopReason":"stop_sequence"} event: done @@ -223,7 +223,7 @@ log: cookies: [] headers: - name: date - value: Mon, 26 Aug 2024 10:05:43 GMT + value: Tue, 27 Aug 2024 16:11:38 GMT - name: content-type value: text/event-stream - name: transfer-encoding @@ -252,7 +252,7 @@ log: redirectURL: "" status: 200 statusText: OK - startedDateTime: 2024-08-26T10:05:42.406Z + startedDateTime: 2024-08-27T16:11:37.009Z time: 0 timings: blocked: -1 @@ -312,17 +312,17 @@ log: value: null url: https://sourcegraph.com/.api/graphql?ContextFilters response: - bodySize: 107 + bodySize: 114 content: encoding: base64 mimeType: application/json - size: 107 + size: 114 text: "[\"H4sIAAAAAAAAA6pWSkks\",\"SVSyqlYqzixJBdHJ+SmVzvl5JakVJW6ZOSWpRcUg0aLE\ - ciWrvNKcnNra2loAAAAA//8DADYuyGU1AAAA\"]" + ciWrvNKcnNra2loAAAAA//8=\",\"AwA2LshlNQAAAA==\"]" cookies: [] headers: - name: date - value: Mon, 26 Aug 2024 10:05:41 GMT + value: Tue, 27 Aug 2024 16:11:36 GMT - name: content-type value: application/json - name: transfer-encoding @@ -353,7 +353,7 @@ log: redirectURL: "" status: 200 statusText: OK - startedDateTime: 2024-08-26T10:05:41.361Z + startedDateTime: 2024-08-27T16:11:35.893Z time: 0 timings: blocked: -1 @@ -440,15 +440,13 @@ log: cookies: [] headers: - name: date - value: Mon, 26 Aug 2024 10:05:40 GMT + value: Tue, 27 Aug 2024 16:11:34 GMT - name: content-type value: application/json - name: transfer-encoding value: chunked - name: connection value: keep-alive - - name: retry-after - value: "1" - name: access-control-allow-credentials value: "true" - name: access-control-allow-origin @@ -468,12 +466,12 @@ log: value: max-age=31536000; includeSubDomains; preload - name: content-encoding value: gzip - headersSize: 1438 + headersSize: 1333 httpVersion: HTTP/1.1 redirectURL: "" status: 200 statusText: OK - startedDateTime: 2024-08-26T10:05:40.167Z + startedDateTime: 2024-08-27T16:11:34.617Z time: 0 timings: blocked: -1 @@ -533,26 +531,28 @@ log: value: null url: https://sourcegraph.com/.api/graphql?CurrentSiteCodyLlmConfiguration response: - bodySize: 139 + bodySize: 132 content: encoding: base64 mimeType: application/json - size: 139 + size: 132 text: "[\"H4sIAAAAAAAAA6pWSkksSVSyqlYqzixJBdHJ+SmVPj6+zvl5aZnppUWJJZn5eWD53MSiE\ - uf8vJLUipLwzLyU/HIlK6XUvMSknNQUpdra2loAAAAA//8=\",\"AwDoCDSlSwAAAA==\ - \"]" + uf8vJLUipLwzLyU/HIlK6XUvMSknNQUpdra2loAAAAA//8DAOgINKVLAAAA\"]" + textDecoded: + data: + site: + codyLLMConfiguration: + smartContextWindow: enabled cookies: [] headers: - name: date - value: Mon, 26 Aug 2024 10:05:40 GMT + value: Tue, 27 Aug 2024 16:11:34 GMT - name: content-type value: application/json - name: transfer-encoding value: chunked - name: connection value: keep-alive - - name: retry-after - value: "1" - name: access-control-allow-credentials value: "true" - name: access-control-allow-origin @@ -572,12 +572,12 @@ log: value: max-age=31536000; includeSubDomains; preload - name: content-encoding value: gzip - headersSize: 1438 + headersSize: 1333 httpVersion: HTTP/1.1 redirectURL: "" status: 200 statusText: OK - startedDateTime: 2024-08-26T10:05:40.199Z + startedDateTime: 2024-08-27T16:11:34.652Z time: 0 timings: blocked: -1 @@ -637,25 +637,28 @@ log: value: null url: https://sourcegraph.com/.api/graphql?CurrentSiteCodyLlmProvider response: - bodySize: 131 + bodySize: 128 content: encoding: base64 mimeType: application/json - size: 131 + size: 128 text: "[\"H4sIAAAAAAAAA6pWSkksSVSyqlYqzixJBdHJ+SmVPj6+zvl5aZnppUWJJZn5eSDxgqL8s\ - syU1CIlK6Xi/NKi5NT0osSCDKXa2tpaAAAAAP//\",\"AwAfFAXARQAAAA==\"]" + syU1CIlK6Xi/NKi5NT0osSCDKXa2tpaAAAAAP//AwAfFAXARQAAAA==\"]" + textDecoded: + data: + site: + codyLLMConfiguration: + provider: sourcegraph cookies: [] headers: - name: date - value: Mon, 26 Aug 2024 10:05:40 GMT + value: Tue, 27 Aug 2024 16:11:34 GMT - name: content-type value: application/json - name: transfer-encoding value: chunked - name: connection value: keep-alive - - name: retry-after - value: "1" - name: access-control-allow-credentials value: "true" - name: access-control-allow-origin @@ -675,12 +678,12 @@ log: value: max-age=31536000; includeSubDomains; preload - name: content-encoding value: gzip - headersSize: 1438 + headersSize: 1333 httpVersion: HTTP/1.1 redirectURL: "" status: 200 statusText: OK - startedDateTime: 2024-08-26T10:05:40.183Z + startedDateTime: 2024-08-27T16:11:34.634Z time: 0 timings: blocked: -1 @@ -751,29 +754,39 @@ log: value: null url: https://sourcegraph.com/.api/graphql?CurrentUser response: - bodySize: 383 + bodySize: 376 content: encoding: base64 mimeType: application/json - size: 383 + size: 376 text: "[\"H4sIAAAAAAAAA2RPy07CQBT9l7tuaQ1R2klIFAQXaOMjNBjj4nZ6aaePmToPFJr+O2kwc\ eHunJzHvaeHHC0C64E7rUnarSE9UpEDg3SXNLxSp+T+5eqp4nPwoESTkhZ7QfmqRdEA\ s9qRB7kwXYPHBFsCBm/KaU6Fxq5cKOvHYRiCB86QlheD+TNkysa1v5ffrQMP8IAW9fb\ 1ERiU1naGBUFTTieFUkVDYwNX0pK0E67aAIO7ZREpvlnjV/ZOblFn1XW+Xp1+omyXRj\ gTU5Nmm2XynM4eQnc81HMT3/gcPOi0aFEff0f0QBfw77PbYhTGazB4oHSBUpzQCiXNG\ - JMqJwPs43MYhuEMAAD//w==\",\"AwBKjJM/TgEAAA==\"]" + JMqJwPs43MYhuEMAAD//wMASoyTP04BAAA=\"]" + textDecoded: + data: + currentUser: + avatarURL: https://lh3.googleusercontent.com/a/ACg8ocKFaqbYeuBkbj5dFEzx8bXV8a7i3sVbKCNPV7G0uyvk=s96-c + displayName: SourcegraphBot-9000 + hasVerifiedEmail: true + id: VXNlcjozNDQ1Mjc= + organizations: + nodes: [] + primaryEmail: + email: sourcegraphbot9k@gmail.com + username: sourcegraphbot9k-fnwmu cookies: [] headers: - name: date - value: Mon, 26 Aug 2024 10:05:40 GMT + value: Tue, 27 Aug 2024 16:11:34 GMT - name: content-type value: application/json - name: transfer-encoding value: chunked - name: connection value: keep-alive - - name: retry-after - value: "1" - name: access-control-allow-credentials value: "true" - name: access-control-allow-origin @@ -793,12 +806,12 @@ log: value: max-age=31536000; includeSubDomains; preload - name: content-encoding value: gzip - headersSize: 1438 + headersSize: 1333 httpVersion: HTTP/1.1 redirectURL: "" status: 200 statusText: OK - startedDateTime: 2024-08-26T10:05:40.216Z + startedDateTime: 2024-08-27T16:11:34.669Z time: 0 timings: blocked: -1 @@ -862,36 +875,25 @@ log: value: null url: https://sourcegraph.com/.api/graphql?CurrentUserCodySubscription response: - bodySize: 228 + bodySize: 234 content: encoding: base64 mimeType: application/json - size: 228 - text: "[\"H4sIAAAAAAAAA1zMsQrCMBSF4Xc5c4U2dtBsRToIgqWtDm6xyRCoSbi5GUrJu4uCoI7n5\ - +Os0IoV5IopERnHl2joPb1ehnSPE9nA1rtXi6w4RUg0h/F4bVEgzMpBouvPKKBCmJeO\ - fK/YnOzDcoRkSqb4fHeGrNcDK+KGISFKUW/K3aaqRyFkVcmtuOFPt05/2f2vzTnnJwA\ - AAP//AwBSGHacwgAAAA==\"]" - textDecoded: - data: - currentUser: - codySubscription: - applyProRateLimits: true - currentPeriodEndAt: 2024-09-14T22:11:32Z - currentPeriodStartAt: 2024-08-14T22:11:32Z - plan: PRO - status: ACTIVE + size: 234 + text: "[\"H4sIAAAAAAAAA1zMsQrC\",\"MBSF4Xc5c4U2dtBsRToIgqWtDm6xyRCoSbi5GUrJu4uC\ + oI7n5+Os0IoV5IopERnHl2joPb1ehnSPE9nA1rtXi6w4RUg0h/F4bVEgzMpBouvPKKB\ + CmJeOfK/YnOzDcoRkSqb4fHeGrNcDK+KGISFKUW/K3aaqRyFkVcmtuOFPt05/2f2vzT\ + nnJwAAAP//\",\"AwBSGHacwgAAAA==\"]" cookies: [] headers: - name: date - value: Mon, 26 Aug 2024 10:05:40 GMT + value: Tue, 27 Aug 2024 16:11:35 GMT - name: content-type value: application/json - name: transfer-encoding value: chunked - name: connection value: keep-alive - - name: retry-after - value: "1" - name: access-control-allow-credentials value: "true" - name: access-control-allow-origin @@ -911,12 +913,12 @@ log: value: max-age=31536000; includeSubDomains; preload - name: content-encoding value: gzip - headersSize: 1438 + headersSize: 1333 httpVersion: HTTP/1.1 redirectURL: "" status: 200 statusText: OK - startedDateTime: 2024-08-26T10:05:40.442Z + startedDateTime: 2024-08-27T16:11:34.922Z time: 0 timings: blocked: -1 @@ -979,24 +981,22 @@ log: encoding: base64 mimeType: application/json size: 136 - text: "[\"H4sIAAAAAAAAA6pWSkksSVSyqlYqzixJBdEFRfkppcklYalFxZn5eUpWSkYWFmYG5vFGB\ - kYmugYWukZG8aZ6ZrrGxmlJlhbJpgYmFilKtbW1AAAAAP//AwCvLlq5SQAAAA==\"]" + text: "[\"H4sIAAAAAAAAA6pWSkksSVSyqlYqzixJBdEFRfkppcklYalFxZn5eUpWSkYWFpZmRvFGB\ + kYmugYWukbm8aZ6ZrpJqSZGZslGKSamJgZKtbW1AAAAAP//AwBCoM+KSQAAAA==\"]" textDecoded: data: site: - productVersion: 288607_2024-08-22_5.6-33fb98c5048d + productVersion: 288962_2024-08-27_5.6-be426c2d4540 cookies: [] headers: - name: date - value: Mon, 26 Aug 2024 10:05:40 GMT + value: Tue, 27 Aug 2024 16:11:34 GMT - name: content-type value: application/json - name: transfer-encoding value: chunked - name: connection value: keep-alive - - name: retry-after - value: "1" - name: access-control-allow-credentials value: "true" - name: access-control-allow-origin @@ -1016,12 +1016,12 @@ log: value: max-age=31536000; includeSubDomains; preload - name: content-encoding value: gzip - headersSize: 1438 + headersSize: 1333 httpVersion: HTTP/1.1 redirectURL: "" status: 200 statusText: OK - startedDateTime: 2024-08-26T10:05:40.131Z + startedDateTime: 2024-08-27T16:11:34.580Z time: 0 timings: blocked: -1 From 15bd9e703c22f3299ab60c4bfe0711d086cbe07c Mon Sep 17 00:00:00 2001 From: Piotr Kukielka Date: Tue, 27 Aug 2024 19:05:03 +0200 Subject: [PATCH 3/3] Additional test check to make debugging failing tests easier --- .../com/sourcegraph/cody/util/CodyIntegrationTextFixture.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/integrationTest/kotlin/com/sourcegraph/cody/util/CodyIntegrationTextFixture.kt b/src/integrationTest/kotlin/com/sourcegraph/cody/util/CodyIntegrationTextFixture.kt index 1ec0e0c4b8..fe9c3b6798 100644 --- a/src/integrationTest/kotlin/com/sourcegraph/cody/util/CodyIntegrationTextFixture.kt +++ b/src/integrationTest/kotlin/com/sourcegraph/cody/util/CodyIntegrationTextFixture.kt @@ -136,6 +136,7 @@ open class CodyIntegrationTextFixture : BasePlatformTestCase(), LensListener { AnActionEvent.createFromAnAction(action, null, "", createEditorContext(myFixture.editor)) action.update(event) val presentation = event.presentation + assertEquals("Action description should be empty", "", presentation.description) assertTrue("Action should be enabled", presentation.isEnabled) assertTrue("Action should be visible", presentation.isVisible) }