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

Add configurable threshold for number of lines for big files #2484

Merged
merged 1 commit into from
Jun 18, 2022
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -42,15 +42,15 @@ class RainbowifyBanner : EditorNotifications.Provider<EditorNotificationPanel>()
if (psiFile != null && !checkForBigFile(psiFile)) {
if (RainbowSettings.instance.suppressBigFileCheck) return null
return EditorNotificationPanel().apply {
text("Rainbowify is disabled for files > 1000 lines by default")
text("Rainbowify is disabled for files > " + RainbowSettings.instance.bigFilesLinesThreshold + " lines")
icon(AllIcons.General.InspectionsEye)
createComponentActionLabel("got it, don't show again") {
RainbowSettings.instance.suppressBigFileCheck = true
EditorNotifications.getInstance(project).updateAllNotifications()
}

createComponentActionLabel("enable rainbowify for big files") {
RainbowSettings.instance.doNOTRainbowifyBigFiles = false
createComponentActionLabel("open settings") {
ShowSettingsUtilImpl.showSettingsDialog(project, RainbowConfigurable.ID, "")
EditorNotifications.getInstance(project).updateAllNotifications()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class RainbowConfigurable : SearchableConfigurable {
settings.rainbowifyTagNameInXML = settingsForm?.rainbowifyTagNameInXML() ?: false
settings.doNOTRainbowifyTemplateString = settingsForm?.doNOTRainbowifyTemplateString() ?: false
settings.doNOTRainbowifyBigFiles = settingsForm?.doNOTRainbowifyBigFiles() ?: true
settings.bigFilesLinesThreshold = settingsForm?.bigFilesLinesThreshold() ?: 1000
settings.rainbowifyPythonKeywords = settingsForm?.rainbowifyPythonKeywords() ?: false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class RainbowSettings : PersistentStateComponent<RainbowSettings> {
var rainbowifyTagNameInXML = false
var doNOTRainbowifyTemplateString = false
var doNOTRainbowifyBigFiles = true
var bigFilesLinesThreshold = 1000

var languageBlacklist: Set<String> = setOf("hocon", "mxml")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,45 @@
<text value="Do NOT rainbowify template string"/>
</properties>
</component>
<component id="454cb" class="javax.swing.JCheckBox" binding="doNOTRainbowifyBigFiles">
<grid id="528ba" layout-manager="GridLayoutManager" row-count="1" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<border type="none"/>
<constraints>
<grid row="15" 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="Do NOT rainbowify big files"/>
</properties>
</component>
<properties/>
<children>
<component id="454cb" class="javax.swing.JCheckBox" binding="doNOTRainbowifyBigFiles">
<constraints>
<grid row="0" 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="Do NOT rainbowify files with more than"/>
</properties>
</component>
<component id="ac934" class="javax.swing.JTextField" binding="bigFilesLinesThreshold">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<name value=""/>
<text value="1000"/>
</properties>
</component>
<component id="92b4" class="javax.swing.JLabel">
<constraints>
<grid row="0" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
<preferred-size width="96" height="14"/>
</grid>
</constraints>
<properties>
<text value="lines"/>
</properties>
</component>
</children>
</grid>
<component id="6e2da" class="javax.swing.JLabel">
<constraints>
<grid row="18" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class RainbowSettingsForm {

private var doNOTRainbowifyBigFiles: JCheckBox? = null

private var bigFilesLinesThreshold: JTextField? = null

private var rainbowifyPythonKeywords: JCheckBox? = null

private val settings: RainbowSettings = RainbowSettings.instance
Expand Down Expand Up @@ -78,6 +80,8 @@ class RainbowSettingsForm {

fun doNOTRainbowifyBigFiles() = doNOTRainbowifyBigFiles?.isSelected

fun bigFilesLinesThreshold() = bigFilesLinesThreshold?.text?.toIntOrNull()

fun rainbowifyPythonKeywords() = rainbowifyPythonKeywords?.isSelected

val isModified: Boolean
Expand All @@ -98,12 +102,14 @@ class RainbowSettingsForm {
|| rainbowifyTagNameInXML() != settings.rainbowifyTagNameInXML
|| doNOTRainbowifyTemplateString() != settings.doNOTRainbowifyTemplateString
|| doNOTRainbowifyBigFiles() != settings.doNOTRainbowifyBigFiles
|| bigFilesLinesThreshold() != settings.bigFilesLinesThreshold
|| languageBlacklist() != settings.languageBlacklist
|| rainbowifyPythonKeywords() != settings.rainbowifyPythonKeywords
)

init {
loadSettings()
doNOTRainbowifyBigFiles?.addActionListener({e -> bigFilesLinesThreshold?.setEnabled(doNOTRainbowifyBigFiles() ?: false)})
}

fun loadSettings() {
Expand All @@ -124,6 +130,7 @@ class RainbowSettingsForm {
rainbowifyTagNameInXML?.isSelected = settings.rainbowifyTagNameInXML
doNOTRainbowifyTemplateString?.isSelected = settings.doNOTRainbowifyTemplateString
doNOTRainbowifyBigFiles?.isSelected = settings.doNOTRainbowifyBigFiles
bigFilesLinesThreshold?.text = settings.bigFilesLinesThreshold.toString()
languageBlacklist?.text = settings.languageBlacklist.joinToString(",")
rainbowifyPythonKeywords?.isSelected = settings.rainbowifyPythonKeywords
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ abstract class RainbowHighlightVisitor : HighlightVisitor {
}

fun checkForBigFile(file: PsiFile): Boolean =
!(RainbowSettings.instance.doNOTRainbowifyBigFiles && file.getLineCount() > 1000)
!(RainbowSettings.instance.doNOTRainbowifyBigFiles &&
file.getLineCount() > RainbowSettings.instance.bigFilesLinesThreshold)

private fun fileIsNotHaskellOrIntelliJHaskellPluginNotEnabled(fileType: String) =
fileType != "Haskell" || !isIntelliJHaskellEnabled
Expand Down