@@ -102,7 +102,27 @@ private void fetchTokensFromLanguageService() {
102102 }
103103 final String text = token .getText ();
104104 IElementType tokenType = JSGraphQLCodeMirrorTokenMapper .getTokenType (token .getType ());
105- if (tokenType .equals (JSGraphQLTokenTypes .PUNCTUATION )) {
105+ if (tokenType .equals (JSGraphQLTokenTypes .WHITESPACE )) {
106+ String originalText = bufferAsString .substring (token .getStart (), token .getEnd ());
107+ if (originalText .trim ().length () > 0 ) {
108+ // whitespace token with visible text, e.g. due to placeholders being removed at top level
109+ // by the language service and there's nothing valid to replace it with within the GraphQL grammar
110+ // so split the token into traditional ws tokens and the placeholder contents
111+ int offset = 0 ;
112+ final String [] parts = StringUtils .splitByCharacterType (originalText );
113+ for (String part : parts ) {
114+ final Token partSourceToken = token .withTextAndOffset (part , offset );
115+ if (part .trim ().length () > 0 ) {
116+ tokens .add (new JSGraphQLToken (JSGraphQLTokenTypes .TEMPLATE_FRAGMENT , partSourceToken ));
117+ } else {
118+ partSourceToken .setKind (JSGraphQLCodeMirrorTokenMapper .CODEMIRROR_WHITESPACE );
119+ tokens .add (new JSGraphQLToken (JSGraphQLTokenTypes .WHITESPACE , partSourceToken ));
120+ }
121+ offset += part .length ();
122+ }
123+ continue ; // already added the required tokens
124+ }
125+ } else if (tokenType .equals (JSGraphQLTokenTypes .PUNCTUATION )) {
106126 final IElementType punctuationTokenType = getPunctuationTokenType (text );
107127 if (punctuationTokenType != null ) {
108128 tokenType = punctuationTokenType ;
0 commit comments