Skip to content

Commit

Permalink
Fix several issues
Browse files Browse the repository at this point in the history
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
  • Loading branch information
halirutan committed May 6, 2018
1 parent 50c135c commit a7e4f80
Show file tree
Hide file tree
Showing 16 changed files with 357 additions and 496 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.0pre11'
version '3.0pre12'

intellij {
version = '2018.1.2'
Expand Down
7 changes: 5 additions & 2 deletions resources/META-INF/change-notes.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
<i>New features and bug-fixes in version 3:</i>
<br/>
<ul>
<li>Fix for a bug in IDEA 2018</li>
<li>Project wide completion</li>
<li>Support for Mathematica source libraries</li>
<li>Project wide completion</li>
<li>Fix for a bug in IDEA 2018</li>
<li>Make asterix in multi-line comments more usable. Now, the only Jetbrains API is used and no custom hacks</li>
<li>Fix for additional, wrong completions that come from a different project</li>
<li>Fix for FullForm creator</li>
</ul>
</html>
1 change: 0 additions & 1 deletion resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@

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

<liveTemplateContext implementation="de.halirutan.mathematica.codeinsight.livetemplates.MathematicaTemplateContextType"/>
<defaultLiveTemplatesProvider implementation="de.halirutan.mathematica.codeinsight.livetemplates.MathematicaDefaultLiveTemplateProvider"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +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:
* 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.
* 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;
Expand All @@ -30,7 +29,6 @@
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.util.ProcessingContext;
import com.intellij.util.text.StringTokenizer;
import de.halirutan.mathematica.lang.MathematicaLanguage;
import de.halirutan.mathematica.lang.resolve.MathematicaGlobalResolveCache;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -82,12 +80,11 @@ protected void addCompletions(@NotNull CompletionParameters parameters, Processi
.addElement(LookupElementBuilder.create(" :" + tag + ": "));
}
} else {
final String prefix = findCommentPrefix(parameters);
final PsiFile file = parameters.getOriginalFile();
final MathematicaGlobalResolveCache symbolCache = MathematicaGlobalResolveCache.getInstance(file.getProject());
final List<String> cachedDefinitions = symbolCache.getCachedFileSymbolNames(file);
for (String definition : cachedDefinitions) {
result.withPrefixMatcher(new PlainPrefixMatcher(prefix)).addElement(LookupElementBuilder.create(definition));
result.addElement(LookupElementBuilder.create(definition));
}
}
}
Expand All @@ -102,25 +99,4 @@ private boolean isEmptyComment(CompletionParameters parameters) {
return false;
}

