Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several fixes for Hotkey Inlay Hints #1895

Merged
merged 4 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -41,17 +41,22 @@ class CodySelectionInlayManager(val project: Project) {
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@steveyegge Shouldn't isCodyUIHintsEnabled be also checked somewhere in this code block?
I fail to see any place where it is actually used, but perhaps I miss something obvious

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn, good catch. I had it at one point, and a merge killed it. Fixed.

}
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