Skip to content

Commit fd929fa

Browse files
committed
More work on better reference search
1 parent af1eb78 commit fd929fa

17 files changed

Lines changed: 262 additions & 188 deletions

resources/META-INF/plugin.xml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@
4444
<lang.psiStructureViewFactory language="Mathematica" implementationClass="de.halirutan.mathematica.codeinsight.structureview.MathematicaStructureViewFactory"/>
4545
<lang.documentationProvider language="Mathematica" implementationClass="de.halirutan.mathematica.documentation.MathematicaDocumentationProvider"/>
4646

47-
<annotator language="Mathematica" implementationClass="de.halirutan.mathematica.codeinsight.highlighting.MathematicaHighlightingAnnotator"/>
48-
4947
<psi.referenceContributor language="Mathematica" implementation="de.halirutan.mathematica.lang.resolve.MathematicaReferenceContributor"/>
5048
<fileBasedIndex implementation="de.halirutan.mathematica.index.packageexport.MathematicaPackageExportIndex"/>
5149
<lang.refactoringSupport language="Mathematica" implementationClass="de.halirutan.mathematica.refactoring.MathematicaRefactoringSupport"/>
@@ -88,7 +86,12 @@
8886
<additionalTextAttributes scheme="Darcula" file="colors/MathematicaDarcula.xml"/>
8987
<additionalTextAttributes scheme="Default" file="colors/MathematicaDefault.xml"/>
9088
<lang.refactoringSupport language="Mathematica" implementationClass="de.halirutan.mathematica.refactoring.MathematicaRefactoringSupport"/>
91-
<annotator language="Mathematica" implementationClass="de.halirutan.mathematica.codeinsight.highlighting.CommentAnnotator"/>
89+
90+
<annotator language="Mathematica" implementationClass="de.halirutan.mathematica.codeinsight.highlighting.annotators.LocalizedSymbolAnnotator"/>
91+
<annotator language="Mathematica" implementationClass="de.halirutan.mathematica.codeinsight.highlighting.annotators.CommentAnnotator"/>
92+
<annotator language="Mathematica" implementationClass="de.halirutan.mathematica.codeinsight.highlighting.annotators.MessageNameAnnotator"/>
93+
<annotator language="Mathematica" implementationClass="de.halirutan.mathematica.codeinsight.highlighting.annotators.StringifiedSymbolAnnotator"/>
94+
<annotator language="Mathematica" implementationClass="de.halirutan.mathematica.codeinsight.highlighting.annotators.FunctionAnnotator"/>
9295

9396
<inspectionToolProvider implementation="de.halirutan.mathematica.codeinsight.inspections.MathematicaInspectionProvider"/>
9497

@@ -105,6 +108,7 @@
105108
<!--<findUsagesHandlerFactory implementation="de.halirutan.mathematica.find.MathematicaFindUsageHandlerFactory"/>-->
106109

107110
<errorHandler implementation="de.halirutan.mathematica.errorreporting.GitHubErrorReporter"/>
111+
<referencesSearch implementation="de.halirutan.mathematica.lang.search.MathematicaReferenceSearch"/>
108112
</extensions>
109113

110114
<actions>

resources/de/halirutan/mathematica/MathematicaInspectionBundle.properties

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
group.bugs=Probable Errors
2323
group.codestyle=Code Style
24+
group.symbol=Symbols
2425

2526
consistent.compound.expression.in.file.name=Missing semicolon at file-scope
2627
consistent.compound.expression.in.file.description=At file scope it is considered good code-style, when all separate expressions are closed with a semicolon.
@@ -30,3 +31,6 @@ bugs.implicit.times.through.linebreak.description=This linebreak is interpreted
3031
bugs.implicit.times.through.linebreak.message=Missing comma or semicolon
3132
bugs.unsupported.version.name=Function is part of later version
3233
bugs.unsupported.version.description=Reports functions or symbols that are part of a later version of Mathematica than specified. Per default, the language version of the specified Mathematica SDK is used.
34+
symbol.unresolved.name=Unresolved Symbol
35+
symbol.unresolved.description=The place where this symbol is defined could not be found. This usually means that you used a symbol that has no definition, no usage message, is not a built-in symbol or is not locally bound by Module, Table, Compile, ...
36+
symbol.unresolved.message=Could not resolve symbol declaration

src/de/halirutan/mathematica/codeinsight/structureview/groupers/AssignmentTypeGroup.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class AssignmentTypeGroup implements Group, CodePlaceProvider, ColoredIte
4646
private final Collection<TreeElement> myTreeElements;
4747
private final SymbolAssignmentType myType;
4848

