Skip to content

Commit

Permalink
Optimize recognition of changes in the highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
halirutan committed Dec 28, 2017
1 parent 2969b37 commit 6527125
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 42 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ task wrapper(type: Wrapper) {
// Information about the plugin

// Plugin version number
version '3.0pre7'
version '3.0pre8'

intellij {
version = '2017.3.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ import de.halirutan.mathematica.lang.psi.api.Symbol
import de.halirutan.mathematica.lang.resolve.MathematicaGlobalResolveCache

/**
*
* @author patrick (13.09.17).
* Provides warning annotations to symbols that could not be resolved to some place of definition.
*/
class UnresolvedSymbolInspection : AbstractInspection() {

Expand All @@ -67,32 +66,10 @@ class UnresolvedSymbolInspection : AbstractInspection() {
}
return@PsiElementProcessor true
}

// { symbol: Symbol? ->
// if (symbol is Symbol && symbol.localizationConstruct == LocalizationConstruct.MScope.NULL_SCOPE) {
// holder.registerProblem(symbol, InspectionBundle.message("symbol.unresolved.message"))
// }
// }
)
}
}

// override fun visitSymbol(symbol: Symbol?) {
// symbol?.let {
// val localizationConstruct = symbol.localizationConstruct
// if (localizationConstruct == LocalizationConstruct.MScope.NULL_SCOPE || localizationConstruct == LocalizationConstruct.MScope.FILE_SCOPE) {
// ReferencesSearch.search(symbol, GlobalSearchScope.FilesScope.fileScope(symbol.containingFile)).forEach { ref ->
// ref.element?.let {
// if (it is Symbol && it.localizationConstruct == LocalizationConstruct.MScope.NULL_SCOPE) {
// holder.registerProblem(symbol, InspectionBundle.message("symbol.unresolved.message"))
// }
// }
// }
// }
// }
// }
}

}

}
40 changes: 32 additions & 8 deletions src/de/halirutan/mathematica/lang/psi/LocalizationConstruct.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,39 @@ public enum ScopeType {
}

public enum MScope {
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),

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),

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,
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),
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),
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,
// because we create the scope from the PsiElement automatically.
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");
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");

final String myName;
final ScopeType myType;
Expand Down Expand Up @@ -171,6 +197,4 @@ public int getScopePositionEnd() {
return myScopePositionEnd;
}
}


}
15 changes: 6 additions & 9 deletions src/de/halirutan/mathematica/lang/psi/impl/SymbolImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
* Symbols with explicit context like <code>Developer`ToPackedArray</code> are parsed as one symbol and this class
* provides methods to separate the parts.
* <br/>
* Provides functionality to resolve where a certain symbol is defined in code. For this, the SymbolPsiReference class
* Provides functionality to resolve where a certain symbol is defined in code. For this, the SymbolPsiReference class
* uses several processors which scan the local scope and global file scope. Note that GlobalDefinitionResolveProcessor
* does not scan the whole file because this would be too slow. Instead, it expects that global symbol definitions are
* done at file-scope. The class uses caching to speed up the resolve process. Once a definition for a symbol is found,
Expand All @@ -76,7 +76,8 @@ public SymbolImpl(ASTNode node) {
public PsiElement setName(@NonNls @NotNull String name) {
ASTNode identifierNode = getNode().findChildByType(MathematicaElementTypes.IDENTIFIER);
final PsiFileFactory fileFactory = PsiFileFactory.getInstance(getProject());
final MathematicaPsiFileImpl file = (MathematicaPsiFileImpl) fileFactory.createFileFromText("dummy.m", MathematicaFileType.INSTANCE, name);
final MathematicaPsiFileImpl file =
(MathematicaPsiFileImpl) fileFactory.createFileFromText("dummy.m", MathematicaFileType.INSTANCE, name);
ASTNode newElm = file.getFirstChild().getNode().findChildByType(MathematicaElementTypes.IDENTIFIER);
if (identifierNode != null && newElm != null) {
getNode().replaceChild(identifierNode, newElm);
Expand Down Expand Up @@ -126,10 +127,7 @@ public PsiElement getNameIdentifier() {

@NotNull
public MScope getLocalizationConstruct() {
if (myScope == null) {
// this will always set the scope to a valid value
multiResolve(false);
}
multiResolve(false);
return myScope;
}

Expand Down Expand Up @@ -191,12 +189,10 @@ public ResolveResult[] multiResolve(boolean incompleteCode) {
}
myScope = MScope.NULL_SCOPE;
return new ResolveResult[]{new SymbolResolveResult(new LightUndefinedSymbol(this), myScope, containingFile, false)};

}

@Override
public void subtreeChanged() {

myScope = null;
}

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

@Override
public boolean isReferenceTo(PsiElement element) {
return (element instanceof Symbol || element instanceof LightSymbol) && getManager().areElementsEquivalent(resolve(), element);
return (element instanceof Symbol || element instanceof LightSymbol) &&
getManager().areElementsEquivalent(resolve(), element);
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ abstract class AbstractArithmeticOperation extends ExpressionImpl implements Ari
public void accept(@NotNull PsiElementVisitor visitor) {
if (visitor instanceof MathematicaVisitor) {
((MathematicaVisitor) visitor).visitArithmeticOperation(this);
} else {
super.accept(visitor);
}
}
}

0 comments on commit 6527125

Please sign in to comment.