77import com .intellij .psi .PsiFile ;
88import com .intellij .psi .PsiReference ;
99import org .jetbrains .annotations .NotNull ;
10+ import org .jetbrains .annotations .Nullable ;
1011import org .kdb .inside .brains .QFileType ;
11- import org .kdb .inside .brains .psi .ElementScope ;
12- import org .kdb .inside .brains .psi .QLambda ;
13- import org .kdb .inside .brains .psi .QVarDeclaration ;
14- import org .kdb .inside .brains .psi .QVariable ;
12+ import org .kdb .inside .brains .psi .*;
1513
1614public class QRainbowVisitor extends RainbowVisitor {
1715 @ Override
@@ -21,12 +19,15 @@ public boolean suitableForFile(@NotNull PsiFile psiFile) {
2119
2220 @ Override
2321 public void visit (@ NotNull PsiElement psiElement ) {
24- if (psiElement instanceof @ NotNull QVariable var && !var .isGlobal ()) {
25- addInfo (createVariableInfo (var ));
22+ if (psiElement instanceof @ NotNull QVariable var ) {
23+ final HighlightInfo info = createVariableInfo (var );
24+ if (info != null ) {
25+ addInfo (info );
26+ }
2627 }
2728 }
2829
29- private HighlightInfo createVariableInfo (@ NotNull QVariable var ) {
30+ private @ Nullable HighlightInfo createVariableInfo (@ NotNull QVariable var ) {
3031 final QLambda lambda = var .getContext (QLambda .class );
3132 if (lambda == null ) {
3233 return null ;
@@ -36,6 +37,10 @@ private HighlightInfo createVariableInfo(@NotNull QVariable var) {
3637 return getInfo (var , d , lambda );
3738 }
3839
40+ if (lambda .isImplicitDeclaration (var )) {
41+ return createInfo (lambda , var );
42+ }
43+
3944 final PsiReference [] references = var .getReferences ();
4045 for (PsiReference reference : references ) {
4146 final PsiElement resolve = reference .resolve ();
@@ -49,15 +54,15 @@ private HighlightInfo createVariableInfo(@NotNull QVariable var) {
4954 return null ;
5055 }
5156
52- private HighlightInfo getInfo (QVariable v , QVarDeclaration d , QLambda lambda ) {
53- if (d . isGlobal ( )) {
57+ private @ Nullable HighlightInfo getInfo (@ NotNull QVariable var , @ NotNull QVarDeclaration dec , @ NotNull QLambda lambda ) {
58+ if (QPsiUtil . isGlobalDeclaration ( dec )) {
5459 return null ;
5560 }
5661
57- final ElementScope scope = d .getVariableContext ().getScope ();
62+ final ElementScope scope = dec .getVariableContext ().getScope ();
5863 // only root variables, no tables, dicts and so on
5964 if (scope == ElementScope .PARAMETERS || scope == ElementScope .LAMBDA ) {
60- return getInfo (lambda , v , v . getName (), QSyntaxHighlighter . VARIABLE );
65+ return createInfo (lambda , var );
6166 }
6267 return null ;
6368 }
@@ -66,4 +71,8 @@ private HighlightInfo getInfo(QVariable v, QVarDeclaration d, QLambda lambda) {
6671 public @ NotNull HighlightVisitor clone () {
6772 return new QRainbowVisitor ();
6873 }
74+
75+ private @ NotNull HighlightInfo createInfo (@ NotNull QLambda lambda , @ NotNull QVariable var ) {
76+ return getInfo (lambda , var , var .getName (), QSyntaxHighlighter .VARIABLE );
77+ }
6978}
0 commit comments