Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Commit

Permalink
Fix issues in code completion
Browse files Browse the repository at this point in the history
  • Loading branch information
Shan1024 committed Jul 21, 2017
1 parent b2d438a commit 8211b33
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ private BallerinaTypes() {
public static final TokenIElementType IDENTIFIER = tokenIElementTypes.get(BallerinaLexer.Identifier);
public static final TokenIElementType COMMENT_STATEMENT = tokenIElementTypes.get(BallerinaLexer.LINE_COMMENT);
public static final TokenIElementType QUOTED_STRING = tokenIElementTypes.get(BallerinaLexer.QuotedStringLiteral);
public static final TokenIElementType FLOATING_POINT = tokenIElementTypes.get(BallerinaLexer.FloatingPointLiteral);
public static final TokenIElementType INTEGER_LITERAL = tokenIElementTypes.get(BallerinaLexer.IntegerLiteral);
public static final TokenIElementType ERRCHAR = tokenIElementTypes.get(BallerinaLexer.ERRCHAR);
public static final TokenIElementType DOUBLE_QUOTE = tokenIElementTypes.get(BallerinaLexer.DOUBLEQUOTE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ public void handleInsert(@NotNull InsertionContext context, @NotNull LookupEleme
}
}
if (myTriggerAutoPopup) {
PsiDocumentManager.getInstance(project)
.doPostponedOperationsAndUnblockDocument(editor.getDocument());
ApplicationManager.getApplication().runWriteAction(() -> {
PsiDocumentManager.getInstance(project)
.doPostponedOperationsAndUnblockDocument(editor.getDocument());
EditorModificationUtil.insertStringAtCaret(editor, ":");
PsiDocumentManager.getInstance(project).commitDocument(editor.getDocument());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@
import com.intellij.codeInsight.completion.CompletionResultSet;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiErrorElement;
import com.intellij.psi.impl.source.tree.LeafPsiElement;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.PsiTreeUtil;
import org.antlr.jetbrains.adaptor.psi.ANTLRPsiNode;
import org.ballerinalang.plugins.idea.BallerinaTypes;
import org.ballerinalang.plugins.idea.psi.AnnotationDefinitionNode;
import org.ballerinalang.plugins.idea.psi.CallableUnitBodyNode;
import org.ballerinalang.plugins.idea.psi.ConnectorBodyNode;
Expand All @@ -38,6 +41,7 @@
import org.ballerinalang.plugins.idea.psi.PackageDeclarationNode;
import org.ballerinalang.plugins.idea.psi.ResourceDefinitionNode;
import org.ballerinalang.plugins.idea.psi.ServiceBodyNode;
import org.ballerinalang.plugins.idea.psi.ServiceDefinitionNode;
import org.ballerinalang.plugins.idea.psi.TypeNameNode;
import org.jetbrains.annotations.NotNull;

Expand All @@ -50,6 +54,13 @@ public void fillCompletionVariants(@NotNull CompletionParameters parameters, @No
PsiElement element = parameters.getPosition();
PsiElement parent = element.getParent();

if (element instanceof LeafPsiElement) {
IElementType elementType = ((LeafPsiElement) element).getElementType();
if (elementType == BallerinaTypes.FLOATING_POINT) {
return;
}
}

if (parent instanceof NameReferenceNode /*|| parent instanceof PsiErrorElement*/) {
PsiElement prevVisibleSibling = PsiTreeUtil.prevVisibleLeaf(element);
if (prevVisibleSibling instanceof IdentifierPSINode) {
Expand Down Expand Up @@ -86,8 +97,8 @@ public void fillCompletionVariants(@NotNull CompletionParameters parameters, @No

if (parent instanceof PsiErrorElement) {

FunctionDefinitionNode functionDefinitionNode = PsiTreeUtil.getParentOfType(element,
FunctionDefinitionNode.class);
PsiElement functionDefinitionNode = PsiTreeUtil.getParentOfType(element,
FunctionDefinitionNode.class, ServiceDefinitionNode.class, ConnectorDefinitionNode.class);
if (functionDefinitionNode != null) {

PsiElement prevVisibleSibling = PsiTreeUtil.prevVisibleLeaf(element);
Expand Down

0 comments on commit 8211b33

Please sign in to comment.