From 297d49390456db30b8ba5008b471af12f2dc133c Mon Sep 17 00:00:00 2001 From: DariusZdroba Date: Tue, 12 Nov 2024 16:10:28 +0200 Subject: [PATCH 1/8] fix: add iac ignore button --- .../snyk/plugin/cli/ConsoleCommandRunner.kt | 1 + .../io/snyk/plugin/services/CliAdapter.kt | 3 + .../plugin/ui/jcef/IgnoreInFileHandler.kt | 96 +++++++++++++++++++ .../toolwindow/panels/JCEFDescriptionPanel.kt | 56 ++++++++++- .../plugin/ui/jcef/IgnoreInFileHandlerTest.kt | 59 ++++++++++++ 5 files changed, 212 insertions(+), 3 deletions(-) create mode 100644 src/main/kotlin/io/snyk/plugin/ui/jcef/IgnoreInFileHandler.kt create mode 100644 src/test/kotlin/io/snyk/plugin/ui/jcef/IgnoreInFileHandlerTest.kt diff --git a/src/main/kotlin/io/snyk/plugin/cli/ConsoleCommandRunner.kt b/src/main/kotlin/io/snyk/plugin/cli/ConsoleCommandRunner.kt index 70bd701fd..d16246634 100644 --- a/src/main/kotlin/io/snyk/plugin/cli/ConsoleCommandRunner.kt +++ b/src/main/kotlin/io/snyk/plugin/cli/ConsoleCommandRunner.kt @@ -89,5 +89,6 @@ open class ConsoleCommandRunner { companion object { const val PROCESS_CANCELLED_BY_USER = "PROCESS_CANCELLED_BY_USER" + const val SAVING_POLICY_FILE = "Saving .snyk policy file...\n" } } diff --git a/src/main/kotlin/io/snyk/plugin/services/CliAdapter.kt b/src/main/kotlin/io/snyk/plugin/services/CliAdapter.kt index 976f96636..4bbef31ec 100644 --- a/src/main/kotlin/io/snyk/plugin/services/CliAdapter.kt +++ b/src/main/kotlin/io/snyk/plugin/services/CliAdapter.kt @@ -73,6 +73,9 @@ abstract class CliAdapter>(val project: Proj rawStr == ConsoleCommandRunner.PROCESS_CANCELLED_BY_USER -> { getProductResult(null) } + rawStr == ConsoleCommandRunner.SAVING_POLICY_FILE -> { + getProductResult(null) + } rawStr.isEmpty() -> { getErrorResult(CLI_PRODUCE_NO_OUTPUT) } diff --git a/src/main/kotlin/io/snyk/plugin/ui/jcef/IgnoreInFileHandler.kt b/src/main/kotlin/io/snyk/plugin/ui/jcef/IgnoreInFileHandler.kt new file mode 100644 index 000000000..76ef1d2fd --- /dev/null +++ b/src/main/kotlin/io/snyk/plugin/ui/jcef/IgnoreInFileHandler.kt @@ -0,0 +1,96 @@ +package io.snyk.plugin.ui.jcef + +import com.intellij.openapi.diagnostic.LogLevel +import com.intellij.openapi.diagnostic.Logger +import com.intellij.openapi.project.Project +import com.intellij.ui.jcef.JBCefBrowserBase +import com.intellij.ui.jcef.JBCefJSQuery +import io.snyk.plugin.runInBackground +import io.snyk.plugin.ui.SnykBalloonNotificationHelper +import org.cef.browser.CefBrowser +import org.cef.browser.CefFrame +import org.cef.handler.CefLoadHandlerAdapter +import snyk.common.IgnoreService +import snyk.common.lsp.LanguageServerWrapper +import java.io.File +import java.io.IOException + +class IgnoreInFileHandler( + private val project: Project, + ) { + 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 generateIgnoreInFileCommand(jbCefBrowser: JBCefBrowserBase): CefLoadHandlerAdapter { + val applyIgnoreInFileQuery = JBCefJSQuery.create(jbCefBrowser) + + applyIgnoreInFileQuery.addHandler { value -> + val params = value.split("|@", limit = 2) + val issueId = params[0] // ID of issue that needs to be ignored + val filePath = params[1] + // Computed path that will be used in the snyk ignore command for the --path arg + val computedPath = filePath.removePrefix("${project.basePath}${File.separator}") + // Avoid blocking the UI thread + runInBackground("Snyk: applying ignore...") { + val result = try { + applyIgnoreInFileAndSave(issueId, computedPath) + } catch (e: IOException) { + logger.error("Error ignoring in file: $filePath. e:$e") + Result.failure(e) + } catch (e: Exception) { + logger.error("Unexpected error applying ignore. e:$e") + Result.failure(e) + } + + if (result.isSuccess) { + val script = """ + window.receiveIgnoreInFileResponse(true); + """.trimIndent() + jbCefBrowser.cefBrowser.executeJavaScript(script, jbCefBrowser.cefBrowser.url, 0) + } else { + val errorMessage = "Error ignoring in file: ${result.exceptionOrNull()?.message}" + SnykBalloonNotificationHelper.showError(errorMessage, project) + val errorScript = """ + window.receiveIgnoreInFileResponse(false, "$errorMessage"); + """.trimIndent() + jbCefBrowser.cefBrowser.executeJavaScript(errorScript, jbCefBrowser.cefBrowser.url, 0) + } + } + + return@addHandler JBCefJSQuery.Response("success") + } + + return object : CefLoadHandlerAdapter() { + override fun onLoadEnd(browser: CefBrowser, frame: CefFrame, httpStatusCode: Int) { + if (frame.isMain) { + val script = """ + (function() { + if (window.applyIgnoreInFileQuery) { + return; + } + window.applyIgnoreInFileQuery = function(value) { ${applyIgnoreInFileQuery.inject("value")} }; + })(); + """.trimIndent() + browser.executeJavaScript(script, browser.url, 0) + } + } + } + } + + fun applyIgnoreInFileAndSave(issueId: String, filePath: String): Result { + val ignoreService = IgnoreService(project); + if (issueId != "" && filePath != "") { + ignoreService.ignoreInstance(issueId, filePath) + } else { + logger.error("[applyIgnoreInFileAndSave] Failed to find document for: $filePath") + val errorMessage = "Failed to find document for: $filePath" + SnykBalloonNotificationHelper.showError(errorMessage, project) + return Result.failure(IOException(errorMessage)) + } + return Result.success(Unit) + } +} diff --git a/src/main/kotlin/io/snyk/plugin/ui/toolwindow/panels/JCEFDescriptionPanel.kt b/src/main/kotlin/io/snyk/plugin/ui/toolwindow/panels/JCEFDescriptionPanel.kt index 30c58e465..6215b0da3 100644 --- a/src/main/kotlin/io/snyk/plugin/ui/toolwindow/panels/JCEFDescriptionPanel.kt +++ b/src/main/kotlin/io/snyk/plugin/ui/toolwindow/panels/JCEFDescriptionPanel.kt @@ -14,6 +14,7 @@ import io.snyk.plugin.ui.baseGridConstraintsAnchorWest import io.snyk.plugin.ui.descriptionHeaderPanel import io.snyk.plugin.ui.jcef.ApplyFixHandler import io.snyk.plugin.ui.jcef.GenerateAIFixHandler +import io.snyk.plugin.ui.jcef.IgnoreInFileHandler import io.snyk.plugin.ui.jcef.JCEFUtils import io.snyk.plugin.ui.jcef.LoadHandlerGenerator import io.snyk.plugin.ui.jcef.OpenFileLoadHandlerGenerator @@ -70,7 +71,16 @@ class SuggestionDescriptionPanelFromLS( loadHandlerGenerators += { applyFixHandler.generateApplyFixCommand(it) } + + } + ScanIssue.INFRASTRUCTURE_AS_CODE -> + { + val applyIgnoreInFileHandler = IgnoreInFileHandler(project) + loadHandlerGenerators +={ + applyIgnoreInFileHandler.generateIgnoreInFileCommand(it) + } } + } val html = this.getCustomCssAndScript() val jbCefBrowserComponent = @@ -165,13 +175,17 @@ class SuggestionDescriptionPanelFromLS( val editorColorsManager = EditorColorsManager.getInstance() val editorUiTheme = editorColorsManager.schemeForCurrentUITheme + val lsNonce = extractLsNonceIfPresent(html); + var nonce = getNonce() + if (lsNonce != "") { + nonce = lsNonce; + } html = html.replace("\${ideStyle}", "") html = html.replace("\${headerEnd}", "") html = html.replace("\${ideScript}", "") - val nonce = getNonce() html = html.replace("\${nonce}", nonce) html = html.replace("--default-font: ", "--default-font: \"${JBUI.Fonts.label().asPlain().family}\", ") html = html.replace("var(--text-color)", UIUtil.getLabelForeground().toHex()) @@ -199,7 +213,17 @@ class SuggestionDescriptionPanelFromLS( return html } - + private fun extractLsNonceIfPresent(html: String): String{ + // When the nonce is injected by the IDE, it is of format nonce-${nonce} + if (!html.contains("\${nonce}") && html.contains("nonce-")){ + val nonceStartPosition = html.indexOf("nonce-"); + // Length of LS nonce + val startIndex = nonceStartPosition + "nonce-".length; + val endIndex = startIndex + 24; + return html.substring(startIndex, endIndex ).trim(); + } + return ""; + } private fun getNonce(): String { val allowedChars = ('A'..'Z') + ('a'..'z') + ('0'..'9') return (1..32) @@ -341,9 +365,20 @@ class SuggestionDescriptionPanelFromLS( console.log('Applying fix', patch); } + function applyIgnoreInFile() { + console.log('Applying ignore', issue); + if (!issue) return; + + window.applyIgnoreInFileQuery(issue + '|@' + filePath + ' > ' + path); + toggleElement(ignoreInFileBtn, "hide"); + console.log('Applying ignore'); + } + // DOM element references const generateAiFixBtn = document.getElementById("generate-ai-fix"); const applyFixBtn = document.getElementById('apply-fix') + const ignoreContainer = document.getElementById("ignore-container"); + const ignoreInFileBtn = document.getElementById('ignore-file-issue') const retryGenerateFixBtn = document.getElementById('retry-generate-fix') const fixLoadingIndicatorElem = document.getElementById("fix-loading-indicator"); @@ -363,15 +398,19 @@ class SuggestionDescriptionPanelFromLS( let diffSelectedIndex = 0; let fixes = []; - + let issue = ignoreInFileBtn.getAttribute('issue') + let path = ignoreInFileBtn.getAttribute('path') + let filePath = ignoreInFileBtn.getAttribute('filePath') // Event listener for Generate AI fix button generateAiFixBtn?.addEventListener("click", generateAIFix); applyFixBtn?.addEventListener('click', applyFix); retryGenerateFixBtn?.addEventListener('click', reGenerateAIFix); + ignoreInFileBtn?.addEventListener("click", applyIgnoreInFile); nextDiffElem?.addEventListener("click", nextDiff); previousDiffElem?.addEventListener("click", previousDiff); + toggleElement(ignoreContainer, "show"); // This function will be called once the response is received from the Language Server window.receiveAIFixResponse = function (fixesResponse) { fixes = [...fixesResponse]; @@ -382,6 +421,17 @@ class SuggestionDescriptionPanelFromLS( showAIFixes(fixes); }; + window.receiveIgnoreInFileResponse = function (success){ + console.log('[[receiveIgnoreInFileResponse]]', success); + if(success){ + ignoreInFileBtn.disabled = true; + console.log('Ignored in file', success); + document.getElementById('ignore-file-issue').disabled = true; + }else{ + toggleElement(ignoreInFileBtn, "show"); + console.error('Failed to apply fix', success); + } + } window.receiveApplyFixResponse = function (success) { console.log('[[receiveApplyFixResponse]]', success); if (success) { diff --git a/src/test/kotlin/io/snyk/plugin/ui/jcef/IgnoreInFileHandlerTest.kt b/src/test/kotlin/io/snyk/plugin/ui/jcef/IgnoreInFileHandlerTest.kt new file mode 100644 index 000000000..199e37a1d --- /dev/null +++ b/src/test/kotlin/io/snyk/plugin/ui/jcef/IgnoreInFileHandlerTest.kt @@ -0,0 +1,59 @@ +package io.snyk.plugin.ui.jcef + +import com.intellij.openapi.application.WriteAction +import com.intellij.openapi.fileEditor.FileEditorManager +import com.intellij.openapi.vfs.VirtualFile +import com.intellij.psi.PsiFile +import com.intellij.testFramework.PlatformTestUtil +import com.intellij.testFramework.fixtures.BasePlatformTestCase +import io.mockk.every +import io.mockk.mockk +import io.mockk.unmockkAll +import io.mockk.verify +import io.snyk.plugin.resetSettings +import org.eclipse.lsp4j.ExecuteCommandParams +import org.eclipse.lsp4j.services.LanguageServer +import snyk.common.IgnoreService +import snyk.common.annotator.SnykCodeAnnotator +import snyk.common.annotator.SnykIaCAnnotator +import snyk.common.lsp.LanguageServerWrapper +import snyk.common.lsp.commands.COMMAND_EXECUTE_CLI +import java.io.File +import java.nio.file.Paths +import java.util.concurrent.CompletableFuture +import java.util.function.BooleanSupplier + +class IgnoreInFileHandlerTest : BasePlatformTestCase() { + private lateinit var ignorer: IgnoreInFileHandler + private val fileName = "fargate.json" + val lsMock = mockk() + + override fun getTestDataPath(): String { + val resource = SnykIaCAnnotator::class.java.getResource("/iac-test-results") + requireNotNull(resource) { "Make sure that the resource $resource exists!" } + return Paths.get(resource.toURI()).toString() + } + + override fun setUp() { + super.setUp() + unmockkAll() + resetSettings(project) + val languageServerWrapper = LanguageServerWrapper.getInstance() + languageServerWrapper.languageServer = lsMock + languageServerWrapper.isInitialized = true + ignorer = IgnoreInFileHandler(project) + } + + fun `test issue should be ignored in file`() { + every { lsMock.workspaceService.executeCommand(any()) } returns CompletableFuture.completedFuture(null) + val filePath = this.getTestDataPath()+ File.separator + fileName; + ignorer.applyIgnoreInFileAndSave("SNYK-CC-TF-61", filePath ) + val projectBasePath = project.basePath ?: ""; + + // Expected args for executeCommandParams + val args: List = arrayListOf(projectBasePath, "ignore", "--id=SNYK-CC-TF-61", "--path=${filePath}") + + val executeCommandParams = ExecuteCommandParams (COMMAND_EXECUTE_CLI, args); + verify { lsMock.workspaceService.executeCommand(executeCommandParams) } + } +} From 3ff7b951b8bd055ab7af3a261f00eb4e0ef0c214 Mon Sep 17 00:00:00 2001 From: DariusZdroba Date: Wed, 13 Nov 2024 09:48:49 +0200 Subject: [PATCH 2/8] chore: rename path variable --- .../toolwindow/panels/JCEFDescriptionPanel.kt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/io/snyk/plugin/ui/toolwindow/panels/JCEFDescriptionPanel.kt b/src/main/kotlin/io/snyk/plugin/ui/toolwindow/panels/JCEFDescriptionPanel.kt index 6215b0da3..c0408ac83 100644 --- a/src/main/kotlin/io/snyk/plugin/ui/toolwindow/panels/JCEFDescriptionPanel.kt +++ b/src/main/kotlin/io/snyk/plugin/ui/toolwindow/panels/JCEFDescriptionPanel.kt @@ -175,10 +175,10 @@ class SuggestionDescriptionPanelFromLS( val editorColorsManager = EditorColorsManager.getInstance() val editorUiTheme = editorColorsManager.schemeForCurrentUITheme - val lsNonce = extractLsNonceIfPresent(html); + val lsNonce = extractLsNonceIfPresent(html) var nonce = getNonce() if (lsNonce != "") { - nonce = lsNonce; + nonce = lsNonce } html = html.replace("\${ideStyle}", "") @@ -216,13 +216,13 @@ class SuggestionDescriptionPanelFromLS( private fun extractLsNonceIfPresent(html: String): String{ // When the nonce is injected by the IDE, it is of format nonce-${nonce} if (!html.contains("\${nonce}") && html.contains("nonce-")){ - val nonceStartPosition = html.indexOf("nonce-"); + val nonceStartPosition = html.indexOf("nonce-") // Length of LS nonce - val startIndex = nonceStartPosition + "nonce-".length; - val endIndex = startIndex + 24; - return html.substring(startIndex, endIndex ).trim(); + val startIndex = nonceStartPosition + "nonce-".length + val endIndex = startIndex + 24 + return html.substring(startIndex, endIndex ).trim() } - return ""; + return "" } private fun getNonce(): String { val allowedChars = ('A'..'Z') + ('a'..'z') + ('0'..'9') @@ -369,7 +369,7 @@ class SuggestionDescriptionPanelFromLS( console.log('Applying ignore', issue); if (!issue) return; - window.applyIgnoreInFileQuery(issue + '|@' + filePath + ' > ' + path); + window.applyIgnoreInFileQuery(issue + '|@' + filePath + ' > ' + resourcePath); toggleElement(ignoreInFileBtn, "hide"); console.log('Applying ignore'); } @@ -399,7 +399,7 @@ class SuggestionDescriptionPanelFromLS( let diffSelectedIndex = 0; let fixes = []; let issue = ignoreInFileBtn.getAttribute('issue') - let path = ignoreInFileBtn.getAttribute('path') + let resourcePath = ignoreInFileBtn.getAttribute('resourcePath') let filePath = ignoreInFileBtn.getAttribute('filePath') // Event listener for Generate AI fix button generateAiFixBtn?.addEventListener("click", generateAIFix); From 0e50aba6fe9a0bbf3430df2f5dd2a30a1733694b Mon Sep 17 00:00:00 2001 From: DariusZdroba Date: Wed, 13 Nov 2024 13:02:02 +0200 Subject: [PATCH 3/8] chore: update changelog --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a9ef4e8d..300b724fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,10 +5,9 @@ - If $/snyk.hasAuthenticated transmits an API URL, this is saved in the settings. - Add "plugin installed" analytics event (sent after authentication) - Added a description of custom endpoints to settings dialog. - +- Add option to ignore IaC issues ### Fixed - folder-specific configs are availabe on opening projects, not only on restart of the IDE - ## [2.10.0] ### Changed - save git folder config in settings From 118c51ba823284e74500c846ccf697521f7580a4 Mon Sep 17 00:00:00 2001 From: DariusZdroba Date: Wed, 13 Nov 2024 14:16:55 +0200 Subject: [PATCH 4/8] chore: use getContentRootPaths --- src/main/kotlin/io/snyk/plugin/ui/jcef/IgnoreInFileHandler.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/io/snyk/plugin/ui/jcef/IgnoreInFileHandler.kt b/src/main/kotlin/io/snyk/plugin/ui/jcef/IgnoreInFileHandler.kt index 76ef1d2fd..4434e1ec1 100644 --- a/src/main/kotlin/io/snyk/plugin/ui/jcef/IgnoreInFileHandler.kt +++ b/src/main/kotlin/io/snyk/plugin/ui/jcef/IgnoreInFileHandler.kt @@ -5,6 +5,7 @@ import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.project.Project import com.intellij.ui.jcef.JBCefBrowserBase import com.intellij.ui.jcef.JBCefJSQuery +import io.snyk.plugin.getContentRootPaths import io.snyk.plugin.runInBackground import io.snyk.plugin.ui.SnykBalloonNotificationHelper import org.cef.browser.CefBrowser @@ -33,7 +34,7 @@ class IgnoreInFileHandler( val issueId = params[0] // ID of issue that needs to be ignored val filePath = params[1] // Computed path that will be used in the snyk ignore command for the --path arg - val computedPath = filePath.removePrefix("${project.basePath}${File.separator}") + val computedPath = filePath.removePrefix("${project.getContentRootPaths().firstOrNull()}${File.separator}") // Avoid blocking the UI thread runInBackground("Snyk: applying ignore...") { val result = try { From 99b51188d60612cbe3e26c2ceba4391c3400d2e8 Mon Sep 17 00:00:00 2001 From: DariusZdroba Date: Fri, 15 Nov 2024 10:53:00 +0200 Subject: [PATCH 5/8] chore: use Path.relativeTo instead of trimPrefix --- .../kotlin/io/snyk/plugin/ui/jcef/IgnoreInFileHandler.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/io/snyk/plugin/ui/jcef/IgnoreInFileHandler.kt b/src/main/kotlin/io/snyk/plugin/ui/jcef/IgnoreInFileHandler.kt index 4434e1ec1..f8960212b 100644 --- a/src/main/kotlin/io/snyk/plugin/ui/jcef/IgnoreInFileHandler.kt +++ b/src/main/kotlin/io/snyk/plugin/ui/jcef/IgnoreInFileHandler.kt @@ -13,8 +13,9 @@ import org.cef.browser.CefFrame import org.cef.handler.CefLoadHandlerAdapter import snyk.common.IgnoreService import snyk.common.lsp.LanguageServerWrapper -import java.io.File import java.io.IOException +import kotlin.io.path.Path +import kotlin.io.path.relativeTo class IgnoreInFileHandler( private val project: Project, @@ -34,7 +35,7 @@ class IgnoreInFileHandler( val issueId = params[0] // ID of issue that needs to be ignored val filePath = params[1] // Computed path that will be used in the snyk ignore command for the --path arg - val computedPath = filePath.removePrefix("${project.getContentRootPaths().firstOrNull()}${File.separator}") + val computedPath = Path(filePath).relativeTo(project.getContentRootPaths().firstOrNull()!!).toString(); // Avoid blocking the UI thread runInBackground("Snyk: applying ignore...") { val result = try { @@ -83,7 +84,7 @@ class IgnoreInFileHandler( } fun applyIgnoreInFileAndSave(issueId: String, filePath: String): Result { - val ignoreService = IgnoreService(project); + val ignoreService = IgnoreService(project) if (issueId != "" && filePath != "") { ignoreService.ignoreInstance(issueId, filePath) } else { From 986defddc1fc3b3f78bbc3b13c922c55e5f42532 Mon Sep 17 00:00:00 2001 From: DariusZdroba Date: Fri, 15 Nov 2024 13:04:55 +0200 Subject: [PATCH 6/8] chore: move ignore in file specific js logic to ls --- .../toolwindow/panels/JCEFDescriptionPanel.kt | 30 +------------------ 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/src/main/kotlin/io/snyk/plugin/ui/toolwindow/panels/JCEFDescriptionPanel.kt b/src/main/kotlin/io/snyk/plugin/ui/toolwindow/panels/JCEFDescriptionPanel.kt index c0408ac83..5e4bba4bd 100644 --- a/src/main/kotlin/io/snyk/plugin/ui/toolwindow/panels/JCEFDescriptionPanel.kt +++ b/src/main/kotlin/io/snyk/plugin/ui/toolwindow/panels/JCEFDescriptionPanel.kt @@ -183,7 +183,7 @@ class SuggestionDescriptionPanelFromLS( html = html.replace("\${ideStyle}", "") html = html.replace("\${headerEnd}", "") - html = html.replace("\${ideScript}", "") + html = html.replace("\${ideScript}", ideScript) html = html.replace("\${nonce}", nonce) @@ -233,7 +233,6 @@ class SuggestionDescriptionPanelFromLS( private fun getCustomScript(): String { return """ - (function () { // Utility function to show/hide an element based on a toggle value function toggleElement(element, action) { if (!element) return; @@ -365,20 +364,10 @@ class SuggestionDescriptionPanelFromLS( console.log('Applying fix', patch); } - function applyIgnoreInFile() { - console.log('Applying ignore', issue); - if (!issue) return; - - window.applyIgnoreInFileQuery(issue + '|@' + filePath + ' > ' + resourcePath); - toggleElement(ignoreInFileBtn, "hide"); - console.log('Applying ignore'); - } // DOM element references const generateAiFixBtn = document.getElementById("generate-ai-fix"); const applyFixBtn = document.getElementById('apply-fix') - const ignoreContainer = document.getElementById("ignore-container"); - const ignoreInFileBtn = document.getElementById('ignore-file-issue') const retryGenerateFixBtn = document.getElementById('retry-generate-fix') const fixLoadingIndicatorElem = document.getElementById("fix-loading-indicator"); @@ -398,19 +387,14 @@ class SuggestionDescriptionPanelFromLS( let diffSelectedIndex = 0; let fixes = []; - let issue = ignoreInFileBtn.getAttribute('issue') - let resourcePath = ignoreInFileBtn.getAttribute('resourcePath') - let filePath = ignoreInFileBtn.getAttribute('filePath') // Event listener for Generate AI fix button generateAiFixBtn?.addEventListener("click", generateAIFix); applyFixBtn?.addEventListener('click', applyFix); retryGenerateFixBtn?.addEventListener('click', reGenerateAIFix); - ignoreInFileBtn?.addEventListener("click", applyIgnoreInFile); nextDiffElem?.addEventListener("click", nextDiff); previousDiffElem?.addEventListener("click", previousDiff); - toggleElement(ignoreContainer, "show"); // This function will be called once the response is received from the Language Server window.receiveAIFixResponse = function (fixesResponse) { fixes = [...fixesResponse]; @@ -421,17 +405,6 @@ class SuggestionDescriptionPanelFromLS( showAIFixes(fixes); }; - window.receiveIgnoreInFileResponse = function (success){ - console.log('[[receiveIgnoreInFileResponse]]', success); - if(success){ - ignoreInFileBtn.disabled = true; - console.log('Ignored in file', success); - document.getElementById('ignore-file-issue').disabled = true; - }else{ - toggleElement(ignoreInFileBtn, "show"); - console.error('Failed to apply fix', success); - } - } window.receiveApplyFixResponse = function (success) { console.log('[[receiveApplyFixResponse]]', success); if (success) { @@ -442,7 +415,6 @@ class SuggestionDescriptionPanelFromLS( console.error('Failed to apply fix', success); } }; - })(); """.trimIndent() } } From 053e0cfe422a14dae6713092b118766f51ce3e7b Mon Sep 17 00:00:00 2001 From: DariusZdroba Date: Fri, 15 Nov 2024 13:30:01 +0200 Subject: [PATCH 7/8] chore: add back toggle element show only in plugin --- .../snyk/plugin/ui/toolwindow/panels/JCEFDescriptionPanel.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/kotlin/io/snyk/plugin/ui/toolwindow/panels/JCEFDescriptionPanel.kt b/src/main/kotlin/io/snyk/plugin/ui/toolwindow/panels/JCEFDescriptionPanel.kt index 5e4bba4bd..43ce6d14e 100644 --- a/src/main/kotlin/io/snyk/plugin/ui/toolwindow/panels/JCEFDescriptionPanel.kt +++ b/src/main/kotlin/io/snyk/plugin/ui/toolwindow/panels/JCEFDescriptionPanel.kt @@ -384,6 +384,8 @@ class SuggestionDescriptionPanelFromLS( const diffNumElem = document.getElementById("diff-number"); const diffNum2Elem = document.getElementById("diff-number2"); + const ignoreContainer = document.getElementById("ignore-container"); + let diffSelectedIndex = 0; let fixes = []; @@ -395,6 +397,8 @@ class SuggestionDescriptionPanelFromLS( nextDiffElem?.addEventListener("click", nextDiff); previousDiffElem?.addEventListener("click", previousDiff); + toggleElement(ignoreContainer, "show"); + // This function will be called once the response is received from the Language Server window.receiveAIFixResponse = function (fixesResponse) { fixes = [...fixesResponse]; From 7031ce3b6efa92bef479be48cec6f6ff51160884 Mon Sep 17 00:00:00 2001 From: DariusZdroba Date: Fri, 15 Nov 2024 13:44:19 +0200 Subject: [PATCH 8/8] chore: add back script tag for injecting script --- .../io/snyk/plugin/ui/toolwindow/panels/JCEFDescriptionPanel.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/io/snyk/plugin/ui/toolwindow/panels/JCEFDescriptionPanel.kt b/src/main/kotlin/io/snyk/plugin/ui/toolwindow/panels/JCEFDescriptionPanel.kt index 43ce6d14e..e50ebb15d 100644 --- a/src/main/kotlin/io/snyk/plugin/ui/toolwindow/panels/JCEFDescriptionPanel.kt +++ b/src/main/kotlin/io/snyk/plugin/ui/toolwindow/panels/JCEFDescriptionPanel.kt @@ -183,7 +183,7 @@ class SuggestionDescriptionPanelFromLS( html = html.replace("\${ideStyle}", "") html = html.replace("\${headerEnd}", "") - html = html.replace("\${ideScript}", ideScript) + html = html.replace("\${ideScript}", "") html = html.replace("\${nonce}", nonce)