Skip to content

Commit 6963f60

Browse files
committed
Fix local and global resolving
- Fix issue, where completion and resolving showed symbols that came from a completely different project. The reason was that GlobalSearchScope does not work as one would expect. This issue is fixed now and resolving of external symbols from other files or libraries should work correctly. - Fix for a minor issue in resolving patterns from Rule. In a_ -> a, the a_ should be green while the a is a global symbol - External Mathematica libraries are now regarded as "being compiled" to make navigation and resolving work correctly. You need to recreate your libraries in your project settings! - Fix local resolving of Condition expressions - Fix for the FullForm viewer
1 parent 749452b commit 6963f60

17 files changed

Lines changed: 459 additions & 376 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.0pre12'
68+
version '3.0pre13'
6969

7070
intellij {
7171
version = '2018.1.2'

resources/de/halirutan/mathematica/MathematicaBundle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,5 @@ doc.navi.invalid=Cannot resolve symbol {0}
6161
doc.navi.navto=Navigate to definition of {0}
6262
doc.navi.builtin=Built-in symbol <b>{0}</b>
6363
module.settings.language.level=Module Language Level
64+
mathematica.notification.group=Mathematica Notifications
65+
fullform.viewer.no.file=No file in editor open. Open a file to view its FullForm or select code in an editor to inspect the FullForm of an expression.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) 2018 Patrick Scheibe
3+
*
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 all
12+
* 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 THE
20+
* SOFTWARE.
21+
*/
22+
23+
package de.halirutan.mathematica;
24+
25+
import com.intellij.notification.NotificationDisplayType;
26+
import com.intellij.notification.NotificationGroup;
27+
import com.intellij.notification.NotificationType;
28+
import de.halirutan.mathematica.util.MathematicaIcons;
29+
30+
/**
31+
* @author patrick (06.05.18).
32+
*/
33+
public class MathematicaNotification {
34+
private static final NotificationGroup GROUP = new NotificationGroup(
35+
MathematicaBundle.message("mathematica.notification.group"),
36+
NotificationDisplayType.BALLOON,
37+
false,
38+
null,
39+
MathematicaIcons.FILE_ICON);
40+
41+
public static void info(String message) {
42+
showNotification(message, NotificationType.INFORMATION);
43+
}
44+
45+
public static void warning(String message) {
46+
showNotification(message, NotificationType.WARNING);
47+
}
48+
49+
public static void error(String message) {
50+
showNotification(message, NotificationType.ERROR);
51+
}
52+
53+
private static void showNotification(String message, NotificationType type) {
54+
GROUP.createNotification(
55+
MathematicaBundle.message("language.name"),
56+
message,
57+
type,
58+
null).notify(null);
59+
}
60+
61+
}

src/de/halirutan/mathematica/actions/MathematicaFullFormViewer.java

