Skip to content

Commit 4ccb8d7

Browse files
committed
Fix Function[] highlighting, update 2018 API changes, update gradle
1 parent 5fec9e6 commit 4ccb8d7

6 files changed

Lines changed: 83 additions & 87 deletions

File tree

build.gradle

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,22 @@
11
buildscript {
2-
ext.kotlin_version = '1.1.61'
2+
ext.kotlin_version = '1.2.40'
33

44
repositories {
55
mavenCentral()
6-
maven {
7-
url "https://oss.sonatype.org/content/repositories/snapshots/"
8-
}
9-
maven {
10-
url 'http://dl.bintray.com/jetbrains/intellij-plugin-service'
11-
}
12-
maven {
13-
url 'http://dl.bintray.com/kotlin/kotlin-eap-1.2'
14-
}
156
}
167

178
dependencies {
18-
// classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
19-
classpath "org.jetbrains.intellij.plugins:gradle-intellij-plugin:0.3.0-SNAPSHOT"
9+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
2010
}
2111
}
2212

2313

2414
plugins {
25-
id "org.jetbrains.kotlin.jvm" version '1.1.61'
15+
id "org.jetbrains.kotlin.jvm" version "1.2.40"
16+
id "org.jetbrains.intellij" version "0.3.1"
2617
}
2718

2819
apply plugin: 'java'
29-
apply plugin: 'org.jetbrains.intellij'
3020
apply plugin: "kotlin"
3121