private String findCommentPrefix(CompletionParameters parameters) {
final int posOffset = parameters.getOffset();
final PsiElement commentElement = parameters.getPosition();

if (commentElement instanceof PsiComment) {
final int elementStart = commentElement.getTextOffset();
final String commentText = commentElement.getText().substring(0, posOffset - elementStart);
if (commentText.length() == 0 || commentText.matches(".*[ \t\n\f]")) {
return "";
}

StringTokenizer tokenizer = new StringTokenizer(commentText);
String prefix = "";
while (tokenizer.hasMoreElements()) {
prefix = tokenizer.nextToken();
}
return prefix;
}
return "";
}

}
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
/*
* 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:
* 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.
* 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.*;
import com.intellij.codeInsight.completion.impl.CamelHumpMatcher;
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.util.ProcessingContext;
import de.halirutan.mathematica.lang.parsing.MathematicaElementTypes;
import de.halirutan.mathematica.lang.psi.api.MathematicaPsiFile;
import de.halirutan.mathematica.lang.psi.api.Symbol;
import de.halirutan.mathematica.lang.resolve.SymbolResolveResult;
import org.jetbrains.annotations.NotNull;

import java.util.HashSet;

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


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

@Override
public void addTo(CompletionContributor contributor) {
final Capture<PsiElement> symbolPattern = PlatformPatterns.psiElement().withParent(Symbol.class);
final Capture<PsiElement> symbolPattern = psiElement().withElementType(MathematicaElementTypes.IDENTIFIER);
contributor.extend(CompletionType.BASIC, symbolPattern, this);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +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:
* 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.
* 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;
Expand All @@ -27,21 +26,23 @@
import com.intellij.codeInsight.lookup.LookupElementBuilder;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtilCore;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
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.search.GlobalSearchScope;
import com.intellij.psi.search.ProjectScope;
import com.intellij.util.ProcessingContext;
import com.intellij.util.indexing.FileBasedIndex;
import com.intellij.util.indexing.IdFilter;
import de.halirutan.mathematica.index.packageexport.MathematicaPackageExportIndex;
import de.halirutan.mathematica.lang.parsing.MathematicaElementTypes;
import de.halirutan.mathematica.lang.psi.api.Symbol;
import org.jetbrains.annotations.NotNull;

import java.util.Objects;

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


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

@Override
public void addTo(CompletionContributor contributor) {
final Capture<PsiElement> symbolPattern = PlatformPatterns.psiElement().withParent(Symbol.class);
final Capture<PsiElement> symbolPattern = psiElement().withElementType(MathematicaElementTypes.IDENTIFIER);
contributor.extend(CompletionType.BASIC, symbolPattern, this);
}

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

String prefix = findCurrentText(parameters, parameters.getPosition());
if (parameters.getInvocationCount() == 0 && prefix.isEmpty()) {
return;
}
final PsiFile originalFile = parameters.getOriginalFile();
final Module module =
ModuleUtilCore.findModuleForFile(originalFile.getVirtualFile(), project);
if (module != null) {
if (!parameters.isExtendedCompletion() || !(prefix.isEmpty() || Character.isDigit(prefix.charAt(0)))) {
final GlobalSearchScope moduleScope = GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module)
.union(ProjectScope.getLibrariesScope(project));

final GlobalSearchScope moduleScope = module.getModuleWithDependenciesAndLibrariesScope(true);
final FileBasedIndex index = FileBasedIndex.getInstance();

index.processAllKeys(
MathematicaPackageExportIndex.INDEX_ID,
key -> {
if (key.isExported() && !Objects.equals(key.getFileName(), originalFile.getName())) {
ProgressManager.checkCanceled();
if (key.isExported() && !Objects.equals(key.getFileName(), originalFile.getName()) &&
!index.getContainingFiles(MathematicaPackageExportIndex.INDEX_ID, key, moduleScope).isEmpty()) {
result.addElement(PrioritizedLookupElement.withPriority(
LookupElementBuilder.create(key.getSymbol()).withTypeText("(" + key.getFileName() + ")", true),
IMPORT_VARIABLE_PRIORITY));
}
return true;
},
moduleScope,
null
IdFilter.getProjectIdFilter(project, false)
);
}
}
Expand Down
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.codeinsight.editoractions;
Expand All @@ -42,23 +43,12 @@ public String getLineCommentPrefix() {
return null;
}

/**
* Returns the opening string for a comment. In Java and C this is <code >&#47;*</code>, in Mathematica it is <code
* >(*</code>
*
* @return the comment opening string
*/
@Nullable
@Override
public String getBlockCommentPrefix() {
return "(*";
}

/**
* Returns the closing string for a block comment. In Java and C this is <code >*&#47;</code>
*
* @return the block comment closing string
*/
@Nullable
@Override
public String getBlockCommentSuffix() {
Expand All @@ -68,13 +58,13 @@ public String getBlockCommentSuffix() {
@Nullable
@Override
public String getCommentedBlockCommentPrefix() {
return "-";
return null;
}

@Nullable
@Override
public String getCommentedBlockCommentSuffix() {
return "+";
return null;
}

@Nullable
Expand Down Expand Up @@ -115,6 +105,7 @@ public String getDocumentationCommentSuffix() {

@Override
public boolean isDocumentationComment(PsiComment element) {
return true;
return element.getTokenType().equals(MathematicaElementTypes.COMMENT);
}

}
Loading

0 comments on commit a7e4f80

Please sign in to comment.