Auto-popup completion after @

This commit is contained in:
Valentin Kipyatkov
2014-12-26 15:34:59 +03:00
parent 39a5486db8
commit 95285f7a2e
@@ -115,6 +115,10 @@ public class KotlinTypedHandler extends TypedHandlerDelegate {
case '.':
autoPopupMemberLookup(project, editor);
return Result.CONTINUE;
case '@':
autoPopupLabelLookup(project, editor);
return Result.CONTINUE;
}
return Result.CONTINUE;
@@ -135,6 +139,30 @@ public class KotlinTypedHandler extends TypedHandlerDelegate {
});
}
private static void autoPopupLabelLookup(Project project, final Editor editor) {
AutoPopupController.getInstance(project).autoPopupMemberLookup(editor, new Condition<PsiFile>() {
@Override
public boolean value(PsiFile file) {
int offset = editor.getCaretModel().getOffset();
CharSequence chars = editor.getDocument().getCharsSequence();
if (!endsWith(chars, offset, "this@")
&& !endsWith(chars, offset, "return@")
&& !endsWith(chars, offset, "break@")
&& !endsWith(chars, offset, "continue@")) return false;
PsiElement lastElement = file.findElementAt(offset - 1);
if (lastElement == null) return false;
return lastElement.getNode().getElementType() == JetTokens.LABEL_IDENTIFIER;
}
});
}
private static boolean endsWith(CharSequence chars, int offset, String text) {
return chars.subSequence(offset - text.length(), offset).toString().equals(text);
}
@Override
public Result charTyped(char c, Project project, @NotNull Editor editor, @NotNull PsiFile file) {
if (!(file instanceof JetFile)) {