Skip to content

Commit bff69a8

Browse files
committed
Some fixes and customization
1 parent 59370a1 commit bff69a8

File tree

4 files changed

+32
-32
lines changed

4 files changed

+32
-32
lines changed

ui/jetbrains/src/main/java/com/neueda/jetbrains/plugin/graphdb/jetbrains/formatter/CypherBlock.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import com.intellij.psi.TokenType;
1515
import com.intellij.psi.codeStyle.CodeStyleSettings;
1616
import com.intellij.psi.formatter.FormatterUtil;
17-
import com.intellij.psi.impl.source.tree.LeafPsiElement;
1817
import com.intellij.psi.impl.source.tree.TreeUtil;
1918
import com.neueda.jetbrains.plugin.graphdb.language.cypher.psi.CypherTypes;
2019
import org.jetbrains.annotations.NotNull;
@@ -97,14 +96,6 @@ private Block makeSubBlock(@NotNull ASTNode node) {
9796
indent = Indent.getNormalIndent(false);
9897
}
9998

100-
if (isTopLevel(node)) {
101-
String original = node.getPsi().getText();
102-
String text = original.toUpperCase();
103-
if (!original.equals(text)) {
104-
node.getPsi(LeafPsiElement.class).rawReplaceWithText(text);
105-
}
106-
}
107-
10899
return new CypherBlock(node, codeStyleSettings, wrap, indent, null);
109100
}
110101

