Skip to content
Open
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 @@ -25,7 +25,6 @@ public class UnitFileColorSettings implements ColorSettingsPage {
new AttributesDescriptor("Value//Enum (grammar)", UnitFileHighlighter.GRAMMAR_ENUM),
new AttributesDescriptor("Value//Literal (grammar)", UnitFileHighlighter.GRAMMAR_LITERAL),
new AttributesDescriptor("Value//Operator (grammar)", UnitFileHighlighter.GRAMMAR_OPERATOR),
new AttributesDescriptor("Value//Identifier (grammar)", UnitFileHighlighter.GRAMMAR_IDENTIFIER),
};

@Nullable
Expand Down Expand Up @@ -53,7 +52,7 @@ public String getDemoText() {
+ "# (at your option) any later version.\n"
+ "\n"
+ "[Unit]\n"
+ "Description=<gId>Reload Configuration from the Real Root</gId>\n"
+ "Description=Reload Configuration from the Real Root\n"
+ "DefaultDependencies=no\n"
+ "Requires=initrd-root-fs.target\n"
+ "After=initrd-root-fs.target\n"
Expand Down Expand Up @@ -81,7 +80,6 @@ public Map<String, TextAttributesKey> getAdditionalHighlightingTagToDescriptorMa
tags.put("gEnum", UnitFileHighlighter.GRAMMAR_ENUM);
tags.put("gLit", UnitFileHighlighter.GRAMMAR_LITERAL);
tags.put("gOp", UnitFileHighlighter.GRAMMAR_OPERATOR);
tags.put("gId", UnitFileHighlighter.GRAMMAR_IDENTIFIER);
return tags;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ fun defaultRole(terminal: TerminalCombinator): Role? = when (terminal) {
is IntegerTerminal -> Role.LITERAL
is LiteralChoiceTerminal -> if (terminal.choices.allPunctuation()) Role.OPERATOR else Role.ENUM
is FlexibleLiteralChoiceTerminal -> if (terminal.choices.allPunctuation()) Role.OPERATOR else Role.ENUM
is RegexTerminal -> Role.IDENTIFIER
else -> null // WhitespaceTerminal, and any future terminal types: uncoloured by default
// RegexTerminal (free-form names/strings: Description=, interface names, ...) and whitespace stay
// uncoloured by default — they keep the editor's normal value colour. The IDENTIFIER role is still
// available for grammars that opt in explicitly via Labeled (e.g. a single-token field like User=).
else -> null
}

private fun Array<out String>.allPunctuation(): Boolean =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ColoringTest {
assertEquals(Role.ENUM, defaultRole(FlexibleLiteralChoiceTerminal("AF_INET", "AF_INET6")))
assertEquals(Role.OPERATOR, defaultRole(LiteralChoiceTerminal(":")))
assertEquals(Role.OPERATOR, defaultRole(LiteralChoiceTerminal("~")))
assertEquals(Role.IDENTIFIER, defaultRole(RegexTerminal("[a-z]+", "[a-z]+")))
assertEquals(null, defaultRole(RegexTerminal("[a-z]+", "[a-z]+"))) // free-form: keeps default value color
assertEquals(null, defaultRole(WhitespaceTerminal()))
}

Expand Down
Loading