Skip to content

Commit

Permalink
Support showing rule code in inspection message
Browse files Browse the repository at this point in the history
  • Loading branch information
koxudaxi committed Jan 22, 2023
1 parent bc6f304 commit fe5490f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/com/koxudaxi/ruff/RuffConfigPanel.form
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</properties>
<border type="none"/>
<children>
<grid id="da542" layout-manager="GridLayoutManager" row-count="3" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="da542" layout-manager="GridLayoutManager" row-count="4" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
Expand Down Expand Up @@ -39,6 +39,14 @@
<text value="Run ruff when Reformat Code"/>
</properties>
</component>
<component id="d3ece" class="javax.swing.JCheckBox" binding="showRuleCodeCheckBox">
<constraints>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Show Rule Code on inspection message"/>
</properties>
</component>
</children>
</grid>
<vspacer id="a33f9">
Expand Down
5 changes: 5 additions & 0 deletions src/com/koxudaxi/ruff/RuffConfigPanel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@ class RuffConfigPanel(project: Project) {
lateinit var configPanel: JPanel
private lateinit var runRuffOnSaveCheckBox: JCheckBox
private lateinit var runRuffOnReformatCodeCheckBox: JCheckBox
private lateinit var showRuleCodeCheckBox: JCheckBox

init {
val ruffConfigService = getInstance(project)
runRuffOnSaveCheckBox.isSelected = ruffConfigService.runRuffOnSave
runRuffOnSaveCheckBox.isEnabled = true
runRuffOnReformatCodeCheckBox.isSelected = ruffConfigService.runRuffOnReformatCode
runRuffOnReformatCodeCheckBox.isEnabled = true
showRuleCodeCheckBox.isSelected = ruffConfigService.showRuleCode
showRuleCodeCheckBox.isEnabled = true
}
val runRuffOnSave: Boolean
get() = runRuffOnSaveCheckBox.isSelected
val runRuffOnReformatCode: Boolean
get() = runRuffOnReformatCodeCheckBox.isSelected
val showRuleCode: Boolean
get() = showRuleCodeCheckBox.isSelected
}
1 change: 1 addition & 0 deletions src/com/koxudaxi/ruff/RuffConfigService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.intellij.util.xmlb.XmlSerializerUtil
class RuffConfigService : PersistentStateComponent<RuffConfigService> {
var runRuffOnSave: Boolean = false
var runRuffOnReformatCode: Boolean = true
var showRuleCode: Boolean = false
override fun getState(): RuffConfigService {
return this
}
Expand Down
4 changes: 3 additions & 1 deletion src/com/koxudaxi/ruff/RuffConfigurable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ class RuffConfigurable internal constructor(project: Project) : Configurable {

override fun isModified(): Boolean {
return (ruffConfigService.runRuffOnSave != configPanel.runRuffOnSave) ||
(ruffConfigService.runRuffOnReformatCode != configPanel.runRuffOnReformatCode)
(ruffConfigService.runRuffOnReformatCode != configPanel.runRuffOnReformatCode) ||
(ruffConfigService.showRuleCode != configPanel.showRuleCode)
}

override fun apply() {
ruffConfigService.runRuffOnSave = configPanel.runRuffOnSave
ruffConfigService.runRuffOnReformatCode = configPanel.runRuffOnReformatCode
ruffConfigService.showRuleCode = configPanel.showRuleCode
}

override fun disposeUIResources() {
Expand Down
4 changes: 3 additions & 1 deletion src/com/koxudaxi/ruff/RuffInspection.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,13 @@ class RuffInspection : PyInspection() {
*(argsBase + getStdinFileNameArgs(pyFile)).toTypedArray()
)
} ?: return
val showRuleCode = RuffConfigService.getInstance(pyFile.project).showRuleCode

parseJsonResponse(response).forEach {
val psiElement = getPyElement(it, pyFile, document) ?: return@forEach
registerProblem(
psiElement,
it.message,
if(showRuleCode) "${it.code} ${it.message}" else {it.message},
it.fix?.let { fix ->
RuffQuickFix.create(fix, document)
})
Expand Down

0 comments on commit fe5490f

Please sign in to comment.