Skip to content

Commit 6527125

Browse files
committed
Optimize recognition of changes in the highlighting
1 parent 2969b37 commit 6527125

5 files changed

Lines changed: 42 additions & 42 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ task wrapper(type: Wrapper) {
7575
// Information about the plugin
7676

7777
// Plugin version number
78-
version '3.0pre7'
78+
version '3.0pre8'
7979

8080
intellij {
8181
version = '2017.3.1'

src/de/halirutan/mathematica/codeinsight/inspections/symbol/UnresolvedSymbolInspection.kt

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ import de.halirutan.mathematica.lang.psi.api.Symbol
4040
import de.halirutan.mathematica.lang.resolve.MathematicaGlobalResolveCache
4141

4242
/**
43-
*
44-
* @author patrick (13.09.17).
43+
* Provides warning annotations to symbols that could not be resolved to some place of definition.
4544
*/
4645
class UnresolvedSymbolInspection : AbstractInspection() {
4746

@@ -67,32 +66,10 @@ class UnresolvedSymbolInspection : AbstractInspection() {
6766
}
6867
return@PsiElementProcessor true
6968
}
70-
71-
// { symbol: Symbol? ->
72-
// if (symbol is Symbol && symbol.localizationConstruct == LocalizationConstruct.MScope.NULL_SCOPE) {
73-
// holder.registerProblem(symbol, InspectionBundle.message("symbol.unresolved.message"))
74-
// }
75-
// }
7669
)
7770
}
7871
}
79-
80-
// override fun visitSymbol(symbol: Symbol?) {
81-
// symbol?.let {
82-
// val localizationConstruct = symbol.localizationConstruct
83-
// if (localizationConstruct == LocalizationConstruct.MScope.NULL_SCOPE || localizationConstruct == LocalizationConstruct.MScope.FILE_SCOPE) {
84-
// ReferencesSearch.search(symbol, GlobalSearchScope.FilesScope.fileScope(symbol.containingFile)).forEach { ref ->
85-
// ref.element?.let {
86-
// if (it is Symbol && it.localizationConstruct == LocalizationConstruct.MScope.NULL_SCOPE) {
87-
// holder.registerProblem(symbol, InspectionBundle.message("symbol.unresolved.message"))
88-
// }
89-
// }
90-
// }
91-
// }
92-
// }
93-
// }
9472
}
95-
9673
}
9774

9875
}

src/de/halirutan/mathematica/lang/psi/LocalizationConstruct.java

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,39 @@ public enum ScopeType {
104104
}
105105

