From ee28a170d6e0b41ffed7965249ed973f4de58772 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Thu, 1 Oct 2015 21:49:46 +0300 Subject: [PATCH] Auto-popup completion after "::" --- .../idea/editor/KotlinTypedHandler.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/editor/KotlinTypedHandler.java b/idea/src/org/jetbrains/kotlin/idea/editor/KotlinTypedHandler.java index bbf55938f7a..04d189955ea 100644 --- a/idea/src/org/jetbrains/kotlin/idea/editor/KotlinTypedHandler.java +++ b/idea/src/org/jetbrains/kotlin/idea/editor/KotlinTypedHandler.java @@ -40,6 +40,7 @@ import com.intellij.psi.TokenType; import com.intellij.psi.codeStyle.CodeStyleManager; import com.intellij.psi.formatter.FormatterUtil; import com.intellij.psi.impl.source.tree.LeafPsiElement; +import com.intellij.psi.tree.IElementType; import com.intellij.psi.tree.TokenSet; import com.intellij.util.text.CharArrayUtil; import org.jetbrains.annotations.NotNull; @@ -119,6 +120,10 @@ public class KotlinTypedHandler extends TypedHandlerDelegate { case '@': autoPopupLabelLookup(project, editor); return Result.CONTINUE; + + case ':': + autoPopupCallableReferenceLookup(project, editor); + return Result.CONTINUE; } return Result.CONTINUE; @@ -133,8 +138,8 @@ public class KotlinTypedHandler extends TypedHandlerDelegate { PsiElement lastElement = file.findElementAt(offset - 1); if (lastElement == null) return false; - String text = lastElement.getText(); - return ".".equals(text) || "?.".equals(text); + IElementType elementType = lastElement.getNode().getElementType(); + return elementType == JetTokens.DOT || elementType == JetTokens.SAFE_ACCESS; } }); } @@ -159,6 +164,20 @@ public class KotlinTypedHandler extends TypedHandlerDelegate { }); } + private static void autoPopupCallableReferenceLookup(Project project, final Editor editor) { + AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, new Condition() { + @Override + public boolean value(PsiFile file) { + int offset = editor.getCaretModel().getOffset(); + + PsiElement lastElement = file.findElementAt(offset - 1); + if (lastElement == null) return false; + + return lastElement.getNode().getElementType() == JetTokens.COLONCOLON; + } + }); + } + private static boolean endsWith(CharSequence chars, int offset, String text) { if (offset < text.length()) return false; return chars.subSequence(offset - text.length(), offset).toString().equals(text);