Skip to content

Commit a7e4f80

Browse files
committed
Fix several issues
The FullForm creator had a bug with blanks which is fixed Small fix in hash of the package index Fix for wrong completions that came from a different project
1 parent 50c135c commit a7e4f80

16 files changed

Lines changed: 357 additions & 496 deletions

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ task wrapper(type: Wrapper) {
6565
// Information about the plugin
6666

6767
// Plugin version number
68-
version '3.0pre11'
68+
version '3.0pre12'
6969

7070
intellij {
7171
version = '2018.1.2'

resources/META-INF/change-notes.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
<i>New features and bug-fixes in version 3:</i>
33
<br/>
44
<ul>
5-
<li>Fix for a bug in IDEA 2018</li>
6-
<li>Project wide completion</li>
75
<li>Support for Mathematica source libraries</li>
6+
<li>Project wide completion</li>
7+
<li>Fix for a bug in IDEA 2018</li>
8+
<li>Make asterix in multi-line comments more usable. Now, the only Jetbrains API is used and no custom hacks</li>
9+
<li>Fix for additional, wrong completions that come from a different project</li>
10+
<li>Fix for FullForm creator</li>
811
</ul>
912
</html>

resources/META-INF/plugin.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767

6868
<enterHandlerDelegate implementation="de.halirutan.mathematica.codeinsight.editoractions.enter.MathematicaEnterInsideFunctionHandler"/>
6969
<enterHandlerDelegate implementation="de.halirutan.mathematica.codeinsight.editoractions.enter.MathematicaEnterAfterOperatorHandler"/>
70-
<!--<enterHandlerDelegate implementation="de.halirutan.mathematica.codeinsight.editoractions.enter.CommentStarInsertEnterHandler"/>-->
7170

7271
<liveTemplateContext implementation="de.halirutan.mathematica.codeinsight.livetemplates.MathematicaTemplateContextType"/>
7372
<defaultLiveTemplatesProvider implementation="de.halirutan.mathematica.codeinsight.livetemplates.MathematicaDefaultLiveTemplateProvider"/>

src/de/halirutan/mathematica/codeinsight/completion/providers/CommentCompletion.java

Lines changed: 17 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
/*
2-
* Copyright (c) 2017 Patrick Scheibe
2+
* Copyright (c) 2018 Patrick Scheibe
33
*
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:
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:
1010
*
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.
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
2113
*
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 THE
20+
* SOFTWARE.
2221
*/
2322

2423
package de.halirutan.mathematica.codeinsight.completion.providers;
@@ -30,7 +29,6 @@
3029
import com.intellij.psi.PsiElement;
3130
import com.intellij.psi.PsiFile;
3231
import com.intellij.util.ProcessingContext;
33-
import com.intellij.util.text.StringTokenizer;
3432
import de.halirutan.mathematica.lang.MathematicaLanguage;
3533
import de.halirutan.mathematica.lang.resolve.MathematicaGlobalResolveCache;
3634
import org.jetbrains.annotations.NotNull;
@@ -82,12 +80,11 @@ protected void addCompletions(@NotNull CompletionParameters parameters, Processi
8280
.addElement(LookupElementBuilder.create(" :" + tag + ": "));
8381
}
8482
} else {
85-
final String prefix = findCommentPrefix(parameters);
8683
final PsiFile file = parameters.getOriginalFile();
8784
final MathematicaGlobalResolveCache symbolCache = MathematicaGlobalResolveCache.getInstance(file.getProject());
8885
final List<String> cachedDefinitions = symbolCache.getCachedFileSymbolNames(file);
8986
for (String definition : cachedDefinitions) {
90-
result.withPrefixMatcher(new PlainPrefixMatcher(prefix)).addElement(LookupElementBuilder.create(definition));
87+
result.addElement(LookupElementBuilder.create(definition));
9188
}
9289
}
9390
}
@@ -102,25 +99,4 @@ private boolean isEmptyComment(CompletionParameters parameters) {
10299
return false;
103100
}
104101

105-
private String findCommentPrefix(CompletionParameters parameters) {
106-
final int posOffset = parameters.getOffset();
107-
final PsiElement commentElement = parameters.getPosition();
108-
109-
if (commentElement instanceof PsiComment) {
110-
final int elementStart = commentElement.getTextOffset();
111-
final String commentText = commentElement.getText().substring(0, posOffset - elementStart);
112-
if (commentText.length() == 0 || commentText.matches(".*[ \t\n\f]")) {
113-
return "";
114-
}
115-
116-
StringTokenizer tokenizer = new StringTokenizer(commentText);
117-
String prefix = "";
118-
while (tokenizer.hasMoreElements()) {
119-
prefix = tokenizer.nextToken();
120-
}
121-
return prefix;
122-
}
123-
return "";
124-
}
125-
126102
}

