Skip to content

Commit

Permalink
fix: post merge cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
acke committed Sep 21, 2024
1 parent cddf705 commit 1294a5f
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 38 deletions.
32 changes: 2 additions & 30 deletions src/main/kotlin/io/snyk/plugin/ui/jcef/ApplyFixHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,40 +17,15 @@ import io.snyk.plugin.ui.SnykBalloonNotificationHelper
import snyk.common.lsp.LanguageServerWrapper
import java.io.IOException

data class DiffPatch(
val originalFile: String,
val fixedFile: String,
val hunks: List<Hunk>
)

data class Hunk(
val startLineOriginal: Int,
val numLinesOriginal: Int,
val startLineFixed: Int,
val numLinesFixed: Int,
val changes: List<Change>
)

sealed class Change {
data class Addition(val line: String) : Change()
data class Deletion(val line: String) : Change()
data class Context(val line: String) : Change() // Unchanged line for context
}

class ApplyFixHandler(private val project: Project) {

private val enableDebug = Logger.getInstance("Snyk Language Server").isDebugEnabled
private val enableTrace = Logger.getInstance("Snyk Language Server").isTraceEnabled
private val logger = Logger.getInstance(this::class.java)

val logger = Logger.getInstance(this::class.java).apply {
// tie log level to language server log level
val languageServerWrapper = LanguageServerWrapper.getInstance()
if (languageServerWrapper.logger.isDebugEnabled) this.setLevel(LogLevel.DEBUG)
if (languageServerWrapper.logger.isTraceEnabled) this.setLevel(LogLevel.TRACE)
}


fun generateApplyFixCommand(jbCefBrowser: JBCefBrowserBase): CefLoadHandlerAdapter {
val applyFixQuery = JBCefJSQuery.create(jbCefBrowser)

Expand All @@ -77,6 +52,7 @@ class ApplyFixHandler(private val project: Project) {
window.receiveApplyFixResponse(true);
""".trimIndent()
jbCefBrowser.cefBrowser.executeJavaScript(script, jbCefBrowser.cefBrowser.url, 0)
LanguageServerWrapper.getInstance().submitAutofixFeedbackCommand(fixId, "FIX_APPLIED")
} else {
val errorMessage = "Error applying fix: ${result.exceptionOrNull()?.message}"
SnykBalloonNotificationHelper.showError(errorMessage, project)
Expand All @@ -85,7 +61,6 @@ class ApplyFixHandler(private val project: Project) {
""".trimIndent()
jbCefBrowser.cefBrowser.executeJavaScript(errorScript, jbCefBrowser.cefBrowser.url, 0)
}

}

return@addHandler JBCefJSQuery.Response("success")
Expand Down Expand Up @@ -128,11 +103,8 @@ class ApplyFixHandler(private val project: Project) {
SnykBalloonNotificationHelper.showError(errorMessage, project)
return@runWriteCommandAction
}
Result.success(Unit)
} catch (e: Exception) {
log("[applyPatchAndSave] Error applying patch to: $filePath. e: $e")
Result.failure(e)
}

return Result.success(Unit)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,6 @@ class SuggestionDescriptionPanelFromLS(
nextDiffElem?.addEventListener("click", nextDiff);
previousDiffElem?.addEventListener("click", previousDiff);
nextDiffElem?.addEventListener("click", nextDiff);
previousDiffElem?.addEventListener("click", previousDiff);
// This function will be called once the response is received from the Language Server
window.receiveAIFixResponse = function (fixesResponse) {
fixes = [...fixesResponse];
Expand Down
5 changes: 0 additions & 5 deletions src/main/kotlin/snyk/common/lsp/LanguageServerWrapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -521,11 +521,6 @@ class LanguageServerWrapper(
return this.getFeatureFlagStatus("snykCodeConsistentIgnores")
}

data class Fix(
@SerializedName("fixId") val fixId: String,
@SerializedName("unifiedDiffsPerFile") val unifiedDiffsPerFile: Map<String, String>
)

@Suppress("UNCHECKED_CAST")
fun sendCodeFixDiffsCommand(folderURI: String, fileURI: String, issueID: String): List<Fix> {
if (!ensureLanguageServerInitialized()) return emptyList()
Expand Down

0 comments on commit 1294a5f

Please sign in to comment.