Skip to content

Commit ed73e4b

Browse files
committed
Rework symbol resolving, package indexing, code analysis and highlighting
1 parent 1321ecc commit ed73e4b

60 files changed

Lines changed: 2411 additions & 1569 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

resources/META-INF/plugin.xml

Lines changed: 156 additions & 154 deletions
Large diffs are not rendered by default.

resources/colors/MathematicaDarcula.xml

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,45 @@
11
<?xml version='1.0'?>
22
<!--
33
~ Copyright (c) 2017 Patrick Scheibe
4-
~ Permission is hereby granted, free of charge, to any person obtaining a copy
5-
~ of this software and associated documentation files (the "Software"), to deal
6-
~ in the Software without restriction, including without limitation the rights
7-
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8-
~ copies of the Software, and to permit persons to whom the Software is
9-
~ furnished to do so, subject to the following conditions:
104
~
11-
~ The above copyright notice and this permission notice shall be included in
12-
~ all copies or substantial portions of the Software.
5+
~ Permission is hereby granted, free of charge, to any person obtaining a copy
6+
~ of this software and associated documentation files (the "Software"), to deal
7+
~ in the Software without restriction, including without limitation the rights
8+
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
~ copies of the Software, and to permit persons to whom the Software is
10+
~ furnished to do so, subject to the following conditions:
11+
~
12+
~ The above copyright notice and this permission notice shall be included in
13+
~ all copies or substantial portions of the Software.
14+
~
15+
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
~ THE SOFTWARE.
1322
~
14-
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15-
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16-
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17-
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18-
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19-
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20-
~ THE SOFTWARE.
2123
-->
2224

2325

2426
<!--I assume FONT_TYPE values are the ones defined in java.awt.Font-->
2527
<list>
26-
<option name="MMA.IDENTIFIER">
28+
<option name="MMA.SYMBOL">
29+
<value>
30+
<option name="FOREGROUND" value="A9B7C6"/>
31+
</value>
32+
</option>
33+
34+
<option name="MMA.IMPORTED_SYMBOL">
2735
<value>
2836
<option name="FOREGROUND" value="A9B7C6"/>
37+
<option name="EFFECT_COLOR" value="808080"/>
38+
<option name="EFFECT_TYPE" value="1"/>
2939
</value>
3040
</option>
3141

32-
<option name="MMA.BUILTIN_FUNCTION">
42+
<option name="MMA.KERNEL_SYMBOL">
3343
<value>
3444
<!--<option name="FOREGROUND" value="377b94" />-->
3545
<option name="FOREGROUND" value="6897BB"/>

resources/colors/MathematicaDefault.xml

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,46 @@
11
<?xml version='1.0'?>
22
<!--
33
~ Copyright (c) 2017 Patrick Scheibe
4-
~ Permission is hereby granted, free of charge, to any person obtaining a copy
5-
~ of this software and associated documentation files (the "Software"), to deal
6-
~ in the Software without restriction, including without limitation the rights
7-
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8-
~ copies of the Software, and to permit persons to whom the Software is
9-
~ furnished to do so, subject to the following conditions:
104
~
11-
~ The above copyright notice and this permission notice shall be included in
12-
~ all copies or substantial portions of the Software.
5+
~ Permission is hereby granted, free of charge, to any person obtaining a copy
6+
~ of this software and associated documentation files (the "Software"), to deal
7+
~ in the Software without restriction, including without limitation the rights
8+
~ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
~ copies of the Software, and to permit persons to whom the Software is
10+
~ furnished to do so, subject to the following conditions:
11+
~
12+
~ The above copyright notice and this permission notice shall be included in
13+
~ all copies or substantial portions of the Software.
14+
~
15+
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
~ THE SOFTWARE.
1322
~
14-
~ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15-
~ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16-
~ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17-
~ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18-
~ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19-
~ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20-
~ THE SOFTWARE.
2123
-->
2224

2325

2426
<!--I assume FONT_TYPE values are the ones defined in java.awt.Font-->
2527
<list>
26-
<option name="MMA.IDENTIFIER">
28+
<option name="MMA.SYMBOL">
2729
<value>
2830
<option name="FOREGROUND" value="000000"/>
2931
</value>
3032
</option>
3133

