Skip to content

Commit

Permalink
Fix local and global resolving
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
halirutan committed May 8, 2018
1 parent 749452b commit 6963f60
Show file tree
Hide file tree
Showing 17 changed files with 459 additions and 376 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ task wrapper(type: Wrapper) {
// Information about the plugin

// Plugin version number
version '3.0pre12'
version '3.0pre13'

intellij {
version = '2018.1.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@ doc.navi.invalid=Cannot resolve symbol {0}
doc.navi.navto=Navigate to definition of {0}
doc.navi.builtin=Built-in symbol <b>{0}</b>
module.settings.language.level=Module Language Level
mathematica.notification.group=Mathematica Notifications
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.
61 changes: 61 additions & 0 deletions src/de/halirutan/mathematica/MathematicaNotification.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2018 Patrick Scheibe
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package de.halirutan.mathematica;

import com.intellij.notification.NotificationDisplayType;
import com.intellij.notification.NotificationGroup;
import com.intellij.notification.NotificationType;
import de.halirutan.mathematica.util.MathematicaIcons;

/**
* @author patrick (06.05.18).
*/
public class MathematicaNotification {
private static final NotificationGroup GROUP = new NotificationGroup(
MathematicaBundle.message("mathematica.notification.group"),
NotificationDisplayType.BALLOON,
false,
null,
MathematicaIcons.FILE_ICON);

public static void info(String message) {
showNotification(message, NotificationType.INFORMATION);
}

public static void warning(String message) {
showNotification(message, NotificationType.WARNING);
}

public static void error(String message) {
showNotification(message, NotificationType.ERROR);
}

private static void showNotification(String message, NotificationType type) {
GROUP.createNotification(
MathematicaBundle.message("language.name"),
message,
type,
null).notify(null);
}

}
27 changes: 15 additions & 12 deletions src/de/halirutan/mathematica/actions/MathematicaFullFormViewer.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
/*
* Copyright (c) 2017 Patrick Scheibe
* Copyright (c) 2018 Patrick Scheibe
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package de.halirutan.mathematica.actions;
Expand All @@ -25,7 +26,6 @@
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.command.CommandProcessor;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.SelectionModel;
Expand All @@ -36,7 +36,8 @@
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import com.intellij.psi.codeStyle.CodeStyleManager;
import de.halirutan.mathematica.file.MathematicaFileType;
import de.halirutan.mathematica.MathematicaBundle;
import de.halirutan.mathematica.MathematicaNotification;
import de.halirutan.mathematica.lang.MathematicaLanguage;
import de.halirutan.mathematica.lang.psi.util.MathematicaFullFormCreator;
import de.halirutan.mathematica.lang.psi.util.MathematicaPsiElementFactory;
Expand All @@ -53,7 +54,12 @@ public void actionPerformed(AnActionEvent e) {
assert project != null;
final FileEditorManagerEx editorManagerEx = FileEditorManagerEx.getInstanceEx(project);
final VirtualFile currentFile = editorManagerEx.getCurrentFile();
if (currentFile != null && currentFile.getFileType().equals(MathematicaFileType.INSTANCE)) {
if (currentFile == null) {
MathematicaNotification.error(MathematicaBundle.message("fullform.viewer.no.file"));
return;
}
final PsiFile psiFile = PsiManager.getInstance(project).findFile(currentFile);
if (psiFile != null && MathematicaLanguage.INSTANCE.equals(psiFile.getLanguage())) {
MathematicaFullFormCreator fullFormCreator = new MathematicaFullFormCreator();
PsiElement expression = null;
if (editor != null) {
Expand All @@ -65,10 +71,7 @@ public void actionPerformed(AnActionEvent e) {
expression = factory.createDummyFile(selectedText);
}
} else {
final PsiFile psiFile = PsiManager.getInstance(project).findFile(currentFile);
if (psiFile != null) {
expression = psiFile;
}
expression = psiFile;
}
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright (c) 2018 Patrick Scheibe
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package de.halirutan.mathematica.codeinsight.completion.providers

import com.intellij.codeInsight.completion.CompletionContributor
import com.intellij.codeInsight.completion.CompletionParameters
import com.intellij.codeInsight.completion.CompletionResultSet
import com.intellij.codeInsight.completion.CompletionType
import com.intellij.codeInsight.completion.PrioritizedLookupElement
import com.intellij.codeInsight.lookup.LookupElementBuilder
import com.intellij.openapi.module.ModuleUtilCore
import com.intellij.openapi.progress.ProgressManager
import com.intellij.patterns.PlatformPatterns.psiElement
import com.intellij.util.ProcessingContext
import com.intellij.util.indexing.FileBasedIndex
import de.halirutan.mathematica.codeinsight.completion.MathematicaCompletionContributor.IMPORT_VARIABLE_PRIORITY
import de.halirutan.mathematica.index.packageexport.MathematicaPackageExportIndex
import de.halirutan.mathematica.lang.parsing.MathematicaElementTypes
import de.halirutan.mathematica.lang.psi.api.Symbol


/**
* Accesses the file index to provide completion for functions that are defined in other packages.
*/
class ImportedSymbolCompletion : MathematicaCompletionProvider() {

override fun addTo(contributor: CompletionContributor) {
val symbolPattern = psiElement().withElementType(MathematicaElementTypes.IDENTIFIER)
contributor.extend(CompletionType.BASIC, symbolPattern, this)
}

override fun addCompletions(parameters: CompletionParameters, context: ProcessingContext, result: CompletionResultSet) {
val callingSymbol = parameters.position.parent
val project = callingSymbol.project

val prefix = findCurrentText(parameters, parameters.position)
if (parameters.invocationCount == 0 && prefix.isEmpty() || callingSymbol !is Symbol) {
return
}
val originalFile = parameters.originalFile
val module = ModuleUtilCore.findModuleForFile(originalFile.virtualFile, project)
if (module != null) {
val moduleScope = module.getModuleWithDependenciesAndLibrariesScope(true)
val index = FileBasedIndex.getInstance()
val indexID = MathematicaPackageExportIndex.INDEX_ID
index.getAllKeys(indexID, project).forEach {
it?.let {
val inScope = !index.processValues(
indexID,
it,
null,
{ _, _ -> false },
moduleScope
)
ProgressManager.checkCanceled()
if (inScope && it.isExported) {
result.addElement(PrioritizedLookupElement.withPriority(
LookupElementBuilder.create(it.symbol).withTypeText("(" + it.fileName + ")", true),
IMPORT_VARIABLE_PRIORITY))
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,33 @@
/*
* Copyright (c) 2015 Patrick Scheibe
* Copyright (c) 2018 Patrick Scheibe
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package de.halirutan.mathematica.codeinsight.folding;

import com.intellij.openapi.components.*;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.util.xmlb.XmlSerializerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
Expand Down Expand Up @@ -57,7 +62,7 @@ public MathematicaCodeFoldingSettingsImpl getState() {
}

@Override
public void loadState(final MathematicaCodeFoldingSettingsImpl state) {
public void loadState(@NotNull final MathematicaCodeFoldingSettingsImpl state) {
XmlSerializerUtil.copyBean(state, this);
}
}

0 comments on commit 6963f60

Please sign in to comment.