Lines changed: 15 additions & 12 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.actions;
@@ -25,7 +26,6 @@
2526
import com.intellij.openapi.actionSystem.AnAction;
2627
import com.intellij.openapi.actionSystem.AnActionEvent;
2728
import com.intellij.openapi.actionSystem.CommonDataKeys;
28-
import com.intellij.openapi.command.CommandProcessor;
2929
import com.intellij.openapi.command.WriteCommandAction;
3030
import com.intellij.openapi.editor.Editor;
3131
import com.intellij.openapi.editor.SelectionModel;
@@ -36,7 +36,8 @@
3636
import com.intellij.psi.PsiFile;
3737
import com.intellij.psi.PsiManager;
3838
import com.intellij.psi.codeStyle.CodeStyleManager;
39-
import de.halirutan.mathematica.file.MathematicaFileType;
39+
import de.halirutan.mathematica.MathematicaBundle;
40+
import de.halirutan.mathematica.MathematicaNotification;
4041
import de.halirutan.mathematica.lang.MathematicaLanguage;
4142
import de.halirutan.mathematica.lang.psi.util.MathematicaFullFormCreator;
4243
import de.halirutan.mathematica.lang.psi.util.MathematicaPsiElementFactory;
@@ -53,7 +54,12 @@ public void actionPerformed(AnActionEvent e) {
5354
assert project != null;
5455
final FileEditorManagerEx editorManagerEx = FileEditorManagerEx.getInstanceEx(project);
5556
final VirtualFile currentFile = editorManagerEx.getCurrentFile();
56-
if (currentFile != null && currentFile.getFileType().equals(MathematicaFileType.INSTANCE)) {
57+
if (currentFile == null) {
58+
MathematicaNotification.error(MathematicaBundle.message("fullform.viewer.no.file"));
59+
return;
60+
}
61+
final PsiFile psiFile = PsiManager.getInstance(project).findFile(currentFile);
62+
if (psiFile != null && MathematicaLanguage.INSTANCE.equals(psiFile.getLanguage())) {
5763
MathematicaFullFormCreator fullFormCreator = new MathematicaFullFormCreator();
5864
PsiElement expression = null;
5965
if (editor != null) {
@@ -65,10 +71,7 @@ public void actionPerformed(AnActionEvent e) {
6571
expression = factory.createDummyFile(selectedText);
6672
}
6773
} else {
68-
final PsiFile psiFile = PsiManager.getInstance(project).findFile(currentFile);
69-
if (psiFile != null) {
70-
expression = psiFile;
71-
}
74+
expression = psiFile;
7275
}
7376
}
7477

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

Lines changed: 0 additions & 96 deletions
This file was deleted.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright (c) 2018 Patrick Scheibe
3+
*
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 all
12+
* 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 THE
20+
* SOFTWARE.
21+
*/
22+
23+
package de.halirutan.mathematica.codeinsight.completion.providers
24+
25+
import com.intellij.codeInsight.completion.CompletionContributor
26+
import com.intellij.codeInsight.completion.CompletionParameters
27+
import com.intellij.codeInsight.completion.CompletionResultSet
28+
import com.intellij.codeInsight.completion.CompletionType
29+
import com.intellij.codeInsight.completion.PrioritizedLookupElement
30+
import com.intellij.codeInsight.lookup.LookupElementBuilder
31+
import com.intellij.openapi.module.ModuleUtilCore
32+
import com.intellij.openapi.progress.ProgressManager
33+
import com.intellij.patterns.PlatformPatterns.psiElement
34+
import com.intellij.util.ProcessingContext
35+
import com.intellij.util.indexing.FileBasedIndex
36+
import de.halirutan.mathematica.codeinsight.completion.MathematicaCompletionContributor.IMPORT_VARIABLE_PRIORITY
37+
import de.halirutan.mathematica.index.packageexport.MathematicaPackageExportIndex
38+
import de.halirutan.mathematica.lang.parsing.MathematicaElementTypes
39+
import de.halirutan.mathematica.lang.psi.api.Symbol
40+
41+
42+
/**
43+
* Accesses the file index to provide completion for functions that are defined in other packages.
44+
*/
45+
class ImportedSymbolCompletion : MathematicaCompletionProvider() {
46+
47+
override fun addTo(contributor: CompletionContributor) {
48+
val symbolPattern = psiElement().withElementType(MathematicaElementTypes.IDENTIFIER)
49+
contributor.extend(CompletionType.BASIC, symbolPattern, this)
50+
}
51+
52+
override fun addCompletions(parameters: CompletionParameters, context: ProcessingContext, result: CompletionResultSet) {
53+
val callingSymbol = parameters.position.parent
54+
val project = callingSymbol.project
55+
56+
val prefix = findCurrentText(parameters, parameters.position)
57+
if (parameters.invocationCount == 0 && prefix.isEmpty() || callingSymbol !is Symbol) {
58+
return
59+
}
60+
val originalFile = parameters.originalFile
61+
val module = ModuleUtilCore.findModuleForFile(originalFile.virtualFile, project)
62+
if (module != null) {
63+
val moduleScope = module.getModuleWithDependenciesAndLibrariesScope(true)
64+
val index = FileBasedIndex.getInstance()
65+
val indexID = MathematicaPackageExportIndex.INDEX_ID
66+
index.getAllKeys(indexID, project).forEach {
67+
it?.let {
68+
val inScope = !index.processValues(
69+
indexID,
70+
it,
71+
null,
72+
{ _, _ -> false },
73+
moduleScope
74+
)
75+
ProgressManager.checkCanceled()
76+
if (inScope && it.isExported) {
77+
result.addElement(PrioritizedLookupElement.withPriority(
78+
LookupElementBuilder.create(it.symbol).withTypeText("(" + it.fileName + ")", true),
79+
IMPORT_VARIABLE_PRIORITY))
80+
}
81+
}
82+
}
83+
}
84+
}
85+
}

src/de/halirutan/mathematica/codeinsight/folding/MathematicaCodeFoldingSettingsImpl.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
11
/*
2-
* Copyright (c) 2015 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.folding;
2324

24-
import com.intellij.openapi.components.*;
25+
import com.intellij.openapi.components.PersistentStateComponent;
26+
import com.intellij.openapi.components.ServiceManager;
27+
import com.intellij.openapi.components.State;
28+
import com.intellij.openapi.components.Storage;
2529
import com.intellij.util.xmlb.XmlSerializerUtil;
30+
import org.jetbrains.annotations.NotNull;
2631
import org.jetbrains.annotations.Nullable;
2732

2833
/**
@@ -57,7 +62,7 @@ public MathematicaCodeFoldingSettingsImpl getState() {
5762
}
5863

5964
@Override
60-
public void loadState(final MathematicaCodeFoldingSettingsImpl state) {
65+
public void loadState(@NotNull final MathematicaCodeFoldingSettingsImpl state) {
6166
XmlSerializerUtil.copyBean(state, this);
6267
}
6368
}

0 commit comments

Comments
 (0)