3838import static com .intellij .patterns .StandardPatterns .*;
3939
4040public class GoKeywordCompletionContributor extends CompletionContributor implements DumbAware {
41- private static final BracesInsertHandler ADD_BRACES_INSERT_HANDLER = new BracesInsertHandler ();
4241 private static final InsertHandler <LookupElement > ADD_BRACKETS_INSERT_HANDLER = new AddBracketsInsertHandler ();
4342
4443 public GoKeywordCompletionContributor () {
@@ -53,9 +52,11 @@ public GoKeywordCompletionContributor() {
5352 extend (CompletionType .BASIC , insideBlockPattern (GoTypes .IDENTIFIER ),
5453 new GoKeywordCompletionProvider (GoCompletionUtil .KEYWORD_PRIORITY , EMPTY_INSERT_HANDLER , "fallthrough" ));
5554 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" ));
5756 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" ));
5960 extend (CompletionType .BASIC , insideForStatement (GoTypes .IDENTIFIER ),
6061 new GoKeywordCompletionProvider (GoCompletionUtil .CONTEXT_KEYWORD_PRIORITY , EMPTY_INSERT_HANDLER , "break" , "continue" ));
6162 extend (CompletionType .BASIC , typeExpression (), new GoKeywordCompletionProvider (GoCompletionUtil .CONTEXT_KEYWORD_PRIORITY , "chan" ));
@@ -65,19 +66,20 @@ public GoKeywordCompletionContributor() {
6566 extend (CompletionType .BASIC , referenceExpression (), new GoKeywordCompletionProvider (GoCompletionUtil .CONTEXT_KEYWORD_PRIORITY ,
6667 ADD_BRACKETS_INSERT_HANDLER , "map" ));
6768 extend (CompletionType .BASIC , referenceExpression (), new GoKeywordCompletionProvider (GoCompletionUtil .CONTEXT_KEYWORD_PRIORITY ,
68- ADD_BRACES_INSERT_HANDLER , "struct" ));
69+ BracesInsertHandler . ONE_LINER , "struct" ));
6970
70- extend (CompletionType .BASIC , afterIfBlock (GoTypes .IDENTIFIER ),
71+ extend (CompletionType .BASIC , afterIfBlock (GoTypes .IDENTIFIER ),
7172 new GoKeywordCompletionProvider (GoCompletionUtil .CONTEXT_KEYWORD_PRIORITY , "else" ));
7273 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" ));
7476 // todo: "range"
7577 }
7678
7779 @ Override
7880 public void fillCompletionVariants (@ NotNull CompletionParameters parameters , @ NotNull CompletionResultSet result ) {
7981 super .fillCompletionVariants (parameters , result );
80- if (insideGoOrDeferStatements (GoTypes . IDENTIFIER ).accepts (parameters .getPosition ())) {
82+ if (insideGoOrDeferStatements ().accepts (parameters .getPosition ())) {
8183 InsertHandler <LookupElement > insertHandler = GoKeywordCompletionProvider .createTemplateBasedInsertHandler ("go_lang_anonymous_func" );
8284 result .addElement (
8385 GoKeywordCompletionProvider .createKeywordLookupElement ("func" , GoCompletionUtil .CONTEXT_KEYWORD_PRIORITY , insertHandler ));
@@ -119,8 +121,8 @@ private static ElementPattern<? extends PsiElement> typeDeclaration() {
119121 .withParent (psiElement (GoTypeReferenceExpression .class ).withParent (psiElement (GoType .class ).withParent (GoSpecType .class )));
120122 }
121123
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 )
124126 .withParent (psiElement (GoExpression .class ).withParent (or (psiElement (GoDeferStatement .class ), psiElement (GoGoStatement .class ))));
125127 }
126128
0 commit comments