-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathHoconLanguageCodeStyleSettingsProvider.scala
More file actions
195 lines (165 loc) · 7.26 KB
/
HoconLanguageCodeStyleSettingsProvider.scala
File metadata and controls
195 lines (165 loc) · 7.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package org.jetbrains.plugins.hocon
package codestyle
import lang.HoconLanguage
import com.intellij.application.options.SmartIndentOptionsEditor
import com.intellij.lang.Language
import com.intellij.psi.codeStyle.CodeStyleSettingsCustomizable.SpacingOption
import com.intellij.psi.codeStyle.LanguageCodeStyleSettingsProvider.SettingsType
import com.intellij.psi.codeStyle.*
class HoconLanguageCodeStyleSettingsProvider extends LanguageCodeStyleSettingsProvider {
override def getLanguage: Language = HoconLanguage
override def getDisplayPriority = DisplayPriority.COMMON_SETTINGS
private val ObjectsWrap = "Objects"
private val ListsWrap = "Lists"
private val ObjectFieldsWithColonWrap = "Object fields with ':'"
private val ObjectFieldsWithAssignmentWrap = "Object fields with '=' or '+='"
override def customizeSettings(consumer: CodeStyleSettingsCustomizable, settingsType: SettingsType): Unit = {
def showCustomOption(name: String, title: String, group: String | Null, options: AnyRef*): Unit =
consumer.showCustomOption(classOf[HoconCustomCodeStyleSettings], name, title, group, options*)
import CodeStyleSettingsCustomizable.{WRAP_VALUES, WRAP_VALUES_FOR_SINGLETON}
import com.intellij.psi.codeStyle.LanguageCodeStyleSettingsProvider.SettingsType.*
val customizableOptions = CodeStyleSettingsCustomizableOptions.getInstance
import customizableOptions.*
settingsType match {
case SPACING_SETTINGS =>
consumer.showStandardOptions(
List(
SpacingOption.SPACE_WITHIN_BRACES,
SpacingOption.SPACE_WITHIN_BRACKETS,
SpacingOption.SPACE_WITHIN_METHOD_CALL_PARENTHESES,
SpacingOption.SPACE_BEFORE_COMMA,
SpacingOption.SPACE_AFTER_COMMA,
).map(_.name)*
)
consumer.renameStandardOption(SpacingOption.SPACE_WITHIN_BRACES.name, "Object braces")
consumer
.renameStandardOption(SpacingOption.SPACE_WITHIN_METHOD_CALL_PARENTHESES.name, "Include qualifier parentheses")
showCustomOption("SPACE_BEFORE_COLON", "Before colon", SPACES_AROUND_OPERATORS)
showCustomOption("SPACE_AFTER_COLON", "After colon", SPACES_AROUND_OPERATORS)
showCustomOption("SPACE_BEFORE_ASSIGNMENT", "Before assignment ('=' and '+=')", SPACES_AROUND_OPERATORS)
showCustomOption("SPACE_AFTER_ASSIGNMENT", "After assignment ('=' and '+=')", SPACES_AROUND_OPERATORS)
showCustomOption("SPACE_BEFORE_LBRACE_AFTER_PATH", "Immediately after path expression", SPACES_BEFORE_LEFT_BRACE)
showCustomOption("SPACE_WITHIN_SUBSTITUTION_BRACES", "Substitution braces", SPACES_WITHIN)
showCustomOption("SPACE_AFTER_QMARK", "After '?'", SPACES_OTHER)
case WRAPPING_AND_BRACES_SETTINGS =>
import com.intellij.psi.codeStyle.CodeStyleSettingsCustomizable.WrappingOrBraceOption.*
consumer.showStandardOptions(KEEP_LINE_BREAKS.name)
showCustomOption("HASH_COMMENTS_AT_FIRST_COLUMN", "Hash comments at first column", WRAPPING_KEEP)
showCustomOption("DOUBLE_SLASH_COMMENTS_AT_FIRST_COLUMN", "Double slash comments at first column", WRAPPING_KEEP)
showCustomOption("OBJECTS_WRAP", ObjectsWrap, null, WRAP_OPTIONS, WRAP_VALUES)
showCustomOption("OBJECTS_ALIGN_WHEN_MULTILINE", "Align when multiline", ObjectsWrap)
showCustomOption("OBJECTS_NEW_LINE_AFTER_LBRACE", "New line after '{'", ObjectsWrap)
showCustomOption("OBJECTS_RBRACE_ON_NEXT_LINE", "Place '}' on new line", ObjectsWrap)
showCustomOption("LISTS_WRAP", ListsWrap, null, WRAP_OPTIONS, WRAP_VALUES)
showCustomOption("LISTS_ALIGN_WHEN_MULTILINE", "Align when multiline", ListsWrap)
showCustomOption("LISTS_NEW_LINE_AFTER_LBRACKET", "New line after '['", ListsWrap)
showCustomOption("LISTS_RBRACKET_ON_NEXT_LINE", "Place ']' on new line", ListsWrap)
showCustomOption(
"OBJECT_FIELDS_WITH_COLON_WRAP",
ObjectFieldsWithColonWrap,
null,
WRAP_OPTIONS_FOR_SINGLETON,
WRAP_VALUES_FOR_SINGLETON,
)
showCustomOption("OBJECT_FIELDS_COLON_ON_NEXT_LINE", "Colon on next line", ObjectFieldsWithColonWrap)
showCustomOption(
"OBJECT_FIELDS_WITH_ASSIGNMENT_WRAP",
ObjectFieldsWithAssignmentWrap,
null,
WRAP_OPTIONS_FOR_SINGLETON,
WRAP_VALUES_FOR_SINGLETON,
)
showCustomOption(
"OBJECT_FIELDS_ASSIGNMENT_ON_NEXT_LINE",
"Assignment operator on next line",
ObjectFieldsWithAssignmentWrap,
)
showCustomOption(
"INCLUDED_RESOURCE_WRAP",
"Included resource",
null,
WRAP_OPTIONS_FOR_SINGLETON,
WRAP_VALUES_FOR_SINGLETON,
)
case BLANK_LINES_SETTINGS =>
showCustomOption("KEEP_BLANK_LINES_IN_OBJECTS", "In objects", BLANK_LINES_KEEP)
showCustomOption("KEEP_BLANK_LINES_BEFORE_RBRACE", "Before '}'", BLANK_LINES_KEEP)
showCustomOption("KEEP_BLANK_LINES_IN_LISTS", "In lists", BLANK_LINES_KEEP)
showCustomOption("KEEP_BLANK_LINES_BEFORE_RBRACKET", "Before ']'", BLANK_LINES_KEEP)
case _ =>
}
}
override def getDefaultCommonSettings: CommonCodeStyleSettings = {
val commonCodeStyleSettings = new CommonCodeStyleSettings(getLanguage)
val indentOptions = commonCodeStyleSettings.initIndentOptions
indentOptions.INDENT_SIZE = 2
indentOptions.TAB_SIZE = 2
indentOptions.CONTINUATION_INDENT_SIZE = 2
commonCodeStyleSettings
}
override def getIndentOptionsEditor: SmartIndentOptionsEditor = new SmartIndentOptionsEditor
def getCodeSample(settingsType: SettingsType): String = settingsType match {
case SettingsType.INDENT_SETTINGS =>
"""object {
| key = value
| some.path: 42
| list = [
| something here
| more stuff
| ]
| some.very.long.path =
| very very very long value
|}
| """.stripMargin.trim
case SettingsType.SPACING_SETTINGS =>
"""include file("application.conf")
|
|object {
| quix: 42
| foo.bar = stuff
| obj = {key: value, kye: vlaue}
| list = [1, 2, 3]
| subst = ${some.path}
| optsubst = ${?some.path}
|}
| """.stripMargin.trim
case SettingsType.WRAPPING_AND_BRACES_SETTINGS =>
"""include "someExtraordinarilyLongName"
|
|object {
| #comment
| key = value
| simplelist = [element]
| simpleobj = {k: v}
| longlist = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
| longobj = {key: value, foo: bar, stuff: 42, quix: 3.14}
| some.path: long long long long long long value
| another.path = another very very very very long value
| anotherobj {key: value, foo: bar, stuff: 42, quix: 3.14}
|
|#comment originally at first column
|//comment originally at first column
|
|}
| """.stripMargin.trim
case SettingsType.BLANK_LINES_SETTINGS =>
"""include "application"
|
|
|object {
| key: value
|
| num = 42
|
|}
|
|list = [
| value
|
| another one
|
|]
| """.stripMargin.trim
case _ => ""
}
}