38
38
import static com .intellij .patterns .StandardPatterns .*;
39
39
40
40
public class GoKeywordCompletionContributor extends CompletionContributor implements DumbAware {
41
- private static final BracesInsertHandler ADD_BRACES_INSERT_HANDLER = new BracesInsertHandler ();
42
41
private static final InsertHandler <LookupElement > ADD_BRACKETS_INSERT_HANDLER = new AddBracketsInsertHandler ();
43
42
44
43
public GoKeywordCompletionContributor () {
@@ -53,9 +52,11 @@ public GoKeywordCompletionContributor() {
53
52
extend (CompletionType .BASIC , insideBlockPattern (GoTypes .IDENTIFIER ),
54
53
new GoKeywordCompletionProvider (GoCompletionUtil .KEYWORD_PRIORITY , EMPTY_INSERT_HANDLER , "fallthrough" ));
55
54
extend (CompletionType .BASIC , insideBlockPattern (GoTypes .IDENTIFIER ),
56
- new GoKeywordCompletionProvider (GoCompletionUtil .KEYWORD_PRIORITY , ADD_BRACES_INSERT_HANDLER , "select" ));
55
+ new GoKeywordCompletionProvider (GoCompletionUtil .KEYWORD_PRIORITY , BracesInsertHandler . INSTANCE , "select" ));
57
56
extend (CompletionType .BASIC , typeDeclaration (),
58
- new GoKeywordCompletionProvider (GoCompletionUtil .KEYWORD_PRIORITY , ADD_BRACES_INSERT_HANDLER , "interface" , "struct" ));
57
+ new GoKeywordCompletionProvider (GoCompletionUtil .KEYWORD_PRIORITY , BracesInsertHandler .INSTANCE , "interface" , "struct" ));
58
+ extend (CompletionType .BASIC , typeExpression (),
59
+ new GoKeywordCompletionProvider (GoCompletionUtil .KEYWORD_PRIORITY , BracesInsertHandler .ONE_LINER , "interface" , "struct" ));
59
60
extend (CompletionType .BASIC , insideForStatement (GoTypes .IDENTIFIER ),
60
61
new GoKeywordCompletionProvider (GoCompletionUtil .CONTEXT_KEYWORD_PRIORITY , EMPTY_INSERT_HANDLER , "break" , "continue" ));
61
62
extend (CompletionType .BASIC , typeExpression (), new GoKeywordCompletionProvider (GoCompletionUtil .CONTEXT_KEYWORD_PRIORITY , "chan" ));
@@ -65,19 +66,20 @@ public GoKeywordCompletionContributor() {
65
66
extend (CompletionType .BASIC , referenceExpression (), new GoKeywordCompletionProvider (GoCompletionUtil .CONTEXT_KEYWORD_PRIORITY ,
66
67
ADD_BRACKETS_INSERT_HANDLER , "map" ));
67
68
extend (CompletionType .BASIC , referenceExpression (), new GoKeywordCompletionProvider (GoCompletionUtil .CONTEXT_KEYWORD_PRIORITY ,
68
- ADD_BRACES_INSERT_HANDLER , "struct" ));
69
+ BracesInsertHandler . ONE_LINER , "struct" ));
69
70
70
- extend (CompletionType .BASIC , afterIfBlock (GoTypes .IDENTIFIER ),
71
+ extend (CompletionType .BASIC , afterIfBlock (GoTypes .IDENTIFIER ),
71
72
new GoKeywordCompletionProvider (GoCompletionUtil .CONTEXT_KEYWORD_PRIORITY , "else" ));
72
73
extend (CompletionType .BASIC , afterElseKeyword (), new GoKeywordCompletionProvider (GoCompletionUtil .CONTEXT_KEYWORD_PRIORITY , "if" ));
73
- extend (CompletionType .BASIC , insideSwitchStatement (), new GoKeywordCompletionProvider (GoCompletionUtil .CONTEXT_KEYWORD_PRIORITY , "case" , "default" ));
74
+ extend (CompletionType .BASIC , insideSwitchStatement (),
75
+ new GoKeywordCompletionProvider (GoCompletionUtil .CONTEXT_KEYWORD_PRIORITY , "case" , "default" ));
74
76
// todo: "range"
75
77
}
76
78
77
79
@ Override
78
80
public void fillCompletionVariants (@ NotNull CompletionParameters parameters , @ NotNull CompletionResultSet result ) {
79
81
super .fillCompletionVariants (parameters , result );
80
- if (insideGoOrDeferStatements (GoTypes . IDENTIFIER ).accepts (parameters .getPosition ())) {
82
+ if (insideGoOrDeferStatements ().accepts (parameters .getPosition ())) {
81
83
InsertHandler <LookupElement > insertHandler = GoKeywordCompletionProvider .createTemplateBasedInsertHandler ("go_lang_anonymous_func" );
82
84
result .addElement (
83
85
GoKeywordCompletionProvider .createKeywordLookupElement ("func" , GoCompletionUtil .CONTEXT_KEYWORD_PRIORITY , insertHandler ));
@@ -119,8 +121,8 @@ private static ElementPattern<? extends PsiElement> typeDeclaration() {
119
121
.withParent (psiElement (GoTypeReferenceExpression .class ).withParent (psiElement (GoType .class ).withParent (GoSpecType .class )));
120
122
}
121
123
122
- private static PsiElementPattern .Capture <PsiElement > insideGoOrDeferStatements (@ NotNull IElementType tokenType ) {
123
- return psiElement (tokenType )
124
+ private static PsiElementPattern .Capture <PsiElement > insideGoOrDeferStatements () {
125
+ return psiElement (GoTypes . IDENTIFIER )
124
126
.withParent (psiElement (GoExpression .class ).withParent (or (psiElement (GoDeferStatement .class ), psiElement (GoGoStatement .class ))));
125
127
}
126
128
0 commit comments