Skip to content

Commit 1e646a0

Browse files
committed
Add support for categories in symbol mappings.
This update introduces categories for symbol mappings, enabling better organization and management. It includes changes to the settings interface, import/export functionality, and the addition of related data classes (`MappingEntry` and `MappingsData`). Default mappings are updated accordingly, and the FoldingBuilder now supports the updated data structure.
1 parent c7cf5e8 commit 1e646a0

File tree

6 files changed

+180
-184
lines changed

6 files changed

+180
-184
lines changed

src/main/kotlin/dev/meanmail/prettifypython/FoldingBuilder.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ class PrettifyFoldingBuilder : FoldingBuilder {
3636
val text = node.text
3737

3838
val settings = PrettifySettings.getInstance()
39-
val replacement = settings.symbolMappings[text]
39+
val replacement = settings.mappings
40+
.find { it.first == text }
41+
?.second
4042

4143
if (replacement == null || (text == "**" && node.psi.parent !is PyBinaryExpression)) {
4244
return emptyList()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package dev.meanmail.prettifypython.settings
2+
3+
import kotlinx.serialization.Serializable
4+
5+
@Serializable
6+
data class MappingEntry(
7+
val from: String = "",
8+
val to: String = ""
9+
)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package dev.meanmail.prettifypython.settings
2+
3+
import kotlinx.serialization.Serializable
4+
5+
@Serializable
6+
data class MappingsData(
7+
val exportDate: String,
8+
val pluginVersion: String,
9+
val ideVersion: String,
10+
val mappingsCount: Int,
11+
val comment: String = "",
12+
val mappings: List<MappingEntry>,
13+
val categories: Set<String> = emptySet()
14+
)

src/main/kotlin/dev/meanmail/prettifypython/settings/PrettifySettings.kt

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,21 @@ package dev.meanmail.prettifypython.settings
22

33
import com.intellij.openapi.application.ApplicationManager
44
import com.intellij.openapi.components.PersistentStateComponent
5+
import com.intellij.openapi.components.Service
56
import com.intellij.openapi.components.State
67
import com.intellij.openapi.components.Storage
8+
import kotlinx.serialization.Serializable
79

810
@State(
9-
name = "PrettifySettings",
10-
storages = [Storage("PrettifySettings.xml")]
11+
name = "PrettifyPythonSettings",
12+
storages = [Storage("PrettifyPythonSettings.xml")]
1113
)
14+
@Service
1215
class PrettifySettings : PersistentStateComponent<PrettifySettings.State> {
13-
companion object {
14-
fun getInstance(): PrettifySettings =
15-
ApplicationManager.getApplication().getService(PrettifySettings::class.java)
16-
17-
val DEFAULT_MAPPINGS = mapOf(
18-
">=" to "",
19-
"<=" to "",
20-
"!=" to "",
21-
"->" to "",
22-
"lambda" to "λ",
23-
"**" to "^"
24-
)
25-
}
2616

17+
@Serializable
2718
data class State(
28-
var symbolMappings: MutableMap<String, String> = DEFAULT_MAPPINGS.toMutableMap()
19+
var mappings: List<MappingEntry> = DEFAULT_MAPPINGS
2920
)
3021

3122
private var myState = State()
@@ -36,13 +27,29 @@ class PrettifySettings : PersistentStateComponent<PrettifySettings.State> {
3627
myState = state
3728
}
3829

39-
var symbolMappings: Map<String, String>
40-
get() = myState.symbolMappings
30+
var mappings: List<Pair<String, String>>
31+
get() = myState.mappings.map { Pair(it.from, it.to) }
4132
set(value) {
42-
myState.symbolMappings = value.toMutableMap()
33+
myState.mappings = value.map { MappingEntry(it.first, it.second) }
4334
}
4435

4536
fun resetToDefaults() {
46-
symbolMappings = DEFAULT_MAPPINGS
37+
mappings = DEFAULT_MAPPINGS_PAIRS
38+
}
39+
40+
companion object {
41+
fun getInstance(): PrettifySettings =
42+
ApplicationManager.getApplication().getService(PrettifySettings::class.java)
43+
44+
private val DEFAULT_MAPPINGS = listOf(
45+
MappingEntry(">=", ""),
46+
MappingEntry("<=", ""),
47+
MappingEntry("!=", ""),
48+
MappingEntry("->", ""),
49+
MappingEntry("lambda", "λ"),
50+
MappingEntry("**", "^")
51+
)
52+
53+
private val DEFAULT_MAPPINGS_PAIRS = DEFAULT_MAPPINGS.map { Pair(it.from, it.to) }
4754
}
4855
}

0 commit comments

Comments
 (0)