Skip to content

Commit

Permalink
feat: load issue html on demand (#626)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShawkyZ authored Oct 16, 2024
1 parent f5edb1d commit 170f7da
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/io/snyk/plugin/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ fun String.toVirtualFile(): VirtualFile {
return if (!this.startsWith("file://")) {
StandardFileSystems.local().refreshAndFindFileByPath(this) ?: throw FileNotFoundException(this)
} else {
VirtualFileManager.getInstance().refreshAndFindFileByNioPath(convertUriToPath(this.toVirtualFileURL()))
VirtualFileManager.getInstance().refreshAndFindFileByNioPath(convertUriToPath(this))
?: throw FileNotFoundException(this)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class SuggestionDescriptionPanelFromLS(
}

fun getCustomCssAndScript(): String {
var html = issue.details().ifBlank { issue.additionalData.customUIContent }
var html = issue.details()
val ideScript = getCustomScript()

// TODO: remove custom stylesheets, deliver variables from LS, replace variables with colors
Expand Down
17 changes: 17 additions & 0 deletions src/main/kotlin/snyk/common/lsp/LanguageServerWrapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import snyk.common.lsp.commands.COMMAND_LOGIN
import snyk.common.lsp.commands.COMMAND_LOGOUT
import snyk.common.lsp.commands.COMMAND_REPORT_ANALYTICS
import snyk.common.lsp.commands.COMMAND_WORKSPACE_FOLDER_SCAN
import snyk.common.lsp.commands.SNYK_GENERATE_ISSUE_DESCRIPTION
import snyk.common.lsp.commands.ScanDoneEvent
import snyk.common.lsp.progress.ProgressManager
import snyk.common.lsp.settings.LanguageServerSettings
Expand Down Expand Up @@ -524,6 +525,22 @@ class LanguageServerWrapper(
}
}

fun generateIssueDescription(issueID: String): String? {
if (!ensureLanguageServerInitialized()) return null
try {
val generateIssueCommand = ExecuteCommandParams(SNYK_GENERATE_ISSUE_DESCRIPTION, listOf(issueID))
val result =
languageServer.workspaceService
.executeCommand(generateIssueCommand)
.get(2, TimeUnit.SECONDS)
.toString()
return result
} catch (e: TimeoutException) {
logger.warn("could not generate html description", e)
return null
}
}

fun logout() {
if (!ensureLanguageServerInitialized()) return
val cmd = ExecuteCommandParams(COMMAND_LOGOUT, emptyList())
Expand Down
14 changes: 11 additions & 3 deletions src/main/kotlin/snyk/common/lsp/Types.kt
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,19 @@ data class ScanIssue(

fun details(): String {
return when (this.filterableIssueType) {
OPEN_SOURCE -> this.additionalData.details ?: ""
else -> this.additionalData.details ?: ""
OPEN_SOURCE, CODE_SECURITY, CODE_QUALITY -> getHtml(this.additionalData.details)
INFRASTRUCTURE_AS_CODE -> getHtml(this.additionalData.customUIContent)
else -> ""
}
}

private fun getHtml(details: String?): String {
if (details.isNullOrEmpty()) {
return LanguageServerWrapper.getInstance().generateIssueDescription(this.id) ?: ""
}
return details
}

fun annotationMessage(): String {
return when (this.filterableIssueType) {
OPEN_SOURCE -> this.title + " in " + this.additionalData.packageName + " id: " + this.ruleId()
Expand Down Expand Up @@ -445,7 +453,7 @@ data class IssueData(
@SerializedName("resolve") val resolve: String,
@SerializedName("path") val path: List<String>,
@SerializedName("references") val references: List<String>,
@SerializedName("customUIContent") val customUIContent: String,
@SerializedName("customUIContent") val customUIContent: String?,

// all
@SerializedName("key") val key: String,
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 @@ -11,3 +11,4 @@ internal const val COMMAND_GET_SETTINGS_SAST_ENABLED = "snyk.getSettingsSastEnab
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"
internal const val SNYK_GENERATE_ISSUE_DESCRIPTION = "snyk.generateIssueDescription"

0 comments on commit 170f7da

Please sign in to comment.