Skip to content

Commit

Permalink
Several fixes for Hotkey Inlay Hints (#1895)
Browse files Browse the repository at this point in the history
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:
<img width="653" alt="image"
src="https://github.com/sourcegraph/jetbrains/assets/613744/8a78f2b1-c6d5-4a9c-902b-687d7d2e236d">

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.
  • Loading branch information
steveyegge authored Jul 10, 2024
1 parent f78d85f commit d65ffc9
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = listOf(),
var isOnboardingGuidanceDismissed: Boolean = false,
var shouldAcceptNonTrustedCertificatesAutomatically: Boolean = false,
Expand All @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = listOf(),
var shouldAcceptNonTrustedCertificatesAutomatically: Boolean = false,
var shouldCheckForUpdates: Boolean = false
Expand Down
22 changes: 19 additions & 3 deletions src/main/kotlin/com/sourcegraph/cody/config/ui/CodyConfigurable.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<CodyApplicationSettings>()
private val codyApplicationSettings = CodyApplicationSettings.instance

override fun createPanel(): DialogPanel {
dialogPanel = panel {
Expand All @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/com/sourcegraph/config/ConfigUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d65ffc9

Please sign in to comment.