Skip to content

Commit 11bdfb3

Browse files
committed
Fixed wrong highlighting when using patterns and Set
Fixed equals and hashcode for lightSymbol
1 parent 290da60 commit 11bdfb3

4 files changed

Lines changed: 31 additions & 5 deletions

File tree

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,30 @@ public SearchScope getUseScope() {
6969
return myFile.getUseScope();
7070
}
7171

72+
@Override
73+
public int hashCode() {
74+
int hash = 1;
75+
hash = hash*17 + myName.hashCode();
76+
hash = hash * 31 + myFile.hashCode();
77+
return hash;
78+
}
79+
80+
@Override
81+
public boolean equals(Object obj) {
82+
if (obj != null && obj instanceof LightSymbol) {
83+
return obj.hashCode() == hashCode();
84+
}
85+
return false;
86+
}
87+
7288
@Override
7389
public boolean isEquivalentTo(PsiElement another) {
74-
if (another instanceof Symbol || another instanceof LightSymbol) {
75-
final String name = ((PsiNamedElement) another).getName();
76-
return myName.equals(name);
90+
if (another instanceof Symbol) {
91+
final PsiElement resolve = ((Symbol) another).resolve();
92+
return resolve != null && resolve.equals(this);
93+
}
94+
if (another instanceof LightSymbol) {
95+
return another.hashCode() == hashCode();
7796
}
7897
return false;
7998
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,6 @@ public Object[] getVariants() {
220220

221221
@Override
222222
public boolean isSoft() {
223-
return true;
223+
return false;
224224
}
225225
}

src/de/halirutan/mathematica/lang/psi/util/MathematicaPatternVisitor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ public class MathematicaPatternVisitor extends MathematicaVisitor {
4545

4646
private final Set<Symbol> myPatternSymbols = Sets.newHashSet();
4747
private final LinkedHashSet<Symbol> myUnboundSymbols = Sets.newLinkedHashSet();
48+
/* Except | Longest | Optional | PatternTest | Repeated | RepeatedNull | Shortest
49+
* HoldPattern | IgnoringInactive | KeyValuePattern | Literal | Longest | Optional | Repeated | RepeatedNull | Shortest
50+
* */
4851
private final List<String> myDiveInFirstChild = Lists.newArrayList("Longest", "Shortest", "Repeated", "Optional", "PatternTest", "Condition");
4952
private final List<String> myDoNotDiveIn = Lists.newArrayList("Verbatim");
5053
private Assignment myAssignmentType = Assignment.NONE_;

src/de/halirutan/mathematica/lang/resolve/LocalDefinitionResolveProcessor.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.intellij.psi.util.PsiTreeUtil;
3030
import de.halirutan.mathematica.lang.psi.api.FunctionCall;
3131
import de.halirutan.mathematica.lang.psi.api.Symbol;
32+
import de.halirutan.mathematica.lang.psi.api.assignment.Set;
3233
import de.halirutan.mathematica.lang.psi.api.assignment.SetDelayed;
3334
import de.halirutan.mathematica.lang.psi.api.assignment.TagSetDelayed;
3435
import de.halirutan.mathematica.lang.psi.api.rules.RuleDelayed;
@@ -144,12 +145,15 @@ public boolean execute(@NotNull PsiElement element, @NotNull ResolveState state)
144145
}
145146
}
146147
}
147-
} else if (element instanceof SetDelayed || element instanceof TagSetDelayed) {
148+
} else if (element instanceof SetDelayed || element instanceof TagSetDelayed || element instanceof Set) {
148149

149150
MathematicaPatternVisitor patternVisitor = new MathematicaPatternVisitor();
150151
element.accept(patternVisitor);
151152
for (Symbol p : patternVisitor.getPatternSymbols()) {
152153
if (p.getFullSymbolName().equals(myStartElement.getFullSymbolName())) {
154+
if (element instanceof Set && myStartElement != p) {
155+
continue;
156+
}
153157
myReferringSymbol = p;
154158
myLocalization = MScope.SETDELAYEDPATTERN;
155159
myLocalizationSymbol = element;

0 commit comments

Comments
 (0)