3222
//noinspection GroovyAssignabilityCheck,GrUnresolvedAccess
@@ -78,10 +68,10 @@ task wrapper(type: Wrapper) {
7868
version '3.0pre10'
7969

8070
intellij {
81-
version = '2017.3.4'
71+
version = '2018.1.2'
8272
downloadSources = true
8373
pluginName = 'Mathematica-IntelliJ-Plugin'
84-
updateSinceUntilBuild = false
74+
updateSinceUntilBuild = true
8575
}
8676

8777
// Simple function to load change-notes.html and description.html into valid text for plugin.xml

src/de/halirutan/mathematica/codeinsight/completion/util/LocalDefinitionCompletionProvider.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import com.google.common.collect.Lists;
2727
import com.intellij.psi.PsiElement;
2828
import com.intellij.psi.ResolveState;
29-
import com.intellij.psi.scope.BaseScopeProcessor;
29+
import com.intellij.psi.scope.PsiScopeProcessor;
3030
import de.halirutan.mathematica.lang.psi.LocalizationConstruct;
3131
import de.halirutan.mathematica.lang.psi.api.FunctionCall;
3232
import de.halirutan.mathematica.lang.psi.api.Symbol;
@@ -49,7 +49,7 @@
4949
*
5050
* @author patrick (5/22/13)
5151
*/
52-
public class LocalDefinitionCompletionProvider extends BaseScopeProcessor {
52+
public class LocalDefinitionCompletionProvider implements PsiScopeProcessor {
5353

5454
private final List<Symbol> mySymbols = Lists.newLinkedList();
5555
private final Symbol myStartElement;
@@ -119,7 +119,8 @@ public List<Symbol> getSymbols() {
119119
mySymbols.sort(new SymbolComparator());
120120
Pattern pattern = Pattern.compile(myStartElement.getFullSymbolName().substring(0, 1) + ".*");
121121
Symbol tmp = null;
122-
for (Iterator<Symbol> symbolIterator = mySymbols.iterator(); symbolIterator.hasNext(); ) {
122+
Iterator<Symbol> symbolIterator = mySymbols.iterator();
123+
while (symbolIterator.hasNext()) {
123124
Symbol next = symbolIterator.next();
124125

125126
if (!pattern.matcher(next.getFullSymbolName()).matches()) {

src/de/halirutan/mathematica/errorreporting/IdeaInformationProxy.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import com.intellij.openapi.application.ApplicationNamesInfo;
2626
import com.intellij.openapi.application.ex.ApplicationInfoEx;
2727
import com.intellij.openapi.diagnostic.Attachment;
28-
import com.intellij.util.SystemProperties;
28+
import com.intellij.openapi.util.SystemInfo;
2929

3030
import java.util.LinkedHashMap;
3131

@@ -44,9 +44,9 @@ static LinkedHashMap<String, String> getKeyValuePairs(GitHubErrorBean error,
4444
params.put("Plugin Name", error.getPluginName());
4545
params.put("Plugin Version", error.getPluginVersion());
4646

47-
params.put("OS Name", SystemProperties.getOsName());
48-
params.put("Java version", SystemProperties.getJavaVersion());
49-
params.put("Java vm vendor", SystemProperties.getJavaVmVendor());
47+
params.put("OS Name", SystemInfo.OS_NAME);
48+
params.put("Java version", SystemInfo.JAVA_VERSION);
49+
params.put("Java vm vendor", SystemInfo.JAVA_VENDOR);
5050

5151
params.put("App Name", namesInfo.getProductName());
5252
params.put("App Full Name", namesInfo.getFullProductName());

src/de/halirutan/mathematica/lang/resolve/processors/LocalDefinitionResolveProcessor.kt

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ package de.halirutan.mathematica.lang.resolve.processors
2525

2626
import com.intellij.psi.PsiElement
2727
import com.intellij.psi.ResolveState
28-
import com.intellij.psi.scope.BaseScopeProcessor
28+
import com.intellij.psi.scope.PsiScopeProcessor
2929
import com.intellij.psi.util.PsiTreeUtil
3030
import de.halirutan.mathematica.lang.psi.LocalizationConstruct
3131
import de.halirutan.mathematica.lang.psi.LocalizationConstruct.MScope
@@ -80,73 +80,73 @@ import de.halirutan.mathematica.lang.resolve.resolvers.TableLikeResolver
8080
*
8181
* @author patrick (5/22/13)
8282
*/
83-
class LocalDefinitionResolveProcessor(private val myStartElement: Symbol) : BaseScopeProcessor() {
84-
/**
85-
* Returns the list of all symbols collected during a run. Before returning
86-
* the list, it removes duplicates, so that no entry appears more than once in the auto-completion window.
87-
*
88-
* @return Sorted and cleaned list of collected symbols.
89-
*/
90-
var resolveResult: SymbolResolveResult? = null
83+
class LocalDefinitionResolveProcessor(private val myStartElement: Symbol) : PsiScopeProcessor {
84+
/**
85+
* Returns the list of all symbols collected during a run. Before returning
86+
* the list, it removes duplicates, so that no entry appears more than once in the auto-completion window.
87+
*
88+
* @return Sorted and cleaned list of collected symbols.
89+
*/
90+
var resolveResult: SymbolResolveResult? = null
9191

92-
/**
93-
* There are several places where a local variable can be "defined". First I check all localization constructs which
94-
* are always function call like `Module[{var},...]`. The complete list of localization constructs can be
95-
* found in [MScope].
96-
*
97-
*
98-
* Secondly I check the patterns in e.g. ```f[var_]:=...!``` for `SetDelayed` and `TagSetDelayed`.
99-
*
100-
*
101-
* Finally, `RuleDelayed` constructs are checked.
102-
*
103-
* @param element
104-
* Element to check for defining the [.myStartElement].
105-
* @param state State of the resolving.
106-
* @return `false` if the search can be stopped, `true` otherwise
107-
*/
108-
override fun execute(element: PsiElement, state: ResolveState): Boolean {
109-
if (element is FunctionCall) {
92+
/**
93+
* There are several places where a local variable can be "defined". First I check all localization constructs which
94+
* are always function call like `Module[{var},...]`. The complete list of localization constructs can be
95+
* found in [MScope].
96+
*
97+
*
98+
* Secondly I check the patterns in e.g. ```f[var_]:=...!``` for `SetDelayed` and `TagSetDelayed`.
99+
*
100+
*
101+
* Finally, `RuleDelayed` constructs are checked.
102+
*
103+
* @param element
104+
* Element to check for defining the [.myStartElement].
105+
* @param state State of the resolving.
106+
* @return `false` if the search can be stopped, `true` otherwise
107+
*/
108+
override fun execute(element: PsiElement, state: ResolveState): Boolean {
109+
if (element is FunctionCall) {
110110

111-
if (element.isScopingConstruct) {
112-
val scopingConstruct = element.scopingConstruct
111+
if (element.isScopingConstruct) {
112+
val scopingConstruct = element.scopingConstruct
113113

114-
when {
115-
LocalizationConstruct.isModuleLike(scopingConstruct) -> resolveResult = ModuleLikeResolver().resolve(myStartElement, element, state)
116-
LocalizationConstruct.isFunctionLike(scopingConstruct) -> resolveResult = FunctionLikeResolver().resolve(myStartElement, element, state)
117-
LocalizationConstruct.isCompileLike(scopingConstruct) -> resolveResult = CompileLikeResolver().resolve(myStartElement, element, state)
118-
LocalizationConstruct.isTableLike(scopingConstruct) -> resolveResult = TableLikeResolver().resolve(myStartElement, element, state)
119-
LocalizationConstruct.isManipulateLike(scopingConstruct) -> resolveResult = TableLikeResolver().resolve(myStartElement, element, state)
120-
}
121-
resolveResult?.let { return false }
122-
}
123-
} else if (element is SetDelayed || element is TagSetDelayed || element is Set) {
114+
when {
115+
LocalizationConstruct.isModuleLike(scopingConstruct) -> resolveResult = ModuleLikeResolver().resolve(myStartElement, element, state)
116+
LocalizationConstruct.isFunctionLike(scopingConstruct) -> resolveResult = FunctionLikeResolver().resolve(myStartElement, element, state)
117+
LocalizationConstruct.isCompileLike(scopingConstruct) -> resolveResult = CompileLikeResolver().resolve(myStartElement, element, state)
118+
LocalizationConstruct.isTableLike(scopingConstruct) -> resolveResult = TableLikeResolver().resolve(myStartElement, element, state)
119+
LocalizationConstruct.isManipulateLike(scopingConstruct) -> resolveResult = TableLikeResolver().resolve(myStartElement, element, state)
120+
}
121+
resolveResult?.let { return false }
122+
}
123+
} else if (element is SetDelayed || element is TagSetDelayed || element is Set) {
124124

125-
val p2 = MathematicaPatternVisitor2()
126-
element.accept(p2)
125+
val p2 = MathematicaPatternVisitor2()
126+
element.accept(p2)
127127

128-
val patternVisitor = MathematicaPatternVisitor()
129-
element.accept(patternVisitor)
130-
for (p in patternVisitor.patternSymbols) {
131-
if (p.fullSymbolName == myStartElement.fullSymbolName) {
132-
if (element is Set && myStartElement !== p) {
133-
continue
134-
}
135-
resolveResult = SymbolResolveResult(p, MScope.SETDELAYED_SCOPE, element, true)
136-
return false
137-
}
138-
}
139-
} else if (element is RuleDelayed) {
140-
val patternExtractor = PatternSymbolExtractor()
141-
element.accept(patternExtractor)
128+
val patternVisitor = MathematicaPatternVisitor()
129+
element.accept(patternVisitor)
130+
for (p in patternVisitor.patternSymbols) {
131+
if (p.fullSymbolName == myStartElement.fullSymbolName) {
132+
if (element is Set && myStartElement !== p) {
133+
continue
134+
}
135+
resolveResult = SymbolResolveResult(p, MScope.SETDELAYED_SCOPE, element, true)
136+
return false
137+
}
138+
}
139+
} else if (element is RuleDelayed) {
140+
val patternExtractor = PatternSymbolExtractor()
141+
element.accept(patternExtractor)
142142

143-
for (symbol in patternExtractor.patternSymbols) {
144-
if (symbol.fullSymbolName == myStartElement.fullSymbolName) {
145-
resolveResult = SymbolResolveResult(symbol, MScope.RULEDELAYED_SCOPE, element, true)
146-
return false
147-
}
148-
}
143+
for (symbol in patternExtractor.patternSymbols) {
144+
if (symbol.fullSymbolName == myStartElement.fullSymbolName) {
145+
resolveResult = SymbolResolveResult(symbol, MScope.RULEDELAYED_SCOPE, element, true)
146+
return false
149147
}
150-
return true
148+
}
151149
}
150+
return true
151+
}
152152
}

src/de/halirutan/mathematica/lang/resolve/resolvers/FunctionLikeResolver.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ class FunctionLikeResolver : Resolver {
5656
if (elm is Symbol && elm.hasSameName(symbol)) {
5757
return SymbolResolveResult(elm, scope, scopingElement, true)
5858
}
59-
6059
}
60+
} else if (defList is Symbol && defList.hasSameName(symbol)) {
61+
return SymbolResolveResult(defList, scope, scopingElement, true)
6162
}
6263
}
6364
} else {
@@ -69,6 +70,8 @@ class FunctionLikeResolver : Resolver {
6970
return SymbolResolveResult(elm, scope, scopingElement, true)
7071
}
7172
}
73+
} else if (expr is Symbol && expr == symbol) {
74+
return SymbolResolveResult(symbol, scope, scopingElement, true)
7275
}
7376
}
7477
}

tests/de/halirutan/mathematica/lang/resolve/LocalVariableResolveTestCase.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ class LocalVariableResolveTestCase : AbstractResolveTest() {
5151
)
5252

5353
private val functionLike = mapOf(
54-
"Function[{val, key}, val + <ref>key]" to TextRange.create(15, 18)
54+
"Function[{val, key}, val + <ref>key]" to TextRange.create(15, 18),
55+
"Function[val, <ref>val]" to TextRange.create(9, 12)
56+
5557
)
5658

5759
fun testModule() {

0 commit comments

Comments
 (0)