src/de/halirutan/mathematica/codeinsight/completion/providers/FileSymbolCompletion.java

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,42 @@
11
/*
2-
* Copyright (c) 2017 Patrick Scheibe
2+
* Copyright (c) 2018 Patrick Scheibe
33
*
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:
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:
1010
*
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.
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
2113
*
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 THE
20+
* SOFTWARE.
2221
*/
2322

2423
package de.halirutan.mathematica.codeinsight.completion.providers;
2524

2625
import com.intellij.codeInsight.completion.*;
2726
import com.intellij.codeInsight.completion.impl.CamelHumpMatcher;
2827
import com.intellij.codeInsight.lookup.LookupElementBuilder;
29-
import com.intellij.patterns.PlatformPatterns;
3028
import com.intellij.patterns.PsiElementPattern.Capture;
3129
import com.intellij.psi.PsiElement;
3230
import com.intellij.psi.PsiFile;
3331
import com.intellij.util.ProcessingContext;
32+
import de.halirutan.mathematica.lang.parsing.MathematicaElementTypes;
3433
import de.halirutan.mathematica.lang.psi.api.MathematicaPsiFile;
35-
import de.halirutan.mathematica.lang.psi.api.Symbol;
3634
import de.halirutan.mathematica.lang.resolve.SymbolResolveResult;
3735
import org.jetbrains.annotations.NotNull;
3836

3937
import java.util.HashSet;
4038

39+
import static com.intellij.patterns.PlatformPatterns.psiElement;
4140
import static de.halirutan.mathematica.codeinsight.completion.MathematicaCompletionContributor.GLOBAL_VARIABLE_PRIORITY;
4241

4342

