Skip to content

Commit

Permalink
fix: UI fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bastiandoetsch committed Oct 23, 2024
1 parent b0e998d commit e728743
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ class SnykToolWindowPanel(
}

fun cleanUiAndCaches() {
getSnykCachedResults(project)?.cleanCaches()
getSnykCachedResults(project)?.clearCaches()
rootOssTreeNode.originalCliErrorMessage = null

getKubernetesImageCache(project)?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class SnykToolWindowSnykScanListenerLS(
override fun scanningStarted(snykScan: SnykScanParams) {
if (disposed) return
ApplicationManager.getApplication().invokeLater {
this.snykToolWindowPanel.cleanUiAndCaches()
this.snykToolWindowPanel.updateTreeRootNodesPresentation()
this.snykToolWindowPanel.displayScanningMessage()
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/snyk/common/SnykCachedResults.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SnykCachedResults(

override fun dispose() {
disposed = true
cleanCaches()
clearCaches()
}

fun isDisposed() = disposed
Expand All @@ -54,7 +54,7 @@ class SnykCachedResults(
var currentIacError: SnykError? = null
var currentSnykCodeError: SnykError? = null

fun cleanCaches() {
fun clearCaches() {
currentContainerResult = null
currentOssError = null
currentContainerError = null
Expand Down
34 changes: 27 additions & 7 deletions src/main/kotlin/snyk/common/lsp/LanguageServerWrapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import org.eclipse.lsp4j.WorkspaceEditCapabilities
import org.eclipse.lsp4j.WorkspaceFolder
import org.eclipse.lsp4j.WorkspaceFoldersChangeEvent
import org.eclipse.lsp4j.jsonrpc.Launcher
import org.eclipse.lsp4j.jsonrpc.MessageConsumer
import org.eclipse.lsp4j.jsonrpc.RemoteEndpoint
import org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer
import org.eclipse.lsp4j.launch.LSPLauncher
Expand Down Expand Up @@ -79,7 +80,7 @@ private const val INITIALIZATION_TIMEOUT = 20L
@Suppress("TooGenericExceptionCaught")
class LanguageServerWrapper(
private val lsPath: String = getCliFile().absolutePath,
private val executorService: ExecutorService = Executors.newCachedThreadPool(),
private val executorService: ExecutorService = Executors.newCachedThreadPool()
) : Disposable {
private var authenticatedUser: Map<String, String>? = null
private var initializeResult: InitializeResult? = null
Expand Down Expand Up @@ -150,7 +151,22 @@ class LanguageServerWrapper(
}
}

launcher = LSPLauncher.createClientLauncher(languageClient, process.inputStream, process.outputStream)
// enable message logging
val wrapper = fun(wrapped: MessageConsumer): MessageConsumer {
return MessageConsumer { message ->
logger.trace(message.toString())
wrapped.consume(message)
}
}

launcher = LSPLauncher.createClientLauncher(
snykLanguageClient,
process.inputStream,
process.outputStream,
executorService,
wrapper
)

languageServer = launcher.remoteProxy

val listenerFuture = launcher.startListening()
Expand Down Expand Up @@ -530,15 +546,20 @@ class LanguageServerWrapper(
if (key.isBlank()) throw RuntimeException("Issue ID is required")
val generateIssueCommand = ExecuteCommandParams(SNYK_GENERATE_ISSUE_DESCRIPTION, listOf(key))
return try {
logger.info("########### calling generateIssueDescription")
executeCommand(generateIssueCommand, 10000).toString()
executeCommand(generateIssueCommand, Long.MAX_VALUE).toString()
} catch (e: TimeoutException) {
val exceptionMessage = "generate issue description failed"
logger.warn(exceptionMessage, e)
null
} catch (e: Exception) {
logger.error("generate issue description failed", e)
null
if (e.message?.contains("failed to find issue") == true) {
val msg = "The issue is not in the server cache anymore, please wait for any running scans to finish"
logger.debug(msg)
return msg
} else {
logger.error("generate issue description failed", e)
null
}
}
}

Expand Down Expand Up @@ -686,4 +707,3 @@ class LanguageServerWrapper(
}

}

0 comments on commit e728743

Please sign in to comment.