ui/jetbrains/src/main/java/com/neueda/jetbrains/plugin/graphdb/jetbrains/formatter/CypherCodeStyleSettings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public class CypherCodeStyleSettings extends CustomCodeStyleSettings {
77

88
public boolean SPACE_AFTER_COLON = false;
99
public boolean SPACE_BEFORE_COLON = false;
10+
public boolean SPACE_BETWEEN_LABEL_AND_PARAMS = true;
1011

1112
CypherCodeStyleSettings(CodeStyleSettings container) {
1213
super("CypherCodeStyleSettings", container);

ui/jetbrains/src/main/java/com/neueda/jetbrains/plugin/graphdb/jetbrains/formatter/CypherFormattingModelBuilder.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import com.intellij.psi.codeStyle.CodeStyleSettings;
1616
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
1717
import com.neueda.jetbrains.plugin.graphdb.language.cypher.CypherLanguage;
18-
import com.neueda.jetbrains.plugin.graphdb.language.cypher.psi.CypherTypes;
1918
import org.jetbrains.annotations.NotNull;
2019
import org.jetbrains.annotations.Nullable;
2120

@@ -45,14 +44,16 @@ static SpacingBuilder createSpacingBuilder(CodeStyleSettings settings) {
4544
final int spacesBeforeComma = commonSettings.SPACE_BEFORE_COMMA ? 1 : 0;
4645
final int spacesBeforeColon = customSettings.SPACE_BEFORE_COLON ? 1 : 0;
4746
final int spacesAfterColon = customSettings.SPACE_AFTER_COLON ? 1 : 0;
47+
final int spacesAfterLabel = customSettings.SPACE_BETWEEN_LABEL_AND_PARAMS ? 1 : 0;
48+
49+
final int spacesAroundEqualityOperator = commonSettings.SPACE_AROUND_EQUALITY_OPERATORS ? 1 : 0;
50+
final int spacesAroundAdditiveOperator = commonSettings.SPACE_AROUND_ADDITIVE_OPERATORS ? 1 : 0;
51+
final int spacesAroundMulOperator = commonSettings.SPACE_AROUND_MULTIPLICATIVE_OPERATORS ? 1 : 0;
4852

4953
return new SpacingBuilder(settings, CypherLanguage.INSTANCE)
5054
.before(OP_COLON).spacing(spacesBeforeColon, spacesBeforeColon, 0, false, 0)
5155
.after(OP_COLON).spacing(spacesAfterColon, spacesAfterColon, 0, false, 0)
5256

53-
.beforeInside(CypherTypes.BRACKET_CURLYOPEN, CypherTypes.NODE_LABEL)
54-
.spacing(1, 1, 0, false, 0)
55-
5657
.withinPair(PARENTHESE_OPEN, PARENTHESE_CLOSE)
5758
.spaceIf(commonSettings.SPACE_WITHIN_BRACKETS, true)
5859

@@ -62,21 +63,20 @@ static SpacingBuilder createSpacingBuilder(CodeStyleSettings settings) {
6263
.before(OP_COMMA).spacing(spacesBeforeComma, spacesBeforeComma, 0, false, 0)
6364
.after(OP_COMMA).spaceIf(commonSettings.SPACE_AFTER_COMMA)
6465

65-
.between(NODE_LABEL, BRACKET_CURLYOPEN).spaces(1)
66+
.between(NODE_LABELS, PROPERTIES).spaces(spacesAfterLabel)
6667
.between(PARENTHESIZED_EXPRESSION, PATTERN).spaceIf(false)
67-
.around(OP_PLUS).spaces(1)
68-
.around(OP_MINUS).spaces(1)
69-
.around(OP_MUL).spaces(1)
70-
.around(OP_DIVIDE).spaces(1)
71-
.around(OP_MODULO).spaces(1)
72-
.around(OP_POW).spaces(1)
73-
.around(OP_EQUAL).spaces(1)
74-
.around(OP_NOTEQUALS).spaces(1)
75-
.around(OP_LESSTHEN).spaces(1)
76-
.around(OP_GREATHERTHEN).spaces(1)
77-
.around(OP_LESSTHANEQUALS).spaces(1)
78-
.around(OP_GREATERTHANEQUALS).spaces(1)
79-
.between(STATEMENT_ITEM, STATEMENT_ITEM).blankLines(1)
80-
;
68+
.around(OP_PLUS).spaces(spacesAroundAdditiveOperator)
69+
.around(OP_MINUS).spaces(spacesAroundAdditiveOperator)
70+
.around(OP_MUL).spaces(spacesAroundMulOperator)
71+
.around(OP_DIVIDE).spaces(spacesAroundMulOperator)
72+
.around(OP_MODULO).spaces(spacesAroundMulOperator)
73+
.around(OP_POW).spaces(spacesAroundMulOperator)
74+
.around(OP_EQUAL).spaces(spacesAroundEqualityOperator)
75+
.around(OP_NOTEQUALS).spaces(spacesAroundEqualityOperator)
76+
.around(OP_LESSTHEN).spaces(spacesAroundEqualityOperator)
77+
.around(OP_GREATHERTHEN).spaces(spacesAroundEqualityOperator)
78+
.around(OP_LESSTHANEQUALS).spaces(spacesAroundEqualityOperator)
79+
.around(OP_GREATERTHANEQUALS).spaces(spacesAroundEqualityOperator)
80+
.between(STATEMENT_ITEM, STATEMENT_ITEM).blankLines(1);
8181
}
8282
}

ui/jetbrains/src/main/java/com/neueda/jetbrains/plugin/graphdb/jetbrains/formatter/CypherLanguageCodeStyleSettingsProvider.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,18 @@ public void customizeSettings(@NotNull CodeStyleSettingsCustomizable consumer, @
3131
"After ':'",
3232
CodeStyleSettingsCustomizable.SPACES_OTHER);
3333

34+
consumer.showCustomOption(CypherCodeStyleSettings.class,
35+
"SPACE_BETWEEN_LABEL_AND_PARAMS",
36+
"Before params block",
37+
CodeStyleSettingsCustomizable.SPACES_OTHER);
38+
3439
consumer.showStandardOptions("SPACE_WITHIN_BRACKETS",
3540
"SPACE_WITHIN_BRACES",
3641
"SPACE_AFTER_COMMA",
37-
"SPACE_BEFORE_COMMA");
42+
"SPACE_BEFORE_COMMA",
43+
"SPACE_AROUND_EQUALITY_OPERATORS",
44+
"SPACE_AROUND_ADDITIVE_OPERATORS",
45+
"SPACE_AROUND_MULTIPLICATIVE_OPERATORS");
3846
} else if (settingsType == SettingsType.BLANK_LINES_SETTINGS) {
3947
consumer.showStandardOptions("KEEP_BLANK_LINES_IN_CODE");
4048
} else if (settingsType == SettingsType.WRAPPING_AND_BRACES_SETTINGS) {
@@ -66,8 +74,8 @@ public CommonCodeStyleSettings getDefaultCommonSettings() {
6674

6775
@Override
6876
public String getCodeSample(@NotNull SettingsType settingsType) {
69-
return "MATCH (a:Person)-[r:WORKS_IN]->(b:Company)\n"
70-
+ "WHERE a.name='Peter'\n"
71-
+ "RETURN a,b,r;";
77+
return "MATCH (a:Person{name:\"Dmitry\"})-[r:WORKS_IN]->(b:Company) "
78+
+ "WHERE b.title='Neueda' "
79+
+ "RETURN a,b,r LIMIT 5";
7280
}
7381
}

0 commit comments

Comments
 (0)