From 47ecca4be9531732adcacfe723efc240fa237ef9 Mon Sep 17 00:00:00 2001 From: Patrick Scheibe Date: Mon, 4 Dec 2017 03:57:43 +0100 Subject: [PATCH] Add simple comment handler for inserting * and completion fix This fixes the missing completion for file-global functions. Additionally, this version includes a simple enter handler that inserts * automatically in multi-line comments. --- CHANGELOG.md | 2 +- build.gradle | 2 +- .../completion/providers/FileSymbolCompletion.java | 13 +++++++++++++ .../highlighting/annotators/SymbolAnnotator.kt | 1 + 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97cf90f3..a699d2d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,6 @@ - Better rendering for "Go to Declaration" targets - Inspection for using the same variable in the e.g. Module definition list several times - Quick fix for adding usages and other messages -- Keeping a leading * when pressing enter inside comments - Rework of creating project templates and modules - Update to Mathematica version 11.2 - Quick fix for pushing a variable inside the Module definition list @@ -13,6 +12,7 @@ ## Version 3.0 +- Keeping a leading * when pressing enter inside comments - Quick Documentation lookup for own functions. This will show the usage message of a function if available. - Performance improvement through caching - Support for Libraries. Libraries are basically a package folder with Mathematica source code. This code is indexed and diff --git a/build.gradle b/build.gradle index ebd99151..f6774f81 100644 --- a/build.gradle +++ b/build.gradle @@ -75,7 +75,7 @@ task wrapper(type: Wrapper) { // Information about the plugin // Plugin version number -version '3.0pre4' +version '3.0pre5' intellij { // version = '2017.2.5' diff --git a/src/de/halirutan/mathematica/codeinsight/completion/providers/FileSymbolCompletion.java b/src/de/halirutan/mathematica/codeinsight/completion/providers/FileSymbolCompletion.java index e4d9ef42..4e778a25 100644 --- a/src/de/halirutan/mathematica/codeinsight/completion/providers/FileSymbolCompletion.java +++ b/src/de/halirutan/mathematica/codeinsight/completion/providers/FileSymbolCompletion.java @@ -38,6 +38,7 @@ import com.intellij.util.containers.hash.HashSet; import de.halirutan.mathematica.codeinsight.completion.util.LocalDefinitionCompletionProvider; import de.halirutan.mathematica.lang.psi.api.Symbol; +import de.halirutan.mathematica.lang.resolve.MathematicaGlobalResolveCache; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -82,6 +83,18 @@ protected void addCompletions(@NotNull CompletionParameters parameters, Processi LookupElementBuilder.create(currentSymbol).bold().withItemTextForeground(JBColor.GREEN), LOCAL_VARIABLE_PRIORITY)); } + + final MathematicaGlobalResolveCache cache = + MathematicaGlobalResolveCache.getInstance(callingSymbol.getProject()); + cache.getCachedFileSymbolResolves(parameters.getOriginalFile()) + .forEach(symbolResolveResult -> { + if (symbolResolveResult.getElement() != null) { + result.addElement(PrioritizedLookupElement.withPriority( + LookupElementBuilder.create(symbolResolveResult.getElement()).bold(), + GLOBAL_VARIABLE_PRIORITY)); + } + }); + } else { final Set allSymbols = new HashSet<>(); PsiRecursiveElementVisitor visitor = new PsiRecursiveElementVisitor() { diff --git a/src/de/halirutan/mathematica/codeinsight/highlighting/annotators/SymbolAnnotator.kt b/src/de/halirutan/mathematica/codeinsight/highlighting/annotators/SymbolAnnotator.kt index 884f18b9..1a0a6a76 100644 --- a/src/de/halirutan/mathematica/codeinsight/highlighting/annotators/SymbolAnnotator.kt +++ b/src/de/halirutan/mathematica/codeinsight/highlighting/annotators/SymbolAnnotator.kt @@ -43,6 +43,7 @@ class SymbolAnnotator : Annotator { /** Annotates a [symbol] by checking its localization */ override fun annotate(symbol: PsiElement, holder: AnnotationHolder) { if (symbol is Symbol) { + symbol.resolve() val scope = symbol.localizationConstruct val scopeType = scope.type if (LocalizationConstruct.MScope.NULL_SCOPE == scope) {