32-
<option name="MMA.BUILTIN_FUNCTION">
34+
<option name="MMA.IMPORTED_SYMBOL">
35+
<value>
36+
<option name="FOREGROUND" value="000000"/>
37+
<option name="EFFECT_COLOR" value="101010"/>
38+
<option name="EFFECT_TYPE" value="1"/>
39+
</value>
40+
</option>
41+
42+
43+
<option name="MMA.KERNEL_SYMBOL">
3344
<value>
3445
<!--<option name="FOREGROUND" value="377b94" />-->
3546
<option name="FOREGROUND" value="0000FF"/>
Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
#
2-
# Copyright (c) 2014 Patrick Scheibe
3-
# Permission is hereby granted, free of charge, to any person obtaining a copy
4-
# of this software and associated documentation files (the "Software"), to deal
5-
# in the Software without restriction, including without limitation the rights
6-
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7-
# copies of the Software, and to permit persons to whom the Software is
8-
# furnished to do so, subject to the following conditions:
2+
# Copyright (c) 2017 Patrick Scheibe
93
#
10-
# The above copyright notice and this permission notice shall be included in
11-
# all copies or substantial portions of the Software.
4+
# Permission is hereby granted, free of charge, to any person obtaining a copy
5+
# of this software and associated documentation files (the "Software"), to deal
6+
# in the Software without restriction, including without limitation the rights
7+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
# copies of the Software, and to permit persons to whom the Software is
9+
# furnished to do so, subject to the following conditions:
10+
#
11+
# The above copyright notice and this permission notice shall be included in
12+
# all copies or substantial portions of the Software.
13+
#
14+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
# THE SOFTWARE.
1221
#
13-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14-
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15-
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16-
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17-
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18-
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19-
# THE SOFTWARE.
2022
#
2123

2224
group.bugs=Probable Errors
@@ -26,11 +28,15 @@ group.symbol=Symbols
2628
consistent.compound.expression.in.file.name=Missing semicolon at file-scope
2729
consistent.compound.expression.in.file.description=At file scope it is considered good code-style, when all separate expressions are closed with a semicolon.
2830
consistent.compound.expression.in.file.message=Missing semicolon
31+
2932
bugs.implicit.times.through.linebreak.name=Multiplication through linebreak
3033
bugs.implicit.times.through.linebreak.description=This linebreak is interpreted as multiplication. When two complete expressions are separated by a linebreak, then Mathematica interprets this as a multiplication. This is probably not intended.
3134
bugs.implicit.times.through.linebreak.message=Missing comma or semicolon
3235
bugs.unsupported.version.name=Function is part of later version
3336
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.
37+
bugs.unsupported.version.association=Associations where introduced in version 10. You are using {0}.
38+
bugs.unsupported.version.with=The feature With having multiple definition lists was introduced in version 10.3. You are using {0}.
39+
3440
symbol.unresolved.name=Unresolved Symbol
3541
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
42+
symbol.unresolved.message=Could not resolve symbol declaration

src/de/halirutan/mathematica/codeinsight/completion/CommentCompletionProvider.java

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
/*
22
* Copyright (c) 2017 Patrick Scheibe
3-
* Permission is hereby granted, free of charge, to any person obtaining a copy
4-
* of this software and associated documentation files (the "Software"), to deal
5-
* in the Software without restriction, including without limitation the rights
6-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7-
* copies of the Software, and to permit persons to whom the Software is
8-
* furnished to do so, subject to the following conditions:
93
*
10-
* The above copyright notice and this permission notice shall be included in
11-
* all copies or substantial portions of the Software.
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
1221
*
13-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19-
* THE SOFTWARE.
2022
*/
2123

2224
package de.halirutan.mathematica.codeinsight.completion;
@@ -31,6 +33,8 @@
3133
import com.intellij.util.text.StringTokenizer;
3234
import de.halirutan.mathematica.lang.MathematicaLanguage;
3335
import de.halirutan.mathematica.lang.psi.api.MathematicaPsiFile;
36+
import de.halirutan.mathematica.lang.psi.api.Symbol;
37+
import de.halirutan.mathematica.lang.resolve.SymbolResolveResult;
3438
import org.jetbrains.annotations.NotNull;
3539

