From c4d31293468547fdb02c7773834fece305a7ef93 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Sat, 24 Jun 2023 09:25:29 -0500 Subject: [PATCH 1/3] fix: missing vertx --- .../jetbrains/status/SourceStatusService.kt | 20 +-- .../sourcemarker/SourceMarkerPlugin.kt | 140 +++++++++--------- .../status/SourceStatusServiceImpl.kt | 52 ++++--- .../view/LiveViewChartManagerImpl.kt | 18 +-- .../view/LiveViewLogManagerImpl.kt | 10 +- .../view/LiveViewTraceManagerImpl.kt | 10 +- 6 files changed, 125 insertions(+), 125 deletions(-) diff --git a/core/src/main/kotlin/spp/jetbrains/status/SourceStatusService.kt b/core/src/main/kotlin/spp/jetbrains/status/SourceStatusService.kt index 28b7684ca..cf60b6bfd 100644 --- a/core/src/main/kotlin/spp/jetbrains/status/SourceStatusService.kt +++ b/core/src/main/kotlin/spp/jetbrains/status/SourceStatusService.kt @@ -16,11 +16,10 @@ */ package spp.jetbrains.status -import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.project.Project import com.intellij.openapi.util.Key import com.intellij.openapi.util.Pair -import spp.jetbrains.UserData +import io.vertx.core.Vertx import spp.protocol.platform.general.Service /** @@ -30,7 +29,6 @@ import spp.protocol.platform.general.Service */ interface SourceStatusService { companion object { - private val log = logger() val KEY = Key.create("SPP_SOURCE_STATUS_SERVICE") @JvmStatic @@ -44,6 +42,7 @@ interface SourceStatusService { } } + val vertx: Vertx val project: Project fun isReady(): Boolean @@ -56,17 +55,12 @@ interface SourceStatusService { fun getCurrentService(): Service? fun setCurrentService(service: Service) fun setActiveServices(services: List) - fun onStatusChange(triggerInitial: Boolean = true, listener: (SourceStatus) -> Unit) - fun onServiceChange(triggerInitial: Boolean = true, listener: () -> Unit) - fun onReadyChange(triggerInitial: Boolean = true, listener: (SourceStatus) -> Unit) - suspend fun start(initialService: String?) + fun onStatusChange(triggerInitial: Boolean = true, listener: suspend (SourceStatus) -> Unit) + fun onServiceChange(triggerInitial: Boolean = true, listener: suspend () -> Unit) + fun onReadyChange(triggerInitial: Boolean = true, listener: suspend (SourceStatus) -> Unit) + suspend fun start(vertx: Vertx, initialService: String?) fun publishStatus(status: SourceStatus) { - if (!UserData.hasVertx(project)) { - log.warn("Vert.x unavailable. Ignoring status: $status") - return - } - - UserData.vertx(project).eventBus().publish("spp.status", status) + vertx.eventBus().publish("spp.status", status) } } diff --git a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/SourceMarkerPlugin.kt b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/SourceMarkerPlugin.kt index 5add89791..0d00fb304 100644 --- a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/SourceMarkerPlugin.kt +++ b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/SourceMarkerPlugin.kt @@ -53,7 +53,6 @@ import io.vertx.servicediscovery.ServiceDiscoveryOptions import io.vertx.servicediscovery.impl.DiscoveryImpl import io.vertx.serviceproxy.ServiceProxyBuilder import kotlinx.coroutines.CancellationException -import kotlinx.coroutines.Job import liveplugin.implementation.LivePluginProjectLoader import org.apache.commons.text.CaseUtils import spp.jetbrains.PluginBundle.message @@ -67,7 +66,6 @@ import spp.jetbrains.marker.plugin.LivePluginService import spp.jetbrains.marker.plugin.LiveStatusBarManager import spp.jetbrains.marker.plugin.SourceInlayHintProvider import spp.jetbrains.marker.plugin.SourceMarkerStartupActivity -import spp.jetbrains.safeLaunch import spp.jetbrains.sourcemarker.command.status.LiveStatusBarManagerImpl import spp.jetbrains.sourcemarker.config.SourceMarkerConfig import spp.jetbrains.sourcemarker.config.getServicePortNormalized @@ -114,6 +112,8 @@ class SourceMarkerPlugin : SourceMarkerStartupActivity() { if (project.getUserData(KEY) == null) { val plugin = SourceMarkerPlugin() plugin.project = project + plugin.setupVertx() + project.putUserData(SourceStatusService.KEY, SourceStatusServiceImpl(project)) project.putUserData(KEY, plugin) } @@ -121,12 +121,23 @@ class SourceMarkerPlugin : SourceMarkerStartupActivity() { } } + private lateinit var vertx: Vertx private lateinit var project: Project private var loadLivePluginsLock = ReentrantLock() - private var connectionJob: Job? = null private var discovery: ServiceDiscovery? = null private var addedConfigListener = false + private fun setupVertx() { + val options = if (System.getProperty("spp.debug.unblocked_threads", "false")!!.toBoolean()) { + log.info("Removed blocked thread checker") + VertxOptions().setBlockedThreadCheckInterval(Int.MAX_VALUE.toLong()) + } else { + VertxOptions() + } + vertx = UserData.vertx(project, Vertx.vertx(options)) + vertx.eventBus().registerDefaultCodec(SourceStatus::class.java, LocalMessageCodec()) + } + override fun runActivity(project: Project) { if (ApplicationManager.getApplication().isUnitTestMode) { return //tests manually set up necessary components @@ -145,7 +156,6 @@ class SourceMarkerPlugin : SourceMarkerStartupActivity() { suspend fun init(configInput: SourceMarkerConfig? = null) { log.info("Initializing SourceMarkerPlugin on project: $project") - disposePlugin() Disposer.register(project) { safeRunBlocking { try { @@ -156,73 +166,59 @@ class SourceMarkerPlugin : SourceMarkerStartupActivity() { } } - val options = if (System.getProperty("spp.debug.unblocked_threads", "false")!!.toBoolean()) { - log.info("Removed blocked thread checker") - VertxOptions().setBlockedThreadCheckInterval(Int.MAX_VALUE.toLong()) - } else { - VertxOptions() - } - val vertx = UserData.vertx(project, Vertx.vertx(options)) - vertx.eventBus().registerDefaultCodec(SourceStatus::class.java, LocalMessageCodec()) - LivePluginProjectLoader.projectOpened(project) val config = configInput ?: getConfig() addSppPluginConfigChangeListener() - connectionJob?.cancel() - connectionJob = null - - connectionJob = vertx.safeLaunch { - try { - initServices(vertx, config) - SourceStatusService.getInstance(project).start(config.serviceName) - - if (!config.notifiedConnection) { - val pluginName = message("plugin_name") - Notifications.Bus.notify( - Notification( - message("plugin_name"), "Connection established", - "You have successfully connected. $pluginName is now fully activated.", - NotificationType.INFORMATION - ), - project - ) - config.notifiedConnection = true + try { + initServices(config) + SourceStatusService.getInstance(project).start(vertx, config.serviceName) + + if (!config.notifiedConnection) { + val pluginName = message("plugin_name") + Notifications.Bus.notify( + Notification( + message("plugin_name"), "Connection established", + "You have successfully connected. $pluginName is now fully activated.", + NotificationType.INFORMATION + ), + project + ) + config.notifiedConnection = true - val projectSettings = PropertiesComponent.getInstance(project) - projectSettings.setValue("sourcemarker_plugin_config", Json.encode(config)) - } - } catch (ignored: CancellationException) { - } catch (throwable: Throwable) { - SourceStatusService.getInstance(project).update(ConnectionError, throwable.message) - log.warn("Connection failed", throwable) - return@safeLaunch + val projectSettings = PropertiesComponent.getInstance(project) + projectSettings.setValue("sourcemarker_plugin_config", Json.encode(config)) } + } catch (ignored: CancellationException) { + } catch (throwable: Throwable) { + SourceStatusService.getInstance(project).update(ConnectionError, throwable.message) + log.warn("Connection failed", throwable) + return + } - val pluginsPromise = Promise.promise() - ProgressManager.getInstance() - .run(object : Task.Backgroundable(project, "Loading Source++ plugins", false, ALWAYS_BACKGROUND) { - override fun run(indicator: ProgressIndicator) { - if (loadLivePluginsLock.tryLock()) { - SourceStatusService.getInstance(project).onStatusChange { - if (it == PluginsLoaded) { - initMarker(vertx) - } + val pluginsPromise = Promise.promise() + ProgressManager.getInstance() + .run(object : Task.Backgroundable(project, "Loading Source++ plugins", false, ALWAYS_BACKGROUND) { + override fun run(indicator: ProgressIndicator) { + if (loadLivePluginsLock.tryLock()) { + SourceStatusService.getInstance(project).onStatusChange { + if (it == PluginsLoaded) { + initMarker() } - - log.info("Loading live plugins for project: $project") - project.getUserData(LivePluginService.LIVE_PLUGIN_LOADER)!!.invoke() - log.info("Loaded live plugins for project: $project") - pluginsPromise.complete() - loadLivePluginsLock.unlock() - } else { - log.warn("Ignoring extraneous live plugins load request for project: $project") } + + log.info("Loading live plugins for project: $project") + project.getUserData(LivePluginService.LIVE_PLUGIN_LOADER)!!.invoke() + log.info("Loaded live plugins for project: $project") + pluginsPromise.complete() + loadLivePluginsLock.unlock() + } else { + log.warn("Ignoring extraneous live plugins load request for project: $project") } - }) - pluginsPromise.future().await() - } + } + }) + pluginsPromise.future().await() } private fun addSppPluginConfigChangeListener() { @@ -331,9 +327,9 @@ class SourceMarkerPlugin : SourceMarkerStartupActivity() { return null } - private suspend fun discoverAvailableServices(vertx: Vertx, config: SourceMarkerConfig) { + private suspend fun discoverAvailableServices(config: SourceMarkerConfig) { SourceStatusService.getInstance(project).update(Pending, "Discovering available services") - setupServiceDiscoveryBackend(vertx, config) + setupServiceDiscoveryBackend(config) val liveStatusManager = LiveStatusBarManagerImpl(project, vertx) project.putUserData(LiveStatusBarManager.KEY, liveStatusManager) @@ -407,7 +403,7 @@ class SourceMarkerPlugin : SourceMarkerStartupActivity() { } } - private fun setupServiceDiscoveryBackend(vertx: Vertx, config: SourceMarkerConfig) { + private fun setupServiceDiscoveryBackend(config: SourceMarkerConfig) { val originalClassLoader = Thread.currentThread().contextClassLoader try { Thread.currentThread().contextClassLoader = javaClass.classLoader @@ -442,24 +438,24 @@ class SourceMarkerPlugin : SourceMarkerStartupActivity() { UserData.clear(project) } - private suspend fun initServices(vertx: Vertx, config: SourceMarkerConfig) { + private suspend fun initServices(config: SourceMarkerConfig) { SourceStatusService.getInstance(project).update(Pending, "Logging in") if (!config.serviceHost.isNullOrBlank()) { - connectToConfiguredService(vertx, config) + connectToConfiguredService(config) } else { //try default local access try { - tryDefaultAccess(vertx, true, config) + tryDefaultAccess(true, config) } catch (ignore: SSLHandshakeException) { - tryDefaultAccess(vertx, false, config) + tryDefaultAccess(false, config) } catch (e: Exception) { log.warn("Unable to find local live platform", e) } } } - private suspend fun connectToConfiguredService(vertx: Vertx, config: SourceMarkerConfig) { + private suspend fun connectToConfiguredService(config: SourceMarkerConfig) { val certificatePins = mutableListOf() certificatePins.addAll(config.certificatePins) val httpClientOptions = if (certificatePins.isNotEmpty()) { @@ -513,13 +509,13 @@ class SourceMarkerPlugin : SourceMarkerStartupActivity() { config.accessToken = body } - discoverAvailableServices(vertx, config) + discoverAvailableServices(config) } else { error("Error getting service token: ${resp.statusCode()} ${resp.statusMessage()}") } } - private suspend fun tryDefaultAccess(vertx: Vertx, ssl: Boolean, config: SourceMarkerConfig) { + private suspend fun tryDefaultAccess(ssl: Boolean, config: SourceMarkerConfig) { val defaultAuthorizationCode = "change-me" val tokenUri = "/api/new-token?authorization_code=$defaultAuthorizationCode" val req = vertx.createHttpClient(HttpClientOptions().setSsl(ssl).setVerifyHost(false).setTrustAll(true)) @@ -550,7 +546,7 @@ class SourceMarkerPlugin : SourceMarkerStartupActivity() { val projectSettings = PropertiesComponent.getInstance(project) projectSettings.setValue("sourcemarker_plugin_config", Json.encode(config)) - discoverAvailableServices(vertx, config) + discoverAvailableServices(config) //auto-established notification Notifications.Bus.notify( @@ -571,7 +567,7 @@ class SourceMarkerPlugin : SourceMarkerStartupActivity() { } } - private fun initMarker(vertx: Vertx) { + private fun initMarker() { log.info("Initializing marker") val originalClassLoader = Thread.currentThread().contextClassLoader try { diff --git a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/status/SourceStatusServiceImpl.kt b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/status/SourceStatusServiceImpl.kt index ab80a592d..79e1957c1 100644 --- a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/status/SourceStatusServiceImpl.kt +++ b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/status/SourceStatusServiceImpl.kt @@ -21,6 +21,7 @@ import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.project.Project import com.intellij.openapi.project.ProjectManager import com.intellij.openapi.util.Pair +import io.vertx.core.Vertx import io.vertx.kotlin.coroutines.await import kotlinx.coroutines.Job import kotlinx.coroutines.delay @@ -39,10 +40,8 @@ import java.util.concurrent.atomic.AtomicBoolean @Suppress("TooManyFunctions") class SourceStatusServiceImpl(override val project: Project) : SourceStatusService { - companion object { - private val log = logger() - } - + private val log = logger() + override val vertx: Vertx = UserData.vertx(project) private val statusLock = Any() private var status: SourceStatus = Pending private var message: String? = null @@ -52,7 +51,7 @@ class SourceStatusServiceImpl(override val project: Project) : SourceStatusServi private var activeServices = listOf() private var initialService: String? = null - override suspend fun start(initialService: String?) { + override suspend fun start(vertx: Vertx, initialService: String?) { this.initialService = initialService //attempt to set current service @@ -62,7 +61,6 @@ class SourceStatusServiceImpl(override val project: Project) : SourceStatusServi private fun periodicallyCheckForCurrentService() { log.info("No current service set, starting periodic check for current service") - val vertx = UserData.vertx(project) vertx.setPeriodic(5000) { timerId -> vertx.safeLaunch { try { @@ -173,54 +171,64 @@ class SourceStatusServiceImpl(override val project: Project) : SourceStatusServi activeServices = services.toMutableList() } - override fun onServiceChange(triggerInitial: Boolean, listener: () -> Unit) { + override fun onServiceChange(triggerInitial: Boolean, listener: suspend () -> Unit) { if (triggerInitial && currentService != null) { synchronized(statusLock) { - listener() + vertx.safeLaunch { + listener() + } } } - UserData.vertx(project).eventBus().consumer("spp.status") { + vertx.eventBus().consumer("spp.status") { if (it.body() == ServiceEstablished) { synchronized(statusLock) { - listener() + vertx.safeLaunch { + listener() + } } } } } - override fun onStatusChange(triggerInitial: Boolean, listener: (SourceStatus) -> Unit) { + override fun onStatusChange(triggerInitial: Boolean, listener: suspend (SourceStatus) -> Unit) { synchronized(statusLock) { if (triggerInitial) { synchronized(statusLock) { - listener(status) + vertx.safeLaunch { + listener(status) + } } } - if (UserData.hasVertx(project)) { - UserData.vertx(project).eventBus().consumer("spp.status") { - synchronized(statusLock) { + vertx.eventBus().consumer("spp.status") { + synchronized(statusLock) { + vertx.safeLaunch { listener(it.body()) } } - } else { - log.warn("No vertx instance found for project: $project") } } } - override fun onReadyChange(triggerInitial: Boolean, listener: (SourceStatus) -> Unit) { + override fun onReadyChange(triggerInitial: Boolean, listener: suspend (SourceStatus) -> Unit) { if (triggerInitial) { synchronized(statusLock) { - listener(status) + vertx.safeLaunch { + listener(status) + } } } val statusTriggered = AtomicBoolean() - UserData.vertx(project).eventBus().consumer("spp.status") { + vertx.eventBus().consumer("spp.status") { synchronized(statusLock) { if (isReady() && statusTriggered.compareAndSet(false, true)) { - listener(status) + vertx.safeLaunch { + listener(status) + } } else if (!isReady() && statusTriggered.compareAndSet(true, false)) { - listener(status) + vertx.safeLaunch { + listener(status) + } } } } diff --git a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/view/LiveViewChartManagerImpl.kt b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/view/LiveViewChartManagerImpl.kt index fdbda86af..d3ba54ef3 100644 --- a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/view/LiveViewChartManagerImpl.kt +++ b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/view/LiveViewChartManagerImpl.kt @@ -85,16 +85,14 @@ class LiveViewChartManagerImpl( project.putUserData(LiveViewChartManager.KEY, this) SourceStatusService.getInstance(project).onReadyChange { if (it.isReady) { - UserData.vertx(project).safeLaunch { - val service = SourceStatusService.getCurrentService(project) - if (service == null) { - log.warn("No service found for project: ${project.name}") - return@safeLaunch - } - - project.invokeLater { - showServiceWindow(service) - } + val service = SourceStatusService.getCurrentService(project) + if (service == null) { + log.warn("No service found for project: ${project.name}") + return@onReadyChange + } + + project.invokeLater { + showServiceWindow(service) } } else { project.invokeLater { diff --git a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/view/LiveViewLogManagerImpl.kt b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/view/LiveViewLogManagerImpl.kt index 420cb656c..5ba664951 100644 --- a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/view/LiveViewLogManagerImpl.kt +++ b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/view/LiveViewLogManagerImpl.kt @@ -87,11 +87,13 @@ class LiveViewLogManagerImpl( project.putUserData(LiveViewLogManager.KEY, this) SourceStatusService.getInstance(project).onReadyChange { if (it.isReady) { - val vertx = UserData.vertx(project) - vertx.safeLaunch { - val service = SourceStatusService.getCurrentService(project)!! - showServicesWindow(service) + val service = SourceStatusService.getCurrentService(project) + if (service == null) { + log.warn("No service found for project: ${project.name}") + return@onReadyChange } + + showServicesWindow(service) } else { project.invokeLater { hideWindows() diff --git a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/view/LiveViewTraceManagerImpl.kt b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/view/LiveViewTraceManagerImpl.kt index 0efa8fa1b..492044b17 100644 --- a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/view/LiveViewTraceManagerImpl.kt +++ b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/view/LiveViewTraceManagerImpl.kt @@ -90,11 +90,13 @@ class LiveViewTraceManagerImpl( project.putUserData(LiveViewTraceManager.KEY, this) SourceStatusService.getInstance(project).onReadyChange { if (it.isReady) { - val vertx = UserData.vertx(project) - vertx.safeLaunch { - val service = SourceStatusService.getCurrentService(project)!! - showServiceWindow(service) + val service = SourceStatusService.getCurrentService(project) + if (service == null) { + log.warn("No service found for project: ${project.name}") + return@onReadyChange } + + showServiceWindow(service) } else { project.invokeLater { hideWindows() From 0eca7341244880bbe8408c0587266aded6856410 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Tue, 4 Jul 2023 13:21:23 -0500 Subject: [PATCH 2/3] style: detekt --- .../command/util/AutocompleteField.kt | 165 ++++++++++-------- 1 file changed, 95 insertions(+), 70 deletions(-) diff --git a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/command/util/AutocompleteField.kt b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/command/util/AutocompleteField.kt index 47a2d2930..ad829ef97 100644 --- a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/command/util/AutocompleteField.kt +++ b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/command/util/AutocompleteField.kt @@ -40,7 +40,8 @@ import javax.swing.event.DocumentListener import javax.swing.text.* /** - * todo: description. + * AutocompleteField is a custom text input field with autocomplete functionality. + * It extends JTextPane and implements various listener interfaces for handling user input and interactions. * * @since 0.3.0 * @author [Brandon Fergerson](mailto:bfergerson@apache.org) @@ -255,88 +256,112 @@ class AutocompleteField( override fun keyTyped(e: KeyEvent) = Unit override fun keyPressed(e: KeyEvent) { - if (e.keyCode == KeyEvent.VK_SPACE && hasControlHeld) { - results.clear() - results.addAll(allLookup - .filter { it.getText().lowercase().contains(text) } - .sortedBy { it.getText() }) - model.updateView() - list.visibleRowCount = results.size.coerceAtMost(maxSuggestSize) - autocompleteDropdown?.setCurrentCommandsLabel(list.visibleRowCount) - if (results.size > 0) { - list.selectedIndex = 0 - } - - if (results.size > 0) { - showAutocompletePopup() - } else { - hideAutocompletePopup() - } - } else if (e.keyCode == KeyEvent.VK_CONTROL) { - hasControlHeld = true + if (e.keyCode == KeyEvent.VK_CONTROL) { + controlPressed() } else if (e.keyCode == KeyEvent.VK_UP) { - val index = list.selectedIndex - if (index > 0) { - list.selectedIndex = index - 1 - } - scrollListToSelected() + upPressed() } else if (e.keyCode == KeyEvent.VK_DOWN) { - val index = list.selectedIndex - if (index != -1 && list.model.size > index + 1) { - list.selectedIndex = index + 1 - } - scrollListToSelected() + downPressed() } else if (e.keyCode == KeyEvent.VK_TAB) { - if (text.isBlank() || list.selectedValue == null || (!replaceCommandOnTab && !autocompleteOnTab)) return - val autocompleteRow = list.selectedValue - if (replaceCommandOnTab) { - if (autocompleteRow is LiveCommandFieldRow && autocompleteRow.liveCommand.params.isNotEmpty()) { - val triggerPrefix = autocompleteRow.liveCommand.getTriggerName().lowercase() + " " - if (text.lowercase().startsWith(triggerPrefix)) { - return //do nothing - } - setText(autocompleteRow.getText() + " ") - } else { - setText(autocompleteRow.getText()) + tabPressed() + } else if (e.keyCode == KeyEvent.VK_ENTER) { + enterPressed() + } else if (e.keyCode == KeyEvent.VK_SPACE && hasControlHeld) { + controlSpacePressed() + } + } + + private fun controlPressed() { + hasControlHeld = true + } + + private fun upPressed() { + val index = list.selectedIndex + if (index > 0) { + list.selectedIndex = index - 1 + } + scrollListToSelected() + } + + private fun downPressed() { + val index = list.selectedIndex + if (index != -1 && list.model.size > index + 1) { + list.selectedIndex = index + 1 + } + scrollListToSelected() + } + + private fun tabPressed() { + if (text.isBlank() || list.selectedValue == null || (!replaceCommandOnTab && !autocompleteOnTab)) return + val autocompleteRow = list.selectedValue + if (replaceCommandOnTab) { + if (autocompleteRow is LiveCommandFieldRow && autocompleteRow.liveCommand.params.isNotEmpty()) { + val triggerPrefix = autocompleteRow.liveCommand.getTriggerName().lowercase() + " " + if (text.lowercase().startsWith(triggerPrefix)) { + return //do nothing } + setText(autocompleteRow.getText() + " ") } else { - val userInput = text.substringAfterLast(" ") - setText(text.substring(0, text.length - userInput.length) + autocompleteRow.getText()) - } - caretPosition = text.length - } else if (e.keyCode == KeyEvent.VK_ENTER) { - if (!autocompleteAndFinishOnEnter) { - ready = true - actualText = text - hideAutocompletePopup() - return + setText(autocompleteRow.getText()) } - actualText = text + } else { + val userInput = text.substringAfterLast(" ") + setText(text.substring(0, text.length - userInput.length) + autocompleteRow.getText()) + } + caretPosition = text.length + } - val text = if (isPopupVisible()) list.selectedValue else null - if (text is LiveCommandFieldRow) { - val liveCommand = text.liveCommand - if (liveCommand.params.isNotEmpty()) { - if (!getText().lowercase().startsWith(liveCommand.getTriggerName().lowercase() + " ")) { - setText(text.getText() + " ") + private fun enterPressed() { + if (!autocompleteAndFinishOnEnter) { + ready = true + actualText = text + hideAutocompletePopup() + return + } + actualText = text + + val text = if (isPopupVisible()) list.selectedValue else null + if (text is LiveCommandFieldRow) { + val liveCommand = text.liveCommand + if (liveCommand.params.isNotEmpty()) { + if (!getText().lowercase().startsWith(liveCommand.getTriggerName().lowercase() + " ")) { + setText(text.getText() + " ") + caretPosition = getText().length + } else { + val params = substringAfterIgnoreCase(getText(), liveCommand.getTriggerName()) + .split(" ").filter { it.isNotEmpty() } + if (params.size < liveCommand.params.size) { + setText(getText().trimEnd() + " ") caretPosition = getText().length } else { - val params = substringAfterIgnoreCase(getText(), liveCommand.getTriggerName()) - .split(" ").filter { it.isNotEmpty() } - if (params.size < liveCommand.params.size) { - setText(getText().trimEnd() + " ") - caretPosition = getText().length - } else { - ready = true - } + ready = true } - } else { - ready = true } - } else if (text != null) { - addAutoCompleteToInput(text) + } else { ready = true } + } else if (text != null) { + addAutoCompleteToInput(text) + ready = true + } + } + + private fun controlSpacePressed() { + results.clear() + results.addAll(allLookup + .filter { it.getText().lowercase().contains(text) } + .sortedBy { it.getText() }) + model.updateView() + list.visibleRowCount = results.size.coerceAtMost(maxSuggestSize) + autocompleteDropdown?.setCurrentCommandsLabel(list.visibleRowCount) + if (results.size > 0) { + list.selectedIndex = 0 + } + + if (results.size > 0) { + showAutocompletePopup() + } else { + hideAutocompletePopup() } } From 15c6153efea1c1e6040848d1bea9f1567d2ba4e9 Mon Sep 17 00:00:00 2001 From: Brandon Fergerson Date: Tue, 4 Jul 2023 13:21:34 -0500 Subject: [PATCH 3/3] style: detekt --- .../spp/jetbrains/sourcemarker/view/LiveViewChartManagerImpl.kt | 1 - .../spp/jetbrains/sourcemarker/view/LiveViewLogManagerImpl.kt | 1 - 2 files changed, 2 deletions(-) diff --git a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/view/LiveViewChartManagerImpl.kt b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/view/LiveViewChartManagerImpl.kt index d3ba54ef3..53eb37e6e 100644 --- a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/view/LiveViewChartManagerImpl.kt +++ b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/view/LiveViewChartManagerImpl.kt @@ -32,7 +32,6 @@ import com.intellij.ui.content.ContentManagerListener import spp.jetbrains.UserData import spp.jetbrains.icons.PluginIcons import spp.jetbrains.invokeLater -import spp.jetbrains.safeLaunch import spp.jetbrains.sourcemarker.view.action.ChangeTimeAction import spp.jetbrains.sourcemarker.view.action.ResumeViewAction import spp.jetbrains.sourcemarker.view.action.SetRefreshIntervalAction diff --git a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/view/LiveViewLogManagerImpl.kt b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/view/LiveViewLogManagerImpl.kt index 5ba664951..98724bc28 100644 --- a/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/view/LiveViewLogManagerImpl.kt +++ b/plugin/src/main/kotlin/spp/jetbrains/sourcemarker/view/LiveViewLogManagerImpl.kt @@ -33,7 +33,6 @@ import io.vertx.core.json.JsonObject import spp.jetbrains.UserData import spp.jetbrains.icons.PluginIcons import spp.jetbrains.invokeLater -import spp.jetbrains.safeLaunch import spp.jetbrains.sourcemarker.view.action.ResumeViewAction import spp.jetbrains.sourcemarker.view.action.SetRefreshIntervalAction import spp.jetbrains.sourcemarker.view.action.StopViewAction