106106
public enum MScope {
107-
MODULE("Module", ScopeType.MODULE_LIKE, 1, 0, 0), BLOCK("Block", ScopeType.MODULE_LIKE, 1, 0, 0), DYNAMICMODULE("DynamicModule", ScopeType.MODULE_LIKE, 1, 0, 0), WITH("With", ScopeType.MODULE_LIKE, -1, 0, -2), FUNCTION("Function", ScopeType.FUNCTION_LIKE, 1, 0, 0), TABLE("Table", ScopeType.TABLE_LIKE, 0, 1, -1), DO("Do", ScopeType.TABLE_LIKE, 0, 1, -1), SUM("Sum", ScopeType.TABLE_LIKE, 0, 1, -1), NSUM("NSum", ScopeType.TABLE_LIKE, 0, 1, -1), INTEGRATE("Integrate", ScopeType.TABLE_LIKE, 0, 1, -1), NINTEGRATE("NIntegrate", ScopeType.TABLE_LIKE, 0, 1, -1),
108-
109-
PLOT("Plot", ScopeType.TABLE_LIKE, 0, 1, 1), PLOT3D("Plot3D", ScopeType.TABLE_LIKE, 0, 1, 2), CONTOURPLOT("ContourPlot", ScopeType.TABLE_LIKE, 0, 1, 2), CONTOURPLOT3D("ContourPlot3D", ScopeType.TABLE_LIKE, 0, 1, 3), PARAMETRICPLOT("ParametricPlot", ScopeType.TABLE_LIKE, 0, 1, 2), PARAMETRICPLOT3D("ParametricPlot3D", ScopeType.TABLE_LIKE, 0, 1, 2), STREAMPLOT("StreamPlot", ScopeType.TABLE_LIKE, 0, 1, 2), STREAMDENSITYPLOT("StreamDensityPlot", ScopeType.TABLE_LIKE, 0, 1, 2), VECTORPLOT("VectorPlot", ScopeType.TABLE_LIKE, 0, 1, 2), VECTORPLOT3D("VectorPlot3D", ScopeType.TABLE_LIKE, 0, 1, 3),
110-
111-
LIMIT("Limit", ScopeType.LIMIT_LIKE, 0, 1, 1), MANIPULATE("Manipulate", ScopeType.MANIPULATE_LIKE, 0, 1, -1), COMPILE("Compile", ScopeType.COMPILE_LIKE, 1, 0, 0), // The last entries because they are not directly connected to a function call with a special head,
107+
MODULE("Module", ScopeType.MODULE_LIKE, 1, 0, 0),
108+
BLOCK("Block", ScopeType.MODULE_LIKE, 1, 0, 0),
109+
DYNAMICMODULE("DynamicModule", ScopeType.MODULE_LIKE, 1, 0, 0),
110+
WITH("With", ScopeType.MODULE_LIKE, -1, 0, -2),
111+
FUNCTION("Function", ScopeType.FUNCTION_LIKE, 1, 0, 0),
112+
TABLE("Table", ScopeType.TABLE_LIKE, 0, 1, -1),
113+
DO("Do", ScopeType.TABLE_LIKE, 0, 1, -1),
114+
SUM("Sum", ScopeType.TABLE_LIKE, 0, 1, -1),
115+
NSUM("NSum", ScopeType.TABLE_LIKE, 0, 1, -1),
116+
INTEGRATE("Integrate", ScopeType.TABLE_LIKE, 0, 1, -1),
117+
NINTEGRATE("NIntegrate", ScopeType.TABLE_LIKE, 0, 1, -1),
118+
PLOT("Plot", ScopeType.TABLE_LIKE, 0, 1, 1),
119+
PLOT3D("Plot3D", ScopeType.TABLE_LIKE, 0, 1, 2),
120+
CONTOURPLOT("ContourPlot", ScopeType.TABLE_LIKE, 0, 1, 2),
121+
CONTOURPLOT3D("ContourPlot3D", ScopeType.TABLE_LIKE, 0, 1, 3),
122+
PARAMETRICPLOT("ParametricPlot", ScopeType.TABLE_LIKE, 0, 1, 2),
123+
PARAMETRICPLOT3D("ParametricPlot3D", ScopeType.TABLE_LIKE, 0, 1, 2),
124+
STREAMPLOT("StreamPlot", ScopeType.TABLE_LIKE, 0, 1, 2),
125+
STREAMDENSITYPLOT("StreamDensityPlot", ScopeType.TABLE_LIKE, 0, 1, 2),
126+
VECTORPLOT("VectorPlot", ScopeType.TABLE_LIKE, 0, 1, 2),
127+
VECTORPLOT3D("VectorPlot3D", ScopeType.TABLE_LIKE, 0, 1, 3),
128+
LIMIT("Limit", ScopeType.LIMIT_LIKE, 0, 1, 1),
129+
MANIPULATE("Manipulate", ScopeType.MANIPULATE_LIKE, 0, 1, -1),
130+
COMPILE("Compile", ScopeType.COMPILE_LIKE, 1, 0, 0),
131+
// The last entries because they are not directly connected to a function call with a special head,
112132
// because we create the scope from the PsiElement automatically.
113-
ANONYMOUS_FUNCTION_SCOPE("AnonymousFunction Scope", ScopeType.ANONYMOUS_FUNCTION_LIKE, 0, 1, 1), RULEDELAYED_SCOPE("RuleDelayed Scope", ScopeType.RULE_LIKE, 1, 0, 0), SETDELAYED_SCOPE("SetDelayed Scope", ScopeType.RULE_LIKE, 1, 0, 0), KERNEL_SCOPE("Kernel Scope"), FILE_SCOPE("File Scope"), IMPORT_SCOPE("Import Scope"), NULL_SCOPE("Null Scope");
133+
ANONYMOUS_FUNCTION_SCOPE("AnonymousFunction Scope", ScopeType.ANONYMOUS_FUNCTION_LIKE, 0, 1, 1),
134+
RULEDELAYED_SCOPE("RuleDelayed Scope", ScopeType.RULE_LIKE, 1, 0, 0),
135+
SETDELAYED_SCOPE("SetDelayed Scope", ScopeType.RULE_LIKE, 1, 0, 0),
136+
KERNEL_SCOPE("Kernel Scope"),
137+
FILE_SCOPE("File Scope"),
138+
IMPORT_SCOPE("Import Scope"),
139+
NULL_SCOPE("Null Scope");
114140

115141
final String myName;
116142
final ScopeType myType;
@@ -171,6 +197,4 @@ public int getScopePositionEnd() {
171197
return myScopePositionEnd;
172198
}
173199
}
174-
175-
176200
}

