From d65ffc93510d120b17ac012a234d2033bd0141d4 Mon Sep 17 00:00:00 2001 From: Steve Yegge Date: Wed, 10 Jul 2024 02:30:11 -0700 Subject: [PATCH] Several fixes for Hotkey Inlay Hints (#1895) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Based on user feedback from GTM and Product, discussions with @danielmarquespt , and my own testing, I've made the following round of fixes to the hotkey hint feature, which shows an inlay with "Ctrl + Alt + ↵ to Edit" at the end of your selections in the editor window: 1. There is a new Preferences option for disabling the feature: image 2. The hint no longer draws if the selection is only on one line. - this takes care of many annoying cases, such as Find/Replace lighting it up everywhere 3. The hint now draws below the last line of the selection. This makes it less intrusive, IMO, as it's out of the way of the cursor. I think it's also more intuitive. Several users claim that it "used to work that way". It never actually worked that way; it always drew at the end of the last line of the selection. But now it does work that way. The one downside is that the hint can sometimes draw rather far from the selection, appearing to be two lines below. We will see how people respond to it. Coincidentally and usefully, this change also fixes CODY-2541. Getting the hint inlay out of the way of the cursor removed the interference with fine-tuning the selection. These changes also appear have to fixed CODY-2748, because I reported it and I can no longer reproduce it. It used to be 100% reproducible, so I'm going to mark it closed until it resurfaces. fixes CODY-2541 fixes CODY-2748 ## Test plan This requires UI testing to verify with actual integration tests. I reviewed the test plan, and these changes do not affect the plan. --- .../cody/config/CodyApplicationSettings.kt | 2 ++ .../sourcegraph/cody/config/SettingsModel.kt | 1 + .../cody/config/ui/CodyConfigurable.kt | 22 ++++++++++++++++--- .../listeners/CodySelectionInlayManager.kt | 20 +++++++++++------ .../com/sourcegraph/config/ConfigUtil.kt | 3 +++ 5 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/com/sourcegraph/cody/config/CodyApplicationSettings.kt b/src/main/kotlin/com/sourcegraph/cody/config/CodyApplicationSettings.kt index 8d2d4e3639..0f71392f0d 100644 --- a/src/main/kotlin/com/sourcegraph/cody/config/CodyApplicationSettings.kt +++ b/src/main/kotlin/com/sourcegraph/cody/config/CodyApplicationSettings.kt @@ -18,6 +18,7 @@ data class CodyApplicationSettings( var isCustomAutocompleteColorEnabled: Boolean = false, var customAutocompleteColor: Int? = null, var isLookupAutocompleteEnabled: Boolean = true, + var isCodyUIHintsEnabled: Boolean = true, var blacklistedLanguageIds: List = listOf(), var isOnboardingGuidanceDismissed: Boolean = false, var shouldAcceptNonTrustedCertificatesAutomatically: Boolean = false, @@ -37,6 +38,7 @@ data class CodyApplicationSettings( this.isCustomAutocompleteColorEnabled = state.isCustomAutocompleteColorEnabled this.customAutocompleteColor = state.customAutocompleteColor this.isLookupAutocompleteEnabled = state.isLookupAutocompleteEnabled + this.isCodyUIHintsEnabled = state.isCodyUIHintsEnabled this.blacklistedLanguageIds = state.blacklistedLanguageIds this.isOnboardingGuidanceDismissed = state.isOnboardingGuidanceDismissed this.shouldAcceptNonTrustedCertificatesAutomatically = diff --git a/src/main/kotlin/com/sourcegraph/cody/config/SettingsModel.kt b/src/main/kotlin/com/sourcegraph/cody/config/SettingsModel.kt index f77f3019a7..72afcbd99f 100644 --- a/src/main/kotlin/com/sourcegraph/cody/config/SettingsModel.kt +++ b/src/main/kotlin/com/sourcegraph/cody/config/SettingsModel.kt @@ -12,6 +12,7 @@ data class SettingsModel( var isCustomAutocompleteColorEnabled: Boolean = false, var customAutocompleteColor: Color? = null, var isLookupAutocompleteEnabled: Boolean = true, + var isCodyUIHintsEnabled: Boolean = true, var blacklistedLanguageIds: List = listOf(), var shouldAcceptNonTrustedCertificatesAutomatically: Boolean = false, var shouldCheckForUpdates: Boolean = false diff --git a/src/main/kotlin/com/sourcegraph/cody/config/ui/CodyConfigurable.kt b/src/main/kotlin/com/sourcegraph/cody/config/ui/CodyConfigurable.kt index 27ee172a30..26c848cc6b 100644 --- a/src/main/kotlin/com/sourcegraph/cody/config/ui/CodyConfigurable.kt +++ b/src/main/kotlin/com/sourcegraph/cody/config/ui/CodyConfigurable.kt @@ -1,13 +1,18 @@ package com.sourcegraph.cody.config.ui -import com.intellij.openapi.components.service import com.intellij.openapi.options.BoundConfigurable import com.intellij.openapi.project.Project import com.intellij.openapi.ui.DialogPanel import com.intellij.ui.ColorPanel import com.intellij.ui.JBColor import com.intellij.ui.components.JBCheckBox -import com.intellij.ui.dsl.builder.* +import com.intellij.ui.dsl.builder.Cell +import com.intellij.ui.dsl.builder.MAX_LINE_LENGTH_NO_WRAP +import com.intellij.ui.dsl.builder.Row +import com.intellij.ui.dsl.builder.bindSelected +import com.intellij.ui.dsl.builder.panel +import com.intellij.ui.dsl.builder.selected +import com.intellij.ui.dsl.builder.toMutableProperty import com.intellij.ui.dsl.gridLayout.HorizontalAlign import com.intellij.ui.layout.and import com.sourcegraph.cody.config.CodyApplicationSettings @@ -21,7 +26,7 @@ import com.sourcegraph.config.ConfigUtil class CodyConfigurable(val project: Project) : BoundConfigurable(ConfigUtil.CODY_DISPLAY_NAME) { private lateinit var dialogPanel: DialogPanel private val settingsModel = SettingsModel() - private val codyApplicationSettings = service() + private val codyApplicationSettings = CodyApplicationSettings.instance override fun createPanel(): DialogPanel { dialogPanel = panel { @@ -30,12 +35,21 @@ class CodyConfigurable(val project: Project) : BoundConfigurable(ConfigUtil.CODY group("Cody") { row { enableCodyCheckbox = + @Suppress("DialogTitleCapitalization") checkBox("Enable Cody") .comment( "Disable this to turn off all AI-based functionality of the plugin, including the Cody chat sidebar and autocomplete", MAX_LINE_LENGTH_NO_WRAP) .bindSelected(settingsModel::isCodyEnabled) } + row { + checkBox("Enable UI Hints") + .comment( + "Disable this to turn off the display of UI hints and help features", + MAX_LINE_LENGTH_NO_WRAP) + .enabledIf(enableCodyCheckbox.selected) + .bindSelected(settingsModel::isCodyUIHintsEnabled) + } row { enableDebugCheckbox = checkBox("Enable debug") @@ -105,6 +119,7 @@ class CodyConfigurable(val project: Project) : BoundConfigurable(ConfigUtil.CODY // note: this sets the same value for both light & dark mode, currently codyApplicationSettings.customAutocompleteColor?.let { JBColor(it, it) } settingsModel.isLookupAutocompleteEnabled = codyApplicationSettings.isLookupAutocompleteEnabled + settingsModel.isCodyUIHintsEnabled = codyApplicationSettings.isCodyUIHintsEnabled settingsModel.blacklistedLanguageIds = codyApplicationSettings.blacklistedLanguageIds settingsModel.shouldAcceptNonTrustedCertificatesAutomatically = codyApplicationSettings.shouldAcceptNonTrustedCertificatesAutomatically @@ -137,6 +152,7 @@ class CodyConfigurable(val project: Project) : BoundConfigurable(ConfigUtil.CODY settingsModel.isCustomAutocompleteColorEnabled codyApplicationSettings.customAutocompleteColor = settingsModel.customAutocompleteColor?.rgb codyApplicationSettings.isLookupAutocompleteEnabled = settingsModel.isLookupAutocompleteEnabled + codyApplicationSettings.isCodyUIHintsEnabled = settingsModel.isCodyUIHintsEnabled codyApplicationSettings.blacklistedLanguageIds = settingsModel.blacklistedLanguageIds codyApplicationSettings.shouldAcceptNonTrustedCertificatesAutomatically = settingsModel.shouldAcceptNonTrustedCertificatesAutomatically diff --git a/src/main/kotlin/com/sourcegraph/cody/listeners/CodySelectionInlayManager.kt b/src/main/kotlin/com/sourcegraph/cody/listeners/CodySelectionInlayManager.kt index 6891ee727a..337ebb8256 100644 --- a/src/main/kotlin/com/sourcegraph/cody/listeners/CodySelectionInlayManager.kt +++ b/src/main/kotlin/com/sourcegraph/cody/listeners/CodySelectionInlayManager.kt @@ -12,6 +12,7 @@ import com.intellij.openapi.keymap.KeymapManager import com.intellij.openapi.project.Project import com.intellij.openapi.util.Disposer import com.sourcegraph.cody.edit.FixupService +import com.sourcegraph.config.ConfigUtil import java.awt.Font import java.awt.Graphics import java.awt.Graphics2D @@ -28,7 +29,6 @@ class CodySelectionInlayManager(val project: Project) { fun handleSelectionChanged(editor: Editor, event: SelectionEvent) { clearInlay() - val service = FixupService.getInstance(project) if (!service.isEligibleForInlineEdit(editor)) { return @@ -37,21 +37,27 @@ class CodySelectionInlayManager(val project: Project) { if (service.getActiveSession() != null) { return } + if (!ConfigUtil.isCodyUIHintsEnabled()) return // User-disabled. val startOffset = event.newRange.startOffset val endOffset = event.newRange.endOffset if (startOffset == endOffset) { - // Don't show if there's no selection. - return + return // Don't show if there's no selection. } - val startLine = editor.document.getLineNumber(startOffset) - val endLine = editor.document.getLineNumber(endOffset) + val document = editor.document + val startLine = document.getLineNumber(startOffset) + val endLine = document.getLineNumber(endOffset) val selectionEndLine = if (startOffset > endOffset) startLine else endLine - + // Don't show if selection is only on one line, as it can be distracting. + if (startLine == selectionEndLine) { + return + } val editShortcutText = getKeyStrokeText("cody.editCodeAction") val inlayContent = "$editShortcutText to Edit" - updateInlay(editor, inlayContent, selectionEndLine) + val bottomLine = // Try to put it beneath the selection. At the end was unpopular. + if (selectionEndLine + 1 < document.lineCount) selectionEndLine + 1 else selectionEndLine + updateInlay(editor, inlayContent, bottomLine) } private fun updateInlay(editor: Editor, content: String, line: Int) { diff --git a/src/main/kotlin/com/sourcegraph/config/ConfigUtil.kt b/src/main/kotlin/com/sourcegraph/config/ConfigUtil.kt index 4026ea7252..a4aee9a4b1 100644 --- a/src/main/kotlin/com/sourcegraph/config/ConfigUtil.kt +++ b/src/main/kotlin/com/sourcegraph/config/ConfigUtil.kt @@ -131,6 +131,9 @@ object ConfigUtil { @JvmStatic fun isCodyDebugEnabled(): Boolean = CodyApplicationSettings.instance.isCodyDebugEnabled + @JvmStatic + fun isCodyUIHintsEnabled(): Boolean = CodyApplicationSettings.instance.isCodyUIHintsEnabled + @JvmStatic fun isCodyVerboseDebugEnabled(): Boolean = CodyApplicationSettings.instance.isCodyVerboseDebugEnabled