Skip to content

Commit

Permalink
feat: send ai fix feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
acke committed Sep 20, 2024
1 parent 6a45d00 commit cddf705
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/main/kotlin/io/snyk/plugin/ui/jcef/ApplyFixHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@ class ApplyFixHandler(private val project: Project) {
val applyFixQuery = JBCefJSQuery.create(jbCefBrowser)

applyFixQuery.addHandler { value ->
val params = value.split("|@", limit = 2)
val filePath = params[0] // Path to the file that needs to be patched
val patch = params[1] // The patch we received from LS
val params = value.split("|@", limit = 3)
val fixId = params[0] // Path to the file that needs to be patched
val filePath = params[1] // Path to the file that needs to be patched
val patch = params[2] // The patch we received from LS

// Avoid blocking the UI thread
runAsync {
Expand Down Expand Up @@ -86,6 +87,7 @@ class ApplyFixHandler(private val project: Project) {
}

}

return@addHandler JBCefJSQuery.Response("success")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,13 @@ class SuggestionDescriptionPanelFromLS(
if (!fixes.length) return;
const currentFix = fixes[diffSelectedIndex];
const fixId = currentFix.fixId;
console.log('currentFix', currentFix);
const filePath = getFilePathFromFix(currentFix);
const patch = currentFix.unifiedDiffsPerFile[filePath];
window.applyFixQuery(filePath + '|@' + patch);
window.applyFixQuery(fixId + '|@' + filePath + '|@' + patch);
// Following VSCode logic, the steps are:
// 1. Read the current file content.
Expand Down
16 changes: 15 additions & 1 deletion src/main/kotlin/snyk/common/lsp/LanguageServerWrapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package snyk.common.lsp

import com.google.gson.Gson
import com.google.gson.annotations.SerializedName
import com.google.gson.reflect.TypeToken
import com.intellij.openapi.Disposable
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.service
Expand Down Expand Up @@ -50,6 +49,7 @@ import org.jetbrains.concurrency.runAsync
import snyk.common.EnvironmentHelper
import snyk.common.getEndpointUrl
import snyk.common.lsp.commands.COMMAND_CODE_FIX_DIFFS
import snyk.common.lsp.commands.COMMAND_CODE_SUBMIT_FIX_FEEDBACK
import snyk.common.lsp.commands.COMMAND_COPY_AUTH_LINK
import snyk.common.lsp.commands.COMMAND_EXECUTE_CLI
import snyk.common.lsp.commands.COMMAND_GET_ACTIVE_USER
Expand Down Expand Up @@ -555,6 +555,20 @@ class LanguageServerWrapper(
}


fun submitAutofixFeedbackCommand(fixId: String, feedback: String) {
if (!ensureLanguageServerInitialized()) return

try {
val param = ExecuteCommandParams()
param.command = COMMAND_CODE_SUBMIT_FIX_FEEDBACK
param.arguments = listOf(fixId, feedback)
languageServer.workspaceService.executeCommand(param)
} catch (ignored: Exception) {
// do nothing to not break UX for analytics
}
}


private fun ensureLanguageServerProtocolVersion(project: Project) {
val protocolVersion = initializeResult?.serverInfo?.version
pluginSettings().currentLSProtocolVersion = protocolVersion?.toIntOrNull()
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/snyk/common/lsp/commands/Commands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ internal const val COMMAND_LOGOUT = "snyk.logout"
internal const val COMMAND_GET_SETTINGS_SAST_ENABLED = "snyk.getSettingsSastEnabled"
internal const val COMMAND_COPY_AUTH_LINK = "snyk.copyAuthLink"
internal const val COMMAND_CODE_FIX_DIFFS = "snyk.code.fixDiffs"
internal const val COMMAND_CODE_SUBMIT_FIX_FEEDBACK = "snyk.code.submitFixFeedback"

0 comments on commit cddf705

Please sign in to comment.