@@ -57,33 +57,30 @@ protected void addCompletions(@NotNull final CompletionParameters parameters, Pr
57
57
58
58
result = updateResult (parameters , result );
59
59
60
- if (hints .getHints ().isEmpty ()) {
61
- // temporary '...' completion for #4 until it's supported by codemirror-graphql -- https://github.com/graphql/codemirror-graphql/issues/7
62
- // we simply return the fragment names in the file without filtering on their applicability
63
- PsiElement originalPosition = parameters .getOriginalPosition ();
64
- if (originalPosition != null ) {
65
- if (originalPosition instanceof PsiWhiteSpace ) {
66
- // this is the completion invoked right after '...'
67
- final PsiElement prevSibling = originalPosition .getPrevSibling ();
68
- if (prevSibling != null ) {
69
- final boolean isKeyword = prevSibling .getNode ().getElementType () == JSGraphQLTokenTypes .KEYWORD ;
70
- if (isKeyword && JSGraphQLKeywords .FRAGMENT_DOTS .equals (prevSibling .getText ())) {
71
- final PsiFile file = prevSibling .getContainingFile ();
72
- addFragmentCompletions (result , file );
73
- }
60
+ // check if the completion was invoked after the '...' fragment spread keyword
61
+ boolean isFragmentSpreadCompletion = false ;
62
+ PsiElement originalPosition = parameters .getOriginalPosition ();
63
+ if (originalPosition != null ) {
64
+ if (originalPosition instanceof PsiWhiteSpace ) {
65
+ // this is the completion invoked right after '...'
66
+ final PsiElement prevSibling = originalPosition .getPrevSibling ();
67
+ if (prevSibling != null ) {
68
+ final boolean isKeyword = prevSibling .getNode ().getElementType () == JSGraphQLTokenTypes .KEYWORD ;
69
+ if (isKeyword && JSGraphQLKeywords .FRAGMENT_DOTS .equals (prevSibling .getText ())) {
70
+ isFragmentSpreadCompletion = true ;
74
71
}
75
- } else if (originalPosition .getParent () instanceof JSGraphQLNamedTypePsiElement ) {
76
- // completion inside the fragment name, e.g. after '...Fra'
77
- for (PsiElement child = originalPosition .getParent ().getPrevSibling (); child != null ; child = child .getPrevSibling ()) {
78
- if (child instanceof PsiWhiteSpace ) {
79
- continue ;
80
- }
81
- final boolean isKeyword = child .getNode ().getElementType () == JSGraphQLTokenTypes .KEYWORD ;
82
- if (isKeyword && JSGraphQLKeywords .FRAGMENT_DOTS .equals (child .getText ())) {
83
- addFragmentCompletions (result , child .getContainingFile ());
84
- }
85
- break ;
72
+ }
73
+ } else if (originalPosition .getParent () instanceof JSGraphQLNamedTypePsiElement ) {
74
+ // completion inside the fragment name, e.g. after '...Fra'
75
+ for (PsiElement child = originalPosition .getParent ().getPrevSibling (); child != null ; child = child .getPrevSibling ()) {
76
+ if (child instanceof PsiWhiteSpace ) {
77
+ continue ;
78
+ }
79
+ final boolean isKeyword = child .getNode ().getElementType () == JSGraphQLTokenTypes .KEYWORD ;
80
+ if (isKeyword && JSGraphQLKeywords .FRAGMENT_DOTS .equals (child .getText ())) {
81
+ isFragmentSpreadCompletion = true ;
86
82
}
83
+ break ;
87
84
}
88
85
}
89
86
}
@@ -103,7 +100,9 @@ protected void addCompletions(@NotNull final CompletionParameters parameters, Pr
103
100
// fields with type or built-ins
104
101
Icon propertyIcon = JSGraphQLIcons .Schema .Field ;
105
102
Icon typeIcon = hint .isRelay () ? JSGraphQLIcons .Logos .Relay : null ;
106
- if (JSGraphQLSchemaLanguageProjectService .SCALAR_TYPES .contains (type )) {
103
+ if (isFragmentSpreadCompletion ) {
104
+ propertyIcon = JSGraphQLIcons .Schema .Fragment ;
105
+ } else if (JSGraphQLSchemaLanguageProjectService .SCALAR_TYPES .contains (type )) {
107
106
if (text .equals ("true" ) || text .equals ("false" )) {
108
107
propertyIcon = null ;
109
108
type = null ;
@@ -148,22 +147,6 @@ protected void addCompletions(@NotNull final CompletionParameters parameters, Pr
148
147
149
148
}
150
149
151
- private void addFragmentCompletions (@ NotNull CompletionResultSet result , PsiFile file ) {
152
- final List <JSGraphQLFragmentDefinitionPsiElement > fragmentDefinitions = getFragmentDefinitions (file );
153
- for (JSGraphQLFragmentDefinitionPsiElement fragmentDefinition : fragmentDefinitions ) {
154
- final String name = fragmentDefinition .getName ();
155
- if (name != null ) {
156
- LookupElementBuilder element = LookupElementBuilder .create (name ).withBoldness (true );
157
- element = element .withIcon (JSGraphQLIcons .Schema .Fragment );
158
- final JSGraphQLNamedTypePsiElement fragmentOnType = fragmentDefinition .getFragmentOnType ();
159
- if (fragmentOnType != null ) {
160
- element = element .withTypeText (fragmentOnType .getName ());
161
- }
162
- result .addElement (element );
163
- }
164
- }
165
- }
166
-
167
150
private List <JSGraphQLFragmentDefinitionPsiElement > getFragmentDefinitions (PsiFile file ) {
168
151
List <JSGraphQLFragmentDefinitionPsiElement > ret = Lists .newArrayList ();
169
152
file .accept (new PsiRecursiveElementVisitor () {
0 commit comments