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