-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve unresolve-highlighting, resolving, and completion
* The file-indexer for libraries and packages will now recognize usage messages that are hidden inside an If[..] statement as this is sometimes used * The unresolved symbol annotation is a bit slower now but should pick up changes more consistently * Contexts of packages are now available for completion * Inside an empty (**) comment, it should now reliably work that sections and author, etc. annotations can be completed with Ctrl+Space * Non empty comments offer completion for function names * The completion panel shows now the localization for local variables * Hopefully fixed the "should not be null" assertion
- Loading branch information
Showing
14 changed files
with
186 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/de/halirutan/mathematica/codeinsight/completion/providers/LocalizedSymbolCompletion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright (c) 2017 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.google.common.collect.Lists; | ||
import com.intellij.codeInsight.completion.*; | ||
import com.intellij.codeInsight.lookup.LookupElementBuilder; | ||
import com.intellij.patterns.PlatformPatterns; | ||
import com.intellij.patterns.PsiElementPattern.Capture; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.PsiFile; | ||
import com.intellij.psi.ResolveState; | ||
import com.intellij.psi.util.PsiTreeUtil; | ||
import com.intellij.ui.JBColor; | ||
import com.intellij.util.ProcessingContext; | ||
import de.halirutan.mathematica.codeinsight.completion.util.LocalDefinitionCompletionProvider; | ||
import de.halirutan.mathematica.lang.psi.LocalizationConstruct; | ||
import de.halirutan.mathematica.lang.psi.api.Symbol; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.List; | ||
|
||
import static de.halirutan.mathematica.codeinsight.completion.MathematicaCompletionContributor.LOCAL_VARIABLE_PRIORITY; | ||
|
||
|
||
/** | ||
* @author patrick (4/2/13) | ||
*/ | ||
public class LocalizedSymbolCompletion extends MathematicaCompletionProvider { | ||
|
||
@Override | ||
public void addTo(CompletionContributor contributor) { | ||
final Capture<PsiElement> symbolPattern = PlatformPatterns.psiElement().withParent(Symbol.class); | ||
contributor.extend(CompletionType.BASIC, symbolPattern, this); | ||
} | ||
|
||
@Override | ||
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context, @NotNull CompletionResultSet result) { | ||
final Symbol callingSymbol = (Symbol) parameters.getPosition().getParent(); | ||
|
||
if (!parameters.isExtendedCompletion()) { | ||
String prefix = findCurrentText(parameters, parameters.getPosition()); | ||
if (prefix.isEmpty() || Character.isDigit(prefix.charAt(0))) { | ||
return; | ||
} | ||
final PsiFile containingFile = parameters.getOriginalFile(); | ||
List<Symbol> variants = Lists.newArrayList(); | ||
|
||
final LocalDefinitionCompletionProvider processor = new LocalDefinitionCompletionProvider(callingSymbol); | ||
PsiTreeUtil.treeWalkUp(processor, callingSymbol, containingFile, ResolveState.initial()); | ||
|
||
variants.addAll(processor.getSymbols()); | ||
|
||
for (Symbol currentSymbol : variants) { | ||
if (LocalizationConstruct.isLocalScoping(currentSymbol.getLocalizationConstruct())) { | ||
final String tailText = currentSymbol.getLocalizationConstruct().toString(); | ||
result.addElement(PrioritizedLookupElement.withPriority( | ||
LookupElementBuilder.create(currentSymbol.getSymbolName()) | ||
.withItemTextForeground(JBColor.GREEN) | ||
.withTypeText(tailText, true), | ||
LOCAL_VARIABLE_PRIORITY)); | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.