49-
public AssignmentTypeGroup(final SymbolAssignmentType type, final Collection<TreeElement> treeElements) {
49+
AssignmentTypeGroup(final SymbolAssignmentType type, final Collection<TreeElement> treeElements) {
5050
this.myTreeElements = treeElements;
5151
this.myType = type;
5252
}
@@ -83,11 +83,11 @@ public TextAttributesKey getTextAttributesKey() {
8383
case UP_SET_DELAYED_ASSIGNMENT:
8484
return DefaultLanguageHighlighterColors.INSTANCE_METHOD;
8585
case MESSAGE_ASSIGNMENT:
86-
return MathematicaSyntaxHighlighterColors.MESSAGE;
86+
return MathematicaSyntaxHighlighterColors.INSTANCE.getMESSAGE();
8787
case OPTIONS_ASSIGNMENT:
88-
return MathematicaSyntaxHighlighterColors.MODULE_LOCALIZED;
88+
return MathematicaSyntaxHighlighterColors.INSTANCE.getMODULE_LOCALIZED();
8989
case ATTRIBUTES_ASSIGNMENT:
90-
return MathematicaSyntaxHighlighterColors.BUILTIN_FUNCTION;
90+
return MathematicaSyntaxHighlighterColors.INSTANCE.getBUILTIN_FUNCTION();
9191
}
9292
return null;
9393
}

src/de/halirutan/mathematica/intentions/localization/MoveVariableToLocalisation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file
8181
PsiElement resolve = reference.resolve();
8282
if (resolve instanceof Symbol) {
8383
LocalizationConstruct.MScope elementConstruct = ((Symbol) resolve).getLocalizationConstruct();
84-
if (elementConstruct != LocalizationConstruct.MScope.NULL) {
84+
if (elementConstruct != LocalizationConstruct.MScope.NULL_SCOPE) {
8585
return false;
8686
}
8787
}

src/de/halirutan/mathematica/lang/psi/api/FunctionCall.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public interface FunctionCall extends PsiElement {
7575
/**
7676
* Returns the type of scoping construct, if the function call is e.g. <code >Module[..]</code>
7777
*
78-
* @return The scoping construct or MScope.NULL if it is no scoping construct.
78+
* @return The scoping construct or MScope.NULL_SCOPE if it is no scoping construct.
7979
*/
8080
MScope getScopingConstruct();
8181

src/de/halirutan/mathematica/lang/psi/api/Symbol.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import com.intellij.psi.PsiElement;
2525
import com.intellij.psi.PsiNameIdentifierOwner;
2626
import com.intellij.psi.PsiReference;
27-
import de.halirutan.mathematica.lang.psi.util.LocalizationConstruct;
2827
import de.halirutan.mathematica.lang.psi.util.LocalizationConstruct.MScope;
2928
import de.halirutan.mathematica.lang.resolve.SymbolResolveResult;
3029

@@ -51,6 +50,7 @@ public interface Symbol extends PsiNameIdentifierOwner, PsiReference {
5150

5251
/**
5352
* Returns the full name of the symbol with context.
53+
*
5454
* @return Symbol name with context
5555
*/
5656
String getFullSymbolName();
@@ -68,4 +68,10 @@ public interface Symbol extends PsiNameIdentifierOwner, PsiReference {
6868
SymbolResolveResult advancedResolve();
6969

7070
boolean isSelfReference();
71+
72+
/**
73+
* Checks if this symbol is locally scoped by Module, ...
74+
* @return true if it is bound by a localization function
75+
*/
76+
boolean isLocallyBound();
7177
}

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

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,22 @@
3333
import de.halirutan.mathematica.lang.psi.util.LocalizationConstruct.MScope;
3434
import de.halirutan.mathematica.lang.resolve.processors.SymbolResolveHint;
3535
import org.jetbrains.annotations.NotNull;
36-
import org.jetbrains.annotations.Nullable;
3736

3837
import java.util.List;
3938

4039
public class FunctionCallImpl extends ExpressionImpl implements FunctionCall {
4140

42-
// private final Key<Object> myScopeKey = Key.create("SCOPING_CONSTRUCT");
43-
// private boolean myIsUpToDate;
44-
private String myHead;
45-
private MScope myLocalizationConstruct = MScope.NULL;
41+
private final String myHead;
42+
private MScope myLocalizationConstruct = MScope.NULL_SCOPE;
43+
private final boolean myIsScopingFunction;
4644

4745

4846
public FunctionCallImpl(@NotNull ASTNode node) {
4947
super(node);
5048
// myIsUpToDate = false;
5149
myHead = node.getFirstChildNode().getText();
52-
myLocalizationConstruct = LocalizationConstruct.getType(myHead);
50+
myIsScopingFunction = LocalizationConstruct.isScopingFunction(myHead);
51+
myLocalizationConstruct = myIsScopingFunction ? LocalizationConstruct.getScope(myHead) : MScope.NULL_SCOPE;
5352
}
5453

5554
@Override
@@ -125,36 +124,15 @@ public List<PsiElement> getParameters() {
125124
return allArguments;
126125
}
127126

128-
129-
/**
130-
* Extracts the head of the function call and looks whether it is in the list {@link #SCOPING_CONSTRUCTS}. This can
131-
* lead to various false negatives. E.g. <code >(Block)[{..},..]</code> returns false, although after <em
132-
* >evaluating</em> the code in Mathematica, it's of course found to be a correct scoping construct. Btw, the
133-
* Mathematica front end has the same issues.
134-
*
135-
* @return True iff the head is a symbol defining the function as scoping construct like <code >Block[{..},..]</code>.
136-
*/
137-
138127
@Override
139128
public boolean isScopingConstruct() {
140-
return myLocalizationConstruct != MScope.NULL;
129+
return myIsScopingFunction;
141130
}
142131

143132
@Override
144133
public MScope getScopingConstruct() {
145134
return myLocalizationConstruct;
146135
}
147-
//
148-
// private void cacheScopingConstruct() {
149-
// if (myIsUpToDate) return;
150-
// PsiElement head = getFirstChild();
151-
// if (head instanceof Symbol) {
152-
// cacheScopingConstruct(((Symbol) head).getSymbolName());
153-
// } else {
154-
// putUserData(myScopeKey, MScope.NULL);
155-
// }
156-
// myIsUpToDate = true;
157-
// }
158136

159137
@Override
160138
public void accept(@NotNull PsiElementVisitor visitor) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,6 @@ public LightBuiltInSymbol(@NotNull Symbol symbol) {
3434
super(symbol);
3535
}
3636

37+
38+
3739
}

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
*/
3535
public class LightSymbol extends LightElement implements PsiNamedElement {
3636
private String myName;
37-
private PsiFile myFile;
37+
private final PsiFile myFile;
3838

3939
LightSymbol(@NotNull Symbol symbol) {
4040
super(symbol.getManager(), MathematicaLanguage.INSTANCE);
@@ -79,10 +79,7 @@ public int hashCode() {
7979

8080
@Override
8181
public boolean equals(Object obj) {
82-
if (obj != null && obj instanceof LightSymbol) {
83-
return obj.hashCode() == hashCode();
84-
}
85-
return false;
82+
return obj != null && obj instanceof LightSymbol && obj.hashCode() == hashCode();
8683
}
8784

8885
@Override
@@ -91,9 +88,6 @@ public boolean isEquivalentTo(PsiElement another) {
9188
final PsiElement resolve = ((Symbol) another).resolve();
9289
return resolve != null && resolve.equals(this);
9390
}
94-
if (another instanceof LightSymbol) {
95-
return another.hashCode() == hashCode();
96-
}
97-
return false;
91+
return another instanceof LightSymbol && another.hashCode() == hashCode();
9892
}
9993
}

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import de.halirutan.mathematica.lang.parsing.MathematicaElementTypes;
3131
import de.halirutan.mathematica.lang.psi.MathematicaVisitor;
3232
import de.halirutan.mathematica.lang.psi.api.Symbol;
33+
import de.halirutan.mathematica.lang.psi.util.LocalizationConstruct;
3334
import de.halirutan.mathematica.lang.psi.util.LocalizationConstruct.MScope;
3435
import de.halirutan.mathematica.lang.resolve.MathematicaSymbolResolver;
3536
import de.halirutan.mathematica.lang.resolve.SymbolResolveResult;
@@ -59,9 +60,11 @@ public class SymbolImpl extends ExpressionImpl implements Symbol {
5960

6061
private static final MathematicaSymbolResolver RESOLVER = new MathematicaSymbolResolver();
6162

62-
private MScope myScope = MScope.NULL;
63+
private MScope myScope = MScope.NULL_SCOPE;
64+
private PsiElement myScopeElement = null;
6365
private boolean mySelfReferenceQ = false;
6466

67+
6568
public SymbolImpl(ASTNode node) {
6669
super(node);
6770
}
@@ -165,6 +168,9 @@ public PsiElement resolve() {
165168
final SymbolResolveResult symbolResolveResult = advancedResolve();
166169
if (symbolResolveResult != null) {
167170
myScope = symbolResolveResult.getLocalization();
171+
if (LocalizationConstruct.isLocalScoping(myScope)) {
172+
myScopeElement = symbolResolveResult.getElement();
173+
}
168174
mySelfReferenceQ = Objects.equals(symbolResolveResult.getElement(), this);
169175
return symbolResolveResult.getElement();
170176
}
@@ -182,6 +188,11 @@ public boolean isSelfReference() {
182188
return mySelfReferenceQ;
183189
}
184190

191+
@Override
192+
public boolean isLocallyBound() {
193+
return myScopeElement != null && myScopeElement.isValid();
194+
}
195+
185196
@NotNull
186197
@Override
187198
public String getCanonicalText() {

0 commit comments

Comments
 (0)