1
0
mirror of https://github.com/chylex/IntelliJ-Inspection-Lens.git synced 2025-05-02 02:34:07 +02:00

Add option to change maximum inspection description length

Closes 
This commit is contained in:
chylex 2025-01-15 01:51:39 +01:00
parent 102352a2eb
commit 98d3e5db01
Signed by: chylex
SSH Key Fingerprint: SHA256:WqM8X/1DDn11LbYM0H5wsqZUjbcKxVsic37L+ERcF4o
3 changed files with 21 additions and 9 deletions
src/main/kotlin/com/chylex/intellij/inspectionlens

View File

@ -44,7 +44,7 @@ class LensRenderer(private var info: HighlightInfo, private val settings: LensSe
fun setPropertiesFrom(info: HighlightInfo) { fun setPropertiesFrom(info: HighlightInfo) {
this.info = info this.info = info
val description = getValidDescriptionText(info.description) val description = getValidDescriptionText(info.description, settings.maxDescriptionLength)
text = description text = description
attributes = LensSeverity.from(info.severity).textAttributes attributes = LensSeverity.from(info.severity).textAttributes
@ -155,15 +155,13 @@ class LensRenderer(private var info: HighlightInfo, private val settings: LensSe
private const val HOVER_HORIZONTAL_PADDING = TEXT_HORIZONTAL_PADDING - 2 private const val HOVER_HORIZONTAL_PADDING = TEXT_HORIZONTAL_PADDING - 2
private const val UNDERLINE_WIDTH_REDUCTION = (TEXT_HORIZONTAL_PADDING * 2) - 1 private const val UNDERLINE_WIDTH_REDUCTION = (TEXT_HORIZONTAL_PADDING * 2) - 1
private const val MAX_DESCRIPTION_LENGTH = 120
/** /**
* Kotlin compiler inspections have an `[UPPERCASE_TAG]` at the beginning. * Kotlin compiler inspections have an `[UPPERCASE_TAG]` at the beginning.
*/ */
private val UPPERCASE_TAG_REGEX = Pattern.compile("^\\[[A-Z_]+] ") private val UPPERCASE_TAG_REGEX = Pattern.compile("^\\[[A-Z_]+] ")
private fun getValidDescriptionText(text: String?): String { private fun getValidDescriptionText(text: String?, maxLength: Int): String {
return if (text.isNullOrBlank()) " " else addEllipsisOrMissingPeriod(unescapeHtmlEntities(stripUppercaseTag(text))) return if (text.isNullOrBlank()) " " else addEllipsisOrMissingPeriod(unescapeHtmlEntities(stripUppercaseTag(text)), maxLength)
} }
private fun stripUppercaseTag(text: String): String { private fun stripUppercaseTag(text: String): String {
@ -181,11 +179,11 @@ class LensRenderer(private var info: HighlightInfo, private val settings: LensSe
return if (text.contains('&')) StringUtil.unescapeXmlEntities(text) else text return if (text.contains('&')) StringUtil.unescapeXmlEntities(text) else text
} }
private fun addEllipsisOrMissingPeriod(text: String): String { private fun addEllipsisOrMissingPeriod(text: String, maxLength: Int): String {
return when { return when {
text.length > MAX_DESCRIPTION_LENGTH -> text.take(MAX_DESCRIPTION_LENGTH).trimEnd { it.isWhitespace() || it == '.' } + "" text.length > maxLength -> text.take(maxLength).trimEnd { it.isWhitespace() || it == '.' } + ""
!text.endsWith('.') -> "$text." !text.endsWith('.') -> "$text."
else -> text else -> text
} }
} }

View File

@ -20,6 +20,7 @@ import com.intellij.ui.dsl.builder.Cell
import com.intellij.ui.dsl.builder.RightGap import com.intellij.ui.dsl.builder.RightGap
import com.intellij.ui.dsl.builder.Row import com.intellij.ui.dsl.builder.Row
import com.intellij.ui.dsl.builder.RowLayout import com.intellij.ui.dsl.builder.RowLayout
import com.intellij.ui.dsl.builder.bindIntText
import com.intellij.ui.dsl.builder.bindItem import com.intellij.ui.dsl.builder.bindItem
import com.intellij.ui.dsl.builder.bindSelected import com.intellij.ui.dsl.builder.bindSelected
import com.intellij.ui.dsl.builder.panel import com.intellij.ui.dsl.builder.panel
@ -83,6 +84,9 @@ class LensApplicationConfigurable : BoundConfigurable("Inspection Lens"), Config
row { row {
checkBox("Use editor font").bindSelected(settings::useEditorFont) checkBox("Use editor font").bindSelected(settings::useEditorFont)
} }
row("Max description length:") {
intTextField(LensSettingsState.MAX_DESCRIPTION_LENGTH_RANGE, keyboardStep = 10).bindIntText(settings::maxDescriptionLength)
}
} }
group("Behavior") { group("Behavior") {

View File

@ -21,9 +21,14 @@ class LensSettingsState : SimplePersistentStateComponent<LensSettingsState.State
var showUnknownSeverities by property(true) var showUnknownSeverities by property(true)
var useEditorFont by property(true) var useEditorFont by property(true)
var maxDescriptionLength by property(120)
var lensHoverMode by enum(LensHoverMode.DEFAULT) var lensHoverMode by enum(LensHoverMode.DEFAULT)
} }
companion object {
val MAX_DESCRIPTION_LENGTH_RANGE = 20..1000
}
@get:Synchronized @get:Synchronized
@set:Synchronized @set:Synchronized
var severityFilter = createSeverityFilter() var severityFilter = createSeverityFilter()
@ -32,11 +37,15 @@ class LensSettingsState : SimplePersistentStateComponent<LensSettingsState.State
val useEditorFont val useEditorFont
get() = state.useEditorFont get() = state.useEditorFont
val maxDescriptionLength
get() = state.maxDescriptionLength
val lensHoverMode val lensHoverMode
get() = state.lensHoverMode get() = state.lensHoverMode
override fun loadState(state: State) { override fun loadState(state: State) {
super.loadState(state) super.loadState(state)
state.maxDescriptionLength = state.maxDescriptionLength.coerceIn(MAX_DESCRIPTION_LENGTH_RANGE)
update() update()
} }
@ -46,6 +55,7 @@ class LensSettingsState : SimplePersistentStateComponent<LensSettingsState.State
state.hiddenSeverities.apply { clear(); putAll(default.hiddenSeverities) } state.hiddenSeverities.apply { clear(); putAll(default.hiddenSeverities) }
state.showUnknownSeverities = default.showUnknownSeverities state.showUnknownSeverities = default.showUnknownSeverities
state.useEditorFont = default.useEditorFont state.useEditorFont = default.useEditorFont
state.maxDescriptionLength = default.maxDescriptionLength
state.lensHoverMode = default.lensHoverMode state.lensHoverMode = default.lensHoverMode
update() update()