Auto-popup completion after "::"
This commit is contained in:
@@ -40,6 +40,7 @@ import com.intellij.psi.TokenType;
|
|||||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||||
import com.intellij.psi.formatter.FormatterUtil;
|
import com.intellij.psi.formatter.FormatterUtil;
|
||||||
import com.intellij.psi.impl.source.tree.LeafPsiElement;
|
import com.intellij.psi.impl.source.tree.LeafPsiElement;
|
||||||
|
import com.intellij.psi.tree.IElementType;
|
||||||
import com.intellij.psi.tree.TokenSet;
|
import com.intellij.psi.tree.TokenSet;
|
||||||
import com.intellij.util.text.CharArrayUtil;
|
import com.intellij.util.text.CharArrayUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -119,6 +120,10 @@ public class KotlinTypedHandler extends TypedHandlerDelegate {
|
|||||||
case '@':
|
case '@':
|
||||||
autoPopupLabelLookup(project, editor);
|
autoPopupLabelLookup(project, editor);
|
||||||
return Result.CONTINUE;
|
return Result.CONTINUE;
|
||||||
|
|
||||||
|
case ':':
|
||||||
|
autoPopupCallableReferenceLookup(project, editor);
|
||||||
|
return Result.CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Result.CONTINUE;
|
return Result.CONTINUE;
|
||||||
@@ -133,8 +138,8 @@ public class KotlinTypedHandler extends TypedHandlerDelegate {
|
|||||||
PsiElement lastElement = file.findElementAt(offset - 1);
|
PsiElement lastElement = file.findElementAt(offset - 1);
|
||||||
if (lastElement == null) return false;
|
if (lastElement == null) return false;
|
||||||
|
|
||||||
String text = lastElement.getText();
|
IElementType elementType = lastElement.getNode().getElementType();
|
||||||
return ".".equals(text) || "?.".equals(text);
|
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<PsiFile>() {
|
||||||
|
@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) {
|
private static boolean endsWith(CharSequence chars, int offset, String text) {
|
||||||
if (offset < text.length()) return false;
|
if (offset < text.length()) return false;
|
||||||
return chars.subSequence(offset - text.length(), offset).toString().equals(text);
|
return chars.subSequence(offset - text.length(), offset).toString().equals(text);
|
||||||
|
|||||||
Reference in New Issue
Block a user