3640
import java.util.Set;
@@ -66,7 +70,7 @@ protected void addCompletions(@NotNull CompletionParameters parameters, Processi
6670
if (parameters.getInvocationCount() > 0) {
6771
final String prefix = findCommentPrefix(parameters);
6872

69-
if (isEmptyCommennt(parameters)) {
73+
if (isEmptyComment(parameters)) {
7074
int priority = 100;
7175
for (String section : COMMENT_SECTIONS) {
7276
priority--;
@@ -85,19 +89,18 @@ protected void addCompletions(@NotNull CompletionParameters parameters, Processi
8589

8690
final PsiFile file = parameters.getOriginalFile();
8791
if (file instanceof MathematicaPsiFile) {
88-
final Set<String> cachedDefinitions = ((MathematicaPsiFile) file).getCachedDefinitions();
89-
for (String definition : cachedDefinitions) {
90-
resultWithPrefix.addElement(LookupElementBuilder.create(definition));
92+
final Set<SymbolResolveResult> cachedDefinitions = ((MathematicaPsiFile) file).getCachedDefinitions();
93+
for (SymbolResolveResult definition : cachedDefinitions) {
94+
if (definition.getElement() instanceof Symbol)
95+
resultWithPrefix.addElement(LookupElementBuilder.create(((Symbol) definition.getElement()).getFullSymbolName()));
9196
}
9297
}
9398
}
9499
}
95100

96-
private boolean isEmptyCommennt(CompletionParameters parameters) {
97-
final int posOffset = parameters.getOffset();
101+
private boolean isEmptyComment(CompletionParameters parameters) {
98102
final PsiElement commentElement = parameters.getPosition();
99103
if (commentElement instanceof PsiComment) {
100-
final int elementStart = commentElement.getTextOffset();
101104
final String commentText = commentElement.getText();
102105
return commentText.matches("\\(\\*\\s*ZZZ\\s*\\*\\)") || EMPTY_COMMENT.matcher(commentText).matches();
103106
}

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

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
/*
22
* Copyright (c) 2017 Patrick Scheibe
3-
* Permission is hereby granted, free of charge, to any person obtaining a copy
4-
* of this software and associated documentation files (the "Software"), to deal
5-
* in the Software without restriction, including without limitation the rights
6-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7-
* copies of the Software, and to permit persons to whom the Software is
8-
* furnished to do so, subject to the following conditions:
93
*
10-
* The above copyright notice and this permission notice shall be included in
11-
* all copies or substantial portions of the Software.
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
* THE SOFTWARE.
1221
*
13-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19-
* THE SOFTWARE.
2022
*/
2123

2224
package de.halirutan.mathematica.codeinsight.completion;
@@ -25,14 +27,14 @@
2527
import com.intellij.psi.PsiElement;
2628
import com.intellij.psi.ResolveState;
2729
import com.intellij.psi.scope.BaseScopeProcessor;
30+
import de.halirutan.mathematica.lang.psi.LocalizationConstruct;
2831
import de.halirutan.mathematica.lang.psi.api.FunctionCall;
2932
import de.halirutan.mathematica.lang.psi.api.Symbol;
3033
import de.halirutan.mathematica.lang.psi.api.assignment.Set;
3134
import de.halirutan.mathematica.lang.psi.api.assignment.SetDelayed;
3235
import de.halirutan.mathematica.lang.psi.api.assignment.TagSet;
3336
import de.halirutan.mathematica.lang.psi.api.assignment.TagSetDelayed;
3437
import de.halirutan.mathematica.lang.psi.api.rules.RuleDelayed;
35-
import de.halirutan.mathematica.lang.psi.util.LocalizationConstruct;
3638
import de.halirutan.mathematica.lang.psi.util.MathematicaPatternVisitor;
3739
import de.halirutan.mathematica.lang.psi.util.MathematicaPsiUtilities;
3840
import org.jetbrains.annotations.NotNull;

0 commit comments

Comments
 (0)