Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: load issue html on demand #626

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Loading