mirror of
https://github.com/chylex/IntelliJ-Inspection-Lens.git
synced 2025-04-22 18:15:45 +02:00
parent
102352a2eb
commit
98d3e5db01
src/main/kotlin/com/chylex/intellij/inspectionlens
@ -44,7 +44,7 @@ class LensRenderer(private var info: HighlightInfo, private val settings: LensSe
|
||||
|
||||
fun setPropertiesFrom(info: HighlightInfo) {
|
||||
this.info = info
|
||||
val description = getValidDescriptionText(info.description)
|
||||
val description = getValidDescriptionText(info.description, settings.maxDescriptionLength)
|
||||
|
||||
text = description
|
||||
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 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.
|
||||
*/
|
||||
private val UPPERCASE_TAG_REGEX = Pattern.compile("^\\[[A-Z_]+] ")
|
||||
|
||||
private fun getValidDescriptionText(text: String?): String {
|
||||
return if (text.isNullOrBlank()) " " else addEllipsisOrMissingPeriod(unescapeHtmlEntities(stripUppercaseTag(text)))
|
||||
private fun getValidDescriptionText(text: String?, maxLength: Int): String {
|
||||
return if (text.isNullOrBlank()) " " else addEllipsisOrMissingPeriod(unescapeHtmlEntities(stripUppercaseTag(text)), maxLength)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
private fun addEllipsisOrMissingPeriod(text: String): String {
|
||||
private fun addEllipsisOrMissingPeriod(text: String, maxLength: Int): String {
|
||||
return when {
|
||||
text.length > MAX_DESCRIPTION_LENGTH -> text.take(MAX_DESCRIPTION_LENGTH).trimEnd { it.isWhitespace() || it == '.' } + "…"
|
||||
!text.endsWith('.') -> "$text."
|
||||
else -> text
|
||||
text.length > maxLength -> text.take(maxLength).trimEnd { it.isWhitespace() || it == '.' } + "…"
|
||||
!text.endsWith('.') -> "$text."
|
||||
else -> text
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ import com.intellij.ui.dsl.builder.Cell
|
||||
import com.intellij.ui.dsl.builder.RightGap
|
||||
import com.intellij.ui.dsl.builder.Row
|
||||
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.bindSelected
|
||||
import com.intellij.ui.dsl.builder.panel
|
||||
@ -83,6 +84,9 @@ class LensApplicationConfigurable : BoundConfigurable("Inspection Lens"), Config
|
||||
row {
|
||||
checkBox("Use editor font").bindSelected(settings::useEditorFont)
|
||||
}
|
||||
row("Max description length:") {
|
||||
intTextField(LensSettingsState.MAX_DESCRIPTION_LENGTH_RANGE, keyboardStep = 10).bindIntText(settings::maxDescriptionLength)
|
||||
}
|
||||
}
|
||||
|
||||
group("Behavior") {
|
||||
|
@ -21,9 +21,14 @@ class LensSettingsState : SimplePersistentStateComponent<LensSettingsState.State
|
||||
|
||||
var showUnknownSeverities by property(true)
|
||||
var useEditorFont by property(true)
|
||||
var maxDescriptionLength by property(120)
|
||||
var lensHoverMode by enum(LensHoverMode.DEFAULT)
|
||||
}
|
||||
|
||||
companion object {
|
||||
val MAX_DESCRIPTION_LENGTH_RANGE = 20..1000
|
||||
}
|
||||
|
||||
@get:Synchronized
|
||||
@set:Synchronized
|
||||
var severityFilter = createSeverityFilter()
|
||||
@ -32,11 +37,15 @@ class LensSettingsState : SimplePersistentStateComponent<LensSettingsState.State
|
||||
val useEditorFont
|
||||
get() = state.useEditorFont
|
||||
|
||||
val maxDescriptionLength
|
||||
get() = state.maxDescriptionLength
|
||||
|
||||
val lensHoverMode
|
||||
get() = state.lensHoverMode
|
||||
|
||||
override fun loadState(state: State) {
|
||||
super.loadState(state)
|
||||
state.maxDescriptionLength = state.maxDescriptionLength.coerceIn(MAX_DESCRIPTION_LENGTH_RANGE)
|
||||
update()
|
||||
}
|
||||
|
||||
@ -46,6 +55,7 @@ class LensSettingsState : SimplePersistentStateComponent<LensSettingsState.State
|
||||
state.hiddenSeverities.apply { clear(); putAll(default.hiddenSeverities) }
|
||||
state.showUnknownSeverities = default.showUnknownSeverities
|
||||
state.useEditorFont = default.useEditorFont
|
||||
state.maxDescriptionLength = default.maxDescriptionLength
|
||||
state.lensHoverMode = default.lensHoverMode
|
||||
|
||||
update()
|
||||
|
Loading…
Reference in New Issue
Block a user