Skip to content

Commit 8626d35

Browse files
committed
- Semantic highlighting for braces, brackets, and parens
- In ChartView range axis values shown in decimal format all the time rather than converting into exponential
1 parent 6c82f8b commit 8626d35

File tree

7 files changed

+102
-43
lines changed

7 files changed

+102
-43
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# KdbInsideBrains Changelog
22

3+
## 6.5.2
4+
5+
### Added
6+
7+
- Semantic highlighting for braces, brackets, and parens
8+
9+
### Fixed
10+
11+
- In ChartView range axis values shown in decimal format all the time rather than converting into exponential
12+
313
## 6.4.0
414

515
### Added

build.gradle.kts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ plugins {
2828
id("idea")
2929
id("signing")
3030
id("maven-publish")
31-
id("org.jetbrains.changelog") version "2.2.1"
32-
id("org.jetbrains.grammarkit") version "2022.3.2.2"
33-
id("org.jetbrains.intellij.platform") version "2.7.0"
31+
id("org.jetbrains.changelog") version "2.5.0"
32+
id("org.jetbrains.grammarkit") version "2023.3.0.1"
33+
id("org.jetbrains.intellij.platform") version "2.10.5"
3434
}
3535

3636
repositories {
@@ -86,13 +86,13 @@ dependencies {
8686

8787
implementation("org.jfree:jfreechart:1.5.6")
8888
implementation("org.jfree:org.jfree.svg:5.0.7")
89-
implementation("org.apache.poi:poi:5.4.1")
90-
implementation("org.apache.poi:poi-ooxml:5.4.1")
89+
implementation("org.apache.poi:poi:5.5.1")
90+
implementation("org.apache.poi:poi-ooxml:5.5.1")
9191

92-
testImplementation("org.mockito:mockito-core:5.17.0")
93-
testImplementation("org.junit.jupiter:junit-jupiter:5.12.2")
94-
testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.10.1")
95-
testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.11.3")
92+
testImplementation("org.mockito:mockito-core:5.21.0")
93+
testImplementation("org.junit.jupiter:junit-jupiter:5.14.2")
94+
testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.14.2")
95+
testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.14.2")
9696
}
9797

9898
// Read more: https://github.com/JetBrains/gradle-intellij-plugin

gradle.properties

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@ pluginUntilBuild=243.*
1414
# or https://jb.gg/intellij-platform-builds-list
1515
# or https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html - check Releases and Snapshor for EAP
1616
#pluginVerifierVersions=2022.3, 2022.3.3, 2023.3.7, 2024.1.5, 2024.3
17-
pluginVerifierVersions=IC-2022.3, IC-2023.3, IC-2024.3.5, IC-2025.1.3, IC-2025.2
17+
pluginVerifierVersions=IC-2022.3, IC-2023.3, IC-2024.3.7, IC-2025.1.4, IC-2025.2.6, IU-2025.3.1
1818

1919
# IDEA Options
20-
platformType=IC
21-
platformVersion=2025.2
22-
platformPlugins=PsiViewer:252.23892.248
20+
platformType=IU
21+
platformVersion=2025.3.1
22+
platformPlugins=PsiViewer:253.7181
23+
#platformType=IC
24+
#platformVersion=2025.2
25+
#platformPlugins=PsiViewer:252.23892.248
2326
#platformVersion=2025.1.3
2427
#platformPlugins=PsiViewer:251.175
2528
#platformVersion=2024.3.5
Lines changed: 67 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
package org.kdb.inside.brains.lang;
22

33
import com.intellij.codeInsight.daemon.RainbowVisitor;
4-
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
54
import com.intellij.codeInsight.daemon.impl.HighlightVisitor;
5+
import com.intellij.openapi.editor.colors.TextAttributesKey;
66
import com.intellij.psi.PsiElement;
77
import com.intellij.psi.PsiFile;
88
import com.intellij.psi.PsiReference;
9+
import com.intellij.psi.tree.IElementType;
910
import org.jetbrains.annotations.NotNull;
10-
import org.jetbrains.annotations.Nullable;
1111
import org.kdb.inside.brains.QFileType;
1212
import org.kdb.inside.brains.psi.*;
1313

14+
import java.util.function.Predicate;
15+
1416
public class QRainbowVisitor extends RainbowVisitor {
1517
@Override
1618
public boolean suitableForFile(@NotNull PsiFile psiFile) {
@@ -20,59 +22,96 @@ public boolean suitableForFile(@NotNull PsiFile psiFile) {
2022
@Override
2123
public void visit(@NotNull PsiElement psiElement) {
2224
if (psiElement instanceof @NotNull QVariable var) {
23-
final HighlightInfo info = createVariableInfo(var);
24-
if (info != null) {
25-
addInfo(info);
25+
createVariableInfo(var);
26+
} else {
27+
final IElementType type = psiElement.getNode().getElementType();
28+
if (type == QTypes.BRACE_OPEN || type == QTypes.BRACE_CLOSE) {
29+
createBraceInfo(psiElement);
30+
} else if (type == QTypes.PAREN_OPEN || type == QTypes.PAREN_CLOSE) {
31+
createParenInfo(psiElement);
32+
} else if (type == QTypes.BRACKET_OPEN || type == QTypes.BRACKET_CLOSE) {
33+
createBracketInfo(psiElement);
2634
}
2735
}
2836
}
2937

30-
private @Nullable HighlightInfo createVariableInfo(@NotNull QVariable var) {
38+
private void createBraceInfo(@NotNull PsiElement psiElement) {
39+
createBracketsInfo(psiElement, "q_rainbow_brace", QSyntaxHighlighter.BRACES, e -> e instanceof QLambdaExpr);
40+
}
41+
42+
private void createParenInfo(@NotNull PsiElement psiElement) {
43+
createBracketsInfo(psiElement, "q_rainbow_paren", QSyntaxHighlighter.PARENTHESES, e -> e instanceof QParenthesesExpr);
44+
}
45+
46+
private void createBracketInfo(@NotNull PsiElement psiElement) {
47+
createBracketsInfo(psiElement, "q_rainbow_bracket", QSyntaxHighlighter.BRACKETS, e -> e instanceof QConditionExpr || e instanceof QArguments || e instanceof QControlExpr || e instanceof QParameters || e instanceof QGroupingExpr);
48+
}
49+
50+
private void createVariableInfo(@NotNull QVariable var) {
3151
final QLambda lambda = var.getContext(QLambda.class);
3252
if (lambda == null) {
33-
return null;
34-
}
35-
36-
if (var instanceof QVarDeclaration d) {
37-
return getInfo(var, d, lambda);
53+
return;
3854
}
3955

4056
if (lambda.isImplicitDeclaration(var)) {
41-
return createInfo(lambda, var);
42-
}
43-
44-
final PsiReference[] references = var.getReferences();
45-
for (PsiReference reference : references) {
46-
final PsiElement resolve = reference.resolve();
47-
if (resolve instanceof QVarDeclaration d) {
48-
final HighlightInfo info = getInfo(var, d, lambda);
49-
if (info != null) {
50-
return info;
57+
createVariableInfo(lambda, var);
58+
} else if (var instanceof QVarDeclaration d) {
59+
createDeclarationInfo(lambda, d, var);
60+
} else {
61+
final PsiReference[] references = var.getReferences();
62+
for (PsiReference reference : references) {
63+
final PsiElement resolve = reference.resolve();
64+
if (resolve instanceof QVarDeclaration d) {
65+
createDeclarationInfo(lambda, d, var);
66+
break;
5167
}
5268
}
5369
}
54-
return null;
5570
}
5671

57-
private @Nullable HighlightInfo getInfo(@NotNull QVariable var, @NotNull QVarDeclaration dec, @NotNull QLambda lambda) {
72+
private void createDeclarationInfo(@NotNull QLambda lambda, @NotNull QVarDeclaration dec, @NotNull QVariable var) {
5873
if (QPsiUtil.isGlobalDeclaration(dec)) {
59-
return null;
74+
return;
6075
}
6176

6277
final ElementScope scope = dec.getVariableContext().getScope();
6378
// only root variables, no tables, dicts and so on
6479
if (scope == ElementScope.PARAMETERS || scope == ElementScope.LAMBDA) {
65-
return createInfo(lambda, var);
80+
createVariableInfo(lambda, var);
81+
}
82+
}
83+
84+
private void createVariableInfo(@NotNull QLambda lambda, @NotNull QVariable var) {
85+
addInfo(getInfo(lambda, var, var.getName(), QSyntaxHighlighter.VARIABLE));
86+
}
87+
88+
private void createBracketsInfo(PsiElement psiElement, String name, TextAttributesKey key, Predicate<PsiElement> predicate) {
89+
final DepthInfo info = calculateDepth(psiElement, predicate);
90+
if (info.context == null || info.depth < 0) {
91+
return;
92+
}
93+
addInfo(getInfo(info.context, psiElement, name + info.depth, key));
94+
}
95+
96+
private DepthInfo calculateDepth(@NotNull PsiElement psiElement, Predicate<PsiElement> predicate) {
97+
int depth = 0;
98+
PsiElement context = null;
99+
PsiElement parent = psiElement.getParent();
100+
while (parent != null) {
101+
if (predicate.test(parent)) {
102+
context = parent;
103+
depth++;
104+
}
105+
parent = parent.getParent();
66106
}
67-
return null;
107+
return new DepthInfo(context, depth - 1);
68108
}
69109

70110
@Override
71111
public @NotNull HighlightVisitor clone() {
72112
return new QRainbowVisitor();
73113
}
74114

75-
private @NotNull HighlightInfo createInfo(@NotNull QLambda lambda, @NotNull QVariable var) {
76-
return getInfo(lambda, var, var.getName(), QSyntaxHighlighter.VARIABLE);
115+
private record DepthInfo(PsiElement context, int depth) {
77116
}
78117
}

src/main/java/org/kdb/inside/brains/settings/KdbColorSettingsPage.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ public Language getLanguage() {
8787

8888
@Override
8989
public boolean isRainbowType(TextAttributesKey type) {
90-
return QSyntaxHighlighter.VARIABLE.equals(type);
90+
return QSyntaxHighlighter.VARIABLE.equals(type) ||
91+
QSyntaxHighlighter.PARENTHESES.equals(type) ||
92+
QSyntaxHighlighter.BRACKETS.equals(type) ||
93+
QSyntaxHighlighter.BRACES.equals(type);
9194
}
9295

9396
@Override

src/main/java/org/kdb/inside/brains/view/chart/ChartViewPanel.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.io.FileOutputStream;
4040
import java.io.FileWriter;
4141
import java.io.OutputStream;
42+
import java.text.DecimalFormat;
4243
import java.util.List;
4344
import java.util.function.Supplier;
4445

@@ -47,6 +48,8 @@
4748
public class ChartViewPanel extends ChartPanel {
4849
private final Supplier<List<ActionGroup>> popupActionsProvider;
4950

51+
private static final DecimalFormat NUMBER_VALUE_FORMATTER = new DecimalFormat("###,###,###.##");
52+
5053
private static final JBColor COLOR_GRID = new JBColor(new Color(0xd3d3d4), new Color(0xd3d3d4));
5154

5255
public ChartViewPanel(Supplier<List<ActionGroup>> popupActionsProvider) {
@@ -178,6 +181,7 @@ protected void initializeAxis(ValueAxis axis) {
178181

179182
if (axis instanceof NumberAxis a) {
180183
a.setAutoRangeIncludesZero(false);
184+
a.setNumberFormatOverride(NUMBER_VALUE_FORMATTER);
181185
// Leads to wrong values display
182186
// } else if (axis instanceof DateAxis a) {
183187
// a.setTimeZone(UTC_TIMEZONE);

version.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
pluginVersion=6.4.0
1+
pluginVersion=6.5.2

0 commit comments

Comments
 (0)