@@ -48,7 +47,7 @@ public class FileSymbolCompletion extends MathematicaCompletionProvider {
4847

4948
@Override
5049
public void addTo(CompletionContributor contributor) {
51-
final Capture<PsiElement> symbolPattern = PlatformPatterns.psiElement().withParent(Symbol.class);
50+
final Capture<PsiElement> symbolPattern = psiElement().withElementType(MathematicaElementTypes.IDENTIFIER);
5251
contributor.extend(CompletionType.BASIC, symbolPattern, this);
5352
}
5453

src/de/halirutan/mathematica/codeinsight/completion/providers/ImportedSymbolCompletion.java

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
/*
2-
* Copyright (c) 2017 Patrick Scheibe
2+
* Copyright (c) 2018 Patrick Scheibe
33
*
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:
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:
1010
*
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.
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
2113
*
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 THE
20+
* SOFTWARE.
2221
*/
2322

2423
package de.halirutan.mathematica.codeinsight.completion.providers;
@@ -27,21 +26,23 @@
2726
import com.intellij.codeInsight.lookup.LookupElementBuilder;
2827
import com.intellij.openapi.module.Module;
2928
import com.intellij.openapi.module.ModuleUtilCore;
29+
import com.intellij.openapi.progress.ProgressManager;
3030
import com.intellij.openapi.project.Project;
31-
import com.intellij.patterns.PlatformPatterns;
3231
import com.intellij.patterns.PsiElementPattern.Capture;
3332
import com.intellij.psi.PsiElement;
3433
import com.intellij.psi.PsiFile;
3534
import com.intellij.psi.search.GlobalSearchScope;
36-
import com.intellij.psi.search.ProjectScope;
3735
import com.intellij.util.ProcessingContext;
3836
import com.intellij.util.indexing.FileBasedIndex;
37+
import com.intellij.util.indexing.IdFilter;
3938
import de.halirutan.mathematica.index.packageexport.MathematicaPackageExportIndex;
39+
import de.halirutan.mathematica.lang.parsing.MathematicaElementTypes;
4040
import de.halirutan.mathematica.lang.psi.api.Symbol;
4141
import org.jetbrains.annotations.NotNull;
4242

4343
import java.util.Objects;
4444

45+
import static com.intellij.patterns.PlatformPatterns.psiElement;
4546
import static de.halirutan.mathematica.codeinsight.completion.MathematicaCompletionContributor.IMPORT_VARIABLE_PRIORITY;
4647

4748

@@ -52,7 +53,7 @@ public class ImportedSymbolCompletion extends MathematicaCompletionProvider {
5253

5354
@Override
5455
public void addTo(CompletionContributor contributor) {
55-
final Capture<PsiElement> symbolPattern = PlatformPatterns.psiElement().withParent(Symbol.class);
56+
final Capture<PsiElement> symbolPattern = psiElement().withElementType(MathematicaElementTypes.IDENTIFIER);
5657
contributor.extend(CompletionType.BASIC, symbolPattern, this);
5758
}
5859

@@ -62,26 +63,32 @@ protected void addCompletions(@NotNull CompletionParameters parameters, Processi
6263
final Project project = callingSymbol.getProject();
6364

6465
String prefix = findCurrentText(parameters, parameters.getPosition());
66+
if (parameters.getInvocationCount() == 0 && prefix.isEmpty()) {
67+
return;
68+
}
6569
final PsiFile originalFile = parameters.getOriginalFile();
6670
final Module module =
6771
ModuleUtilCore.findModuleForFile(originalFile.getVirtualFile(), project);
6872
if (module != null) {
6973
if (!parameters.isExtendedCompletion() || !(prefix.isEmpty() || Character.isDigit(prefix.charAt(0)))) {
70-
final GlobalSearchScope moduleScope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module)
71-
.union(ProjectScope.getLibrariesScope(project));
74+
75+
final GlobalSearchScope moduleScope = module.getModuleWithDependenciesAndLibrariesScope(true);
7276
final FileBasedIndex index = FileBasedIndex.getInstance();
77+
7378
index.processAllKeys(
7479
MathematicaPackageExportIndex.INDEX_ID,
7580
key -> {
76-
if (key.isExported() && !Objects.equals(key.getFileName(), originalFile.getName())) {
81+
ProgressManager.checkCanceled();
82+
if (key.isExported() && !Objects.equals(key.getFileName(), originalFile.getName()) &&
83+
!index.getContainingFiles(MathematicaPackageExportIndex.INDEX_ID, key, moduleScope).isEmpty()) {
7784
result.addElement(PrioritizedLookupElement.withPriority(
7885
LookupElementBuilder.create(key.getSymbol()).withTypeText("(" + key.getFileName() + ")", true),
7986
IMPORT_VARIABLE_PRIORITY));
8087
}
8188
return true;
8289
},
8390
moduleScope,
84-
null
91+
IdFilter.getProjectIdFilter(project, false)
8592
);
8693
}
8794
}

src/de/halirutan/mathematica/codeinsight/editoractions/MathematicaCommenter.java

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
/*
2-
* Copyright (c) 2017 Patrick Scheibe
2+
* Copyright (c) 2018 Patrick Scheibe
3+
*
34
* Permission is hereby granted, free of charge, to any person obtaining a copy
45
* of this software and associated documentation files (the "Software"), to deal
56
* in the Software without restriction, including without limitation the rights
67
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
78
* copies of the Software, and to permit persons to whom the Software is
89
* furnished to do so, subject to the following conditions:
910
*
10-
* The above copyright notice and this permission notice shall be included in
11-
* all copies or substantial portions of the Software.
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
1213
*
1314
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1415
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1516
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1617
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1718
* 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.
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
2021
*/
2122

2223
package de.halirutan.mathematica.codeinsight.editoractions;
@@ -42,23 +43,12 @@ public String getLineCommentPrefix() {
4243
return null;
4344
}
4445

45-
/**
46-
* Returns the opening string for a comment. In Java and C this is <code >&#47;*</code>, in Mathematica it is <code
47-
* >(*</code>
48-
*
49-
* @return the comment opening string
50-
*/
5146
@Nullable
5247
@Override
5348
public String getBlockCommentPrefix() {
5449
return "(*";
5550
}
5651

57-
/**
58-
* Returns the closing string for a block comment. In Java and C this is <code >*&#47;</code>
59-
*
60-
* @return the block comment closing string
61-
*/
6252
@Nullable
6353
@Override
6454
public String getBlockCommentSuffix() {
@@ -68,13 +58,13 @@ public String getBlockCommentSuffix() {
6858
@Nullable
6959
@Override
7060
public String getCommentedBlockCommentPrefix() {
71-
return "-";
61+
return null;
7262
}
7363

7464
@Nullable
7565
@Override
7666
public String getCommentedBlockCommentSuffix() {
77-
return "+";
67+
return null;
7868
}
7969

8070
@Nullable
@@ -115,6 +105,7 @@ public String getDocumentationCommentSuffix() {
115105

116106
@Override
117107
public boolean isDocumentationComment(PsiComment element) {
118-
return true;
108+
return element.getTokenType().equals(MathematicaElementTypes.COMMENT);
119109
}
110+
120111
}

0 commit comments

Comments
 (0)