Skip to content

Commit

Permalink
Add user-friendly names to the formatter options
Browse files Browse the repository at this point in the history
  • Loading branch information
vitallium committed Jan 25, 2025
1 parent 6c5d1fc commit 810841a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Added

- Support for `251.*` EAP builds
- Add user-friendly names to the formatter options

### Changed

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.github.vitallium.rubylsp.settings

@Target(AnnotationTarget.FIELD)
annotation class DisplayName(val name: String)
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,30 @@ data class RubyLspSettings(

enum class RubyLspSettingsFormatter {
@SerializedName("auto")
@DisplayName("Automatic")
AUTO,

@SerializedName("rubocop")
@DisplayName("RuboCop")
RUBOCOP,

@SerializedName("syntax_tree")
@DisplayName("Syntax Tree")
SYNTAX_TREE,

@SerializedName("standard")
@DisplayName("Standard")
STANDARD,

@SerializedName("rubyfmt")
@DisplayName("Rubyfmt")
RUBYFMT,

@SerializedName("none")
@DisplayName("None")
NONE;

fun getDisplayName(): String {
return this.javaClass.getField(this.name).getAnnotation(DisplayName::class.java)?.name ?: this.name
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.intellij.openapi.options.BoundSearchableConfigurable
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.ComboBox
import com.intellij.openapi.ui.DialogPanel
import com.intellij.ui.SimpleListCellRenderer
import com.intellij.ui.components.JBCheckBox
import com.intellij.ui.components.JBLabel
import com.intellij.ui.dsl.builder.*
Expand All @@ -34,6 +35,7 @@ class RubyLspSettingsConfigurable(private val project: Project) : BoundSearchabl
comboBox(RubyLspSettingsFormatter.entries)
.bindItem(rubyLspSettings::formatter.toNullableProperty())
.applyToComponent {
renderer = SimpleListCellRenderer.create { label, formatter, _ -> label.text = formatter.getDisplayName() }
addActionListener { event ->
val selectedFormatter =
(event.source as ComboBox<*>).selectedItem as RubyLspSettingsFormatter
Expand Down

0 comments on commit 810841a

Please sign in to comment.