Auto-popup completion after @
This commit is contained in:
@@ -115,6 +115,10 @@ public class KotlinTypedHandler extends TypedHandlerDelegate {
|
|||||||
case '.':
|
case '.':
|
||||||
autoPopupMemberLookup(project, editor);
|
autoPopupMemberLookup(project, editor);
|
||||||
return Result.CONTINUE;
|
return Result.CONTINUE;
|
||||||
|
|
||||||
|
case '@':
|
||||||
|
autoPopupLabelLookup(project, editor);
|
||||||
|
return Result.CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
@Override
|
||||||
public Result charTyped(char c, Project project, @NotNull Editor editor, @NotNull PsiFile file) {
|
public Result charTyped(char c, Project project, @NotNull Editor editor, @NotNull PsiFile file) {
|
||||||
if (!(file instanceof JetFile)) {
|
if (!(file instanceof JetFile)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user