src/de/halirutan/mathematica/lang/psi/impl/SymbolImpl.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
* Symbols with explicit context like <code>Developer`ToPackedArray</code> are parsed as one symbol and this class
5353
* provides methods to separate the parts.
5454
* <br/>
55-
* Provides functionality to resolve where a certain symbol is defined in code. For this, the SymbolPsiReference class
55+
* Provides functionality to resolve where a certain symbol is defined in code. For this, the SymbolPsiReference class
5656
* uses several processors which scan the local scope and global file scope. Note that GlobalDefinitionResolveProcessor
5757
* does not scan the whole file because this would be too slow. Instead, it expects that global symbol definitions are
5858
* done at file-scope. The class uses caching to speed up the resolve process. Once a definition for a symbol is found,
@@ -76,7 +76,8 @@ public SymbolImpl(ASTNode node) {
7676
public PsiElement setName(@NonNls @NotNull String name) {
7777
ASTNode identifierNode = getNode().findChildByType(MathematicaElementTypes.IDENTIFIER);
7878
final PsiFileFactory fileFactory = PsiFileFactory.getInstance(getProject());
79-
final MathematicaPsiFileImpl file = (MathematicaPsiFileImpl) fileFactory.createFileFromText("dummy.m", MathematicaFileType.INSTANCE, name);
79+
final MathematicaPsiFileImpl file =
80+
(MathematicaPsiFileImpl) fileFactory.createFileFromText("dummy.m", MathematicaFileType.INSTANCE, name);
8081
ASTNode newElm = file.getFirstChild().getNode().findChildByType(MathematicaElementTypes.IDENTIFIER);
8182
if (identifierNode != null && newElm != null) {
8283
getNode().replaceChild(identifierNode, newElm);
@@ -126,10 +127,7 @@ public PsiElement getNameIdentifier() {
126127

127128
@NotNull
128129
public MScope getLocalizationConstruct() {
129-
if (myScope == null) {
130-
// this will always set the scope to a valid value
131-
multiResolve(false);
132-
}
130+
multiResolve(false);
133131
return myScope;
134132
}
135133

@@ -191,12 +189,10 @@ public ResolveResult[] multiResolve(boolean incompleteCode) {
191189
}
192190
myScope = MScope.NULL_SCOPE;
193191
return new ResolveResult[]{new SymbolResolveResult(new LightUndefinedSymbol(this), myScope, containingFile, false)};
194-
195192
}
196193

197194
@Override
198195
public void subtreeChanged() {
199-
200196
myScope = null;
201197
}
202198

@@ -226,7 +222,8 @@ public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOpe
226222

227223
@Override
228224
public boolean isReferenceTo(PsiElement element) {
229-
return (element instanceof Symbol || element instanceof LightSymbol) && getManager().areElementsEquivalent(resolve(), element);
225+
return (element instanceof Symbol || element instanceof LightSymbol) &&
226+
getManager().areElementsEquivalent(resolve(), element);
230227
}
231228

232229
@NotNull

src/de/halirutan/mathematica/lang/psi/impl/arithmetic/AbstractArithmeticOperation.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ abstract class AbstractArithmeticOperation extends ExpressionImpl implements Ari
4141
public void accept(@NotNull PsiElementVisitor visitor) {
4242
if (visitor instanceof MathematicaVisitor) {
4343
((MathematicaVisitor) visitor).visitArithmeticOperation(this);
44+
} else {
45+
super.accept(visitor);
4446
}
4547
}
4648
}

0 commit comments

Comments
 (0)