Skip to content

Commit

Permalink
Merge pull request #46 from pbroadbery/fricas-next-version
Browse files Browse the repository at this point in the history
Completion can be cancelled, lexing is now incremental
  • Loading branch information
pbroadbery authored Apr 16, 2021
2 parents 80cf724 + d01b76b commit 17a59fd
Show file tree
Hide file tree
Showing 22 changed files with 302 additions and 104 deletions.
65 changes: 65 additions & 0 deletions .idea/libraries-with-intellij-classes.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/libraries/junit_junit_4_13_2.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ buildscript {
url 'https://jetbrains.bintray.com/intellij-plugin-service'
}
maven {
url 'https://jetbrains.bintray.com/intellij-third-party-dependencies'
url 'https://cache-redirector.jetbrains.com/intellij-dependencies'
}

}
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
baseVersion=1.3.1
baseVersion=1.3.2

pluginSinceBuild = 201
pluginUntilBuild = 215.*
Expand All @@ -11,4 +11,4 @@ platformVersion = 2020.2.4
# 2020.2.4 202.8194.7
# 2020.3.2 203.7148.57
# 2020.3.3 203.7717.56
pluginVerifierIdeVersions = IC-2020.3.3, IC-2020.2.4, IC-2020.1.4
pluginVerifierIdeVersions = IC-2021.1.0, IC-2020.3.3, IC-2020.2.4, IC-2020.1.4
18 changes: 10 additions & 8 deletions src/main/grammar/Aldor.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ private BindingL_Infixed_AnyStatement ::=
| KW_Implies Binding_AnyStatement)?
| AnyStatement

left BindingL_Infixed_AnyStatement_Define ::= KW_2EQ BindingL_Infixed_AnyStatement
left BindingL_Infixed_AnyStatement_Define ::= KW_2EQ BindingL_Infixed_AnyStatement //{ pin="KW_2EQ"}
left BindingL_Infixed_AnyStatement_Macro ::= KW_MArrow BindingL_Infixed_AnyStatement
left BindingL_Infixed_AnyStatement_Assign ::= KW_Assign BindingL_Infixed_AnyStatement
left BindingL_Infixed_AnyStatement_Lambda ::= KW_MapsTo BindingL_Infixed_AnyStatement
Expand All @@ -268,7 +268,7 @@ private BindingL_Infixed_BalStatement ::=

left BindingL_Infixed_BalStatement_Assign ::= KW_Assign BindingL_Infixed_BalStatement
left BindingL_Infixed_BalStatement_Macro ::= KW_MArrow BindingL_Infixed_BalStatement
left BindingL_Infixed_BalStatement_Define ::= KW_2EQ BindingL_Infixed_BalStatement
left BindingL_Infixed_BalStatement_Define ::= KW_2EQ BindingL_Infixed_BalStatement //{ pin="KW_2EQ"}
left BindingL_Infixed_BalStatement_Lambda ::= KW_MapsTo BindingL_Infixed_BalStatement

// TODO: Similar left factoring as above.
Expand All @@ -282,7 +282,7 @@ private BindingL_Infixed_Collection ::=
| Collection
left BindingL_Infixed_Collection_Assign ::= KW_Assign BindingL_Infixed_Collection
left BindingL_Infixed_Collection_Macro ::= KW_MArrow BindingL_Infixed_Collection
left BindingL_Infixed_Collection_Define ::= KW_2EQ BindingL_Infixed_Collection
left BindingL_Infixed_Collection_Define ::= KW_2EQ BindingL_Infixed_Collection //{ pin="KW_2EQ"}
left BindingL_Infixed_Collection_Lambda ::= KW_MapsTo BindingL_Infixed_Collection

