Skip to content

Commit 3af01a7

Browse files
committed
Auto-import is not placed on a new line in JS files with GraphQL templates (#91)
1 parent 8ff1a47 commit 3af01a7

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/main/com/intellij/lang/jsgraphql/ide/formatter/JSGraphQLBlockWrapper.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,12 @@ public Indent getIndent() {
166166
@Override
167167
public Spacing getSpacing(@Nullable Block child1, @NotNull Block child2) {
168168
if(wrapped != null) {
169-
return wrapped.getSpacing(child1, child2);
169+
Spacing wrappedSpacing = wrapped.getSpacing(child1, child2);
170+
if(wrappedSpacing == null) {
171+
// the wrapped formatter might not recognize a wrapped block, so try with the orignal wrapped children instead
172+
wrappedSpacing = wrapped.getSpacing(unwrap(child1), unwrap(child2));
173+
}
174+
return wrappedSpacing;
170175
}
171176
return spacingBuilder.getSpacing(this, child1, child2);
172177
}
@@ -209,6 +214,13 @@ public CodeStyleSettings getSettings() {
209214

210215
// ---- implementation ----
211216

217+
private Block unwrap(Block child) {
218+
if(child instanceof JSGraphQLBlockWrapper) {
219+
return ((JSGraphQLBlockWrapper) child).wrapped;
220+
}
221+
return child;
222+
}
223+
212224
// This is based on AbstractBlock.buildInjectedBlocks, but substitutes DefaultInjectedLanguageBlockBuilder for a JSGraphQLInjectedLanguageBlockBuilder to
213225
// enable host JS/TS template fragments that separate/shreds the GraphQL with ${...} expressions
214226
@NotNull

0 commit comments

Comments
 (0)