Skip to content

Commit 1a41d9b

Browse files
committed
Small fix in finding the references in strings
1 parent 351512d commit 1a41d9b

5 files changed

Lines changed: 27 additions & 12 deletions

File tree

resources/META-INF/plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166
implementation="de.halirutan.mathematica.codeinsight.inspections.MathematicaInspectionProvider"/>
167167

168168
<psi.referenceContributor language="Mathematica" implementation="de.halirutan.mathematica.parsing.psi.MathematicaReferenceContributor"/>
169-
<renamePsiElementProcessor implementation="de.halirutan.mathematica.refactoring.MathematicaPsiRenameProcessor"/>
169+
<!--<renamePsiElementProcessor implementation="de.halirutan.mathematica.refactoring.MathematicaPsiRenameProcessor"/>-->
170170

171171

172172
<!--<applicationService serviceInterface="de.halirutan.mathematica.MathematicaSettings" serviceImplementation="de.halirutan.mathematica.MathematicaSettings"/>-->

src/de/halirutan/mathematica/parsing/psi/MathematicaStringReferenceProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNu
6969
final Expression symbol = ((MessageName) messageElement).getSymbol();
7070
if (symbol instanceof Symbol) {
7171
String usageText = element.getText();
72-
final String symbolName = Matcher.quoteReplacement(((Symbol) symbol).getSymbolName());
72+
final String symbolName = Matcher.quoteReplacement(((Symbol) symbol).getFullSymbolName());
7373
Pattern symbolNamePattern = StringUsageReference.getSymbolPattern(symbolName);
7474
final Matcher matcher = symbolNamePattern.matcher(usageText);
7575
while (matcher.find()) {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ public interface Symbol extends PsiNameIdentifierOwner {
4747
*/
4848
String getSymbolName();
4949

50+
/**
51+
* Returns the full name of the symbol with context.
52+
* @return Symbol name with context
53+
*/
54+
String getFullSymbolName();
5055
/**
5156
* Returns true if the <em>definition element</em> of this symbol was already resolved and is up to date. If this
5257
* returns true then you can call {@link #getResolveElement()} to get the place of definition or {@link

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ public String getSymbolName() {
104104
}
105105
}
106106

107+
@Override
108+
public String getFullSymbolName() {
109+
return getName();
110+
}
111+
107112
@Nullable
108113
@Override
109114
public PsiElement getNameIdentifier() {

tests/de/halirutan/mathematica/refactoring/RenameTest.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,20 @@ public void testUsage() throws Exception {
6868
myFixture.checkResult("newFunc::usage = \"newFunc is a function called like newFunc[]\";");
6969
}
7070

71-
// This test fails du to a bug in idea
72-
// @Test
73-
// public void testDollarVariables() throws Exception {
74-
// myFixture.configureByText(MathematicaFileType.INSTANCE,
75-
// "var$ = 1;\n" +
76-
// "var$<caret> + var$");
77-
// myFixture.renameElementAtCaret("$var$");
78-
// myFixture.checkResult("$var$ = 1;\n" +
79-
// "$var$ + $var$");
80-
// }
71+
public void testUsage2() throws Exception {
72+
myFixture.configureByText(MathematicaFileType.INSTANCE,
73+
"func<caret>::usage = \"func is a function called like func[]\";");
74+
myFixture.renameElementAtCaret("newFunc");
75+
myFixture.checkResult("newFunc::usage = \"newFunc is a function called like newFunc[]\";");
76+
}
77+
78+
public void testDollarVariables() throws Exception {
79+
myFixture.configureByText(MathematicaFileType.INSTANCE,
80+
"var$ = 1;\n" +
81+
"var$<caret> + var$");
82+
myFixture.renameElementAtCaret("$var$");
83+
myFixture.checkResult("$var$ = 1;\n" +
84+
"$var$ + $var$");
85+
}
8186

8287
}

0 commit comments

Comments
 (0)