/*
Expand Down Expand Up @@ -612,7 +612,7 @@ DeclBlock ::= Curly_Labelled | DeclPiled_Expression
Block ::= Curly_Labelled | Piled_Expression

RecoverableExpression ::= Expression { recoverWhile=ExpressionRecover}
private ExpressionRecover ::= !(KW_CParen| KW_CBrack | <<blockEnd>> | SpadAbbrevCmd)
private ExpressionRecover ::= !(KW_CParen| KW_CBrack | <<blockEnd>> | TK_SysCmdAbbrev)

Parened ::= KW_OParen (KW_CParen | RecoverableExpression KW_CParen) { pin="KW_OParen"}

Expand Down Expand Up @@ -689,10 +689,12 @@ private enlist1a_Labelled_SEMICOLON ::= Labelled (Semicolon Labelled)* Semicolon
TopLevel ::= CurlyContents_Labelled (KW_StartPile Piled_Content KW_EndPile?)?

//Piled_E ::= KW_BlkStart PileContents_E KW_BlkEnd
private Piled_Expression ::= KW_BlkStart Piled_Content <<blockEnd>>
private Piled_Expression ::= KW_BlkStart Piled_Content <<blockEnd>> { recoverWhile=BlockEndRecover }
DeclPiled_Expression ::= KW_BlkStart DeclPiled_Content <<blockEnd>>
Piled_Content ::= <<parsePiledContent "Pile">>
DeclPiled_Content ::= <<parsePiledContent "Pile">>

private BlockEndRecover ::= !(<<blockEnd>> | TK_SysCmdAbbrev)
//Piled_Expression ::= KW_BlkStart PileContents_Expression <<backTab>>
//Piled_Expression ::= KW_BlkStart Doc_Expression (KW_BlkNext Doc_Expression)* KW_BlkNext? <<backTab>>

Expand Down Expand Up @@ -738,12 +740,12 @@ PreDocument ::= TK_PreDoc*

SpadTopLevel ::= <<parseTopLevel "SpadTopLevel">>
// NB: All spad comments are '++'. Guess that top level is pre - anything else is post.
SpadTopLevelExpression ::= SpadAbbrevCmd* PreDocument Expression // {pin=PreDocument} {recoverWhile="TopLevel_Recover"}
SpadTopLevelExpression ::= SpadAbbrevCmd* PreDocument SpadTopLevelExpression_Inner // {pin=PreDocument} {recoverWhile="TopLevel_Recover"}
SpadDocument ::= TK_PostDoc*
SpadAbbrevCmd ::= TK_SysCmdAbbrev


//private TopLevel_Recover ::= !(TK_PreDoc | SpadAbbrevCmd)
private SpadTopLevelExpression_Inner ::= Expression// { recoverWhile="TopLevel_Recover"}
private TopLevel_Recover ::= !(TK_PreDoc | TK_SysCmdAbbrev| KW_BlkNext | KW_BlkEnd)

SpadInfixed ::= Block | Expr

Expand Down
8 changes: 7 additions & 1 deletion src/main/java/aldor/build/module/AldorModuleType.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import aldor.builder.jps.SpadFacetProperties;
import aldor.file.AldorFileType;
import aldor.file.SpadFileType;
import aldor.file.SpadInputFileType;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleType;
Expand Down Expand Up @@ -50,6 +51,7 @@ public String getDescription() {
return "Module containing spad/aldor sources";
}

@NotNull
@Override
public Icon getNodeIcon(@Deprecated boolean isOpened) {
return AldorIcons.MODULE;
Expand All @@ -64,13 +66,17 @@ public boolean is(Module module) {
return ModuleType.is(module, this);
}

public @Nullable SpadFacet<? extends SpadFacetProperties> facetModuleType(Module module, FileType fileType) {
@Nullable
public SpadFacet<? extends SpadFacetProperties> facetModuleType(Module module, FileType fileType) {
if (fileType.equals(AldorFileType.INSTANCE)) {
return AldorFacet.forModule(module);
}
else if (fileType.equals(SpadFileType.INSTANCE)) {
return FricasFacet.forModule(module);
}
else if (fileType.equals(SpadInputFileType.INSTANCE)) {
return FricasFacet.forModule(module);
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
import com.intellij.codeInsight.completion.util.ParenthesesInsertHandler;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupElementBuilder;
import com.intellij.openapi.application.ex.ApplicationUtil;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.patterns.ElementPattern;
import com.intellij.patterns.PatternCondition;
import com.intellij.patterns.StandardPatterns;
Expand All @@ -27,6 +32,7 @@
import icons.AldorIcons;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
Expand All @@ -38,6 +44,7 @@
import static com.intellij.patterns.StandardPatterns.or;

public class AldorCompletionContributor extends CompletionContributor {
private static final Logger LOG = Logger.getInstance(AldorCompletionContributor.class);

public AldorCompletionContributor() {

Expand All @@ -50,10 +57,10 @@ public AldorCompletionContributor() {
}

private CompletionProvider<CompletionParameters> idCompletion() {
return new CompletionProvider<CompletionParameters>() {
return new CompletionProvider<>() {
@Override
protected void addCompletions(@NotNull CompletionParameters parameters,
ProcessingContext context,
@NotNull ProcessingContext context,
@NotNull CompletionResultSet result) {
List<LookupElement> element = allTypes(parameters);
result.addAllElements(element);
Expand All @@ -64,20 +71,33 @@ protected void addCompletions(@NotNull CompletionParameters parameters,
public List<LookupElement> allTypes(CompletionParameters parameters) {
PsiElement elt = parameters.getPosition();
SpadLibrary spadLibrary = SpadLibraryManager.getInstance(parameters.getOriginalFile().getProject()).spadLibraryForElement(elt);
return (spadLibrary == null) ? Collections.emptyList() : allTypes(spadLibrary);
return (spadLibrary == null) ? Collections.emptyList() : allTypes_withCancel(spadLibrary);
}

@VisibleForTesting
public static List<LookupElement> allTypes(SpadLibrary spadLibrary) {
List<Syntax> allTypes = spadLibrary.allTypes();
public static List<LookupElement> allTypes_withCancel(SpadLibrary spadLibrary) {
try {
ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
return asElements(spadLibrary, ApplicationUtil.runWithCheckCanceled(spadLibrary::allTypes, progressIndicator));
}
catch (ProcessCanceledException e) {
LOG.info("Cancelled completion");
} catch (Exception e) {
LOG.error("Failed to collect all types", e);
}
return Collections.emptyList();
}

@VisibleForTesting
public static List<LookupElement> asElements(SpadLibrary spadLibrary, Collection<Syntax> allTypes) {
return allTypes.stream()
.flatMap(e -> createLookupElement(spadLibrary, e).map(Stream::of).orElse(Stream.empty()))
.flatMap(e -> createLookupElement(spadLibrary, e).stream())
.collect(Collectors.toList());
}

private static Optional<LookupElement> createLookupElement(SpadLibrary spadLibrary, Syntax syntax) {
Optional<Id> id = SyntaxUtils.leadingId(syntax).maybeAs(Id.class);
if (!id.isPresent()) {
if (id.isEmpty()) {
return Optional.empty();
}
else {
Expand Down Expand Up @@ -110,7 +130,7 @@ private static String tailTextForElement(SpadLibrary spadLibrary, Id symbol) {
private static final class AldorPatterns {
static ElementPattern<PsiElement> isFirstChild() {
//noinspection InnerClassTooDeeplyNested
return psiElement().with(new PatternCondition<PsiElement>("firstChild") {
return psiElement().with(new PatternCondition<>("firstChild") {
@Override
public boolean accepts(@NotNull PsiElement psiElement, ProcessingContext context) {
return (psiElement.getParent() != null) && psiElement.getParent().getFirstChild().equals(psiElement);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,54 +1,22 @@
package aldor.hierarchy;

import aldor.hierarchy.util.TypeHierarchyBrowserBaseEx;
import com.intellij.ide.hierarchy.ChangeHierarchyViewActionBase;
import com.intellij.ide.hierarchy.TypeHierarchyBrowserBase;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.actionSystem.ToggleAction;
import com.intellij.openapi.application.ApplicationManager;
import org.jetbrains.annotations.NotNull;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.util.ui.UIUtil;

import javax.swing.Icon;

public abstract class AbstractChangeHierarchyViewAction extends ToggleAction {
public abstract class AbstractChangeHierarchyViewAction extends ChangeHierarchyViewActionBase {

AbstractChangeHierarchyViewAction(final String shortDescription, final String longDescription, final Icon icon) {
super(shortDescription, longDescription, icon);
}

@Override
public final boolean isSelected(final AnActionEvent event) {
final TypeHierarchyBrowserBaseEx browser = (TypeHierarchyBrowserBaseEx) getTypeHierarchyBrowser(event.getDataContext());
return (browser != null) && getTypeName().equals(browser.typeName());
protected TypeHierarchyBrowserBase getHierarchyBrowser(DataContext context) {
return UIUtil.getParentOfType(TypeHierarchyBrowserBase.class, context.getData(PlatformDataKeys.CONTEXT_COMPONENT));
}

protected abstract String getTypeName();

@Override
public final void setSelected(final AnActionEvent event, final boolean flag) {
if (flag) {
final TypeHierarchyBrowserBase browser = getTypeHierarchyBrowser(event.getDataContext());
// setWaitCursor();
ApplicationManager.getApplication().invokeLater(() -> {
if (browser != null) {
browser.changeView(getTypeName());
}
});
}
}

@Override
public void update(@NotNull final AnActionEvent event) {
// its important to assign the myTypeHierarchyBrowser first
super.update(event);
final Presentation presentation = event.getPresentation();
presentation.setEnabled(true);
}

static TypeHierarchyBrowserBase getTypeHierarchyBrowser(final DataContext context) {
return TypeHierarchyBrowserBase.DATA_KEY.getData(context);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public boolean isAlwaysLeaf(Object element) {

@NotNull
@Override
protected Object @NotNull [] buildChildren(@NotNull HierarchyNodeDescriptor descriptor) {
protected Object[] buildChildren(@NotNull HierarchyNodeDescriptor descriptor) {
if (descriptor instanceof ErrorNodeDescriptor) {
return EMPTY_ARRAY;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/aldor/lexer/AldorTokenTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ private static AldorTokenType createTokenType(String name, AldorTokenAttributes
public static IElementType createTokenType(String token) {
IElementType tokenType = tokenTypeForString.get(token);
if (tokenType == null) {
System.out.println("Missing token " + token);
throw new IllegalArgumentException("Unknown token: " + token);
}

Expand Down
Loading

0 comments on commit 17a59fd

Please sign in to comment.