|
85 | 85 | import com.intellij.util.containers.ImmutableList;
|
86 | 86 | import com.intellij.util.messages.MessageBusConnection;
|
87 | 87 | import com.intellij.util.ui.UIUtil;
|
| 88 | +import org.apache.commons.httpclient.Header; |
88 | 89 | import org.apache.commons.httpclient.HttpClient;
|
89 | 90 | import org.apache.commons.httpclient.methods.PostMethod;
|
90 | 91 | import org.apache.commons.httpclient.methods.StringRequestEntity;
|
@@ -464,18 +465,22 @@ public void executeGraphQL(Editor editor, VirtualFile virtualFile) {
|
464 | 465 | httpClient.executeMethod(method);
|
465 | 466 | final String responseJson = Optional.fromNullable(method.getResponseBodyAsString()).or("");
|
466 | 467 | sw.stop();
|
| 468 | + final Header responseHeader = method.getResponseHeader("Content-Type"); |
| 469 | + final boolean reformatJson = responseHeader != null && "application/json".equals(responseHeader.getValue()); |
467 | 470 | final Integer errorCount = getErrorCount(responseJson);
|
468 | 471 | if (fileEditor instanceof TextEditor) {
|
469 | 472 | final TextEditor textEditor = (TextEditor) fileEditor;
|
470 | 473 | UIUtil.invokeLaterIfNeeded(() -> {
|
471 | 474 | ApplicationManager.getApplication().runWriteAction(() -> {
|
472 | 475 | final Document document = textEditor.getEditor().getDocument();
|
473 |
| - document.setText(responseJson); |
474 |
| - if(requestJson.startsWith("{")) { |
475 |
| - final PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(document); |
476 |
| - if (psiFile != null) { |
477 |
| - new ReformatCodeProcessor(psiFile, false).run(); |
478 |
| - } |
| 476 | + document.setText(responseJson.replace("\r\n", "\n")); |
| 477 | + if(reformatJson) { |
| 478 | + PsiDocumentManager.getInstance(myProject).performForCommittedDocument(document, () -> { |
| 479 | + final PsiFile psiFile = PsiDocumentManager.getInstance(myProject).getPsiFile(document); |
| 480 | + if (psiFile != null) { |
| 481 | + new ReformatCodeProcessor(psiFile, false).run(); |
| 482 | + } |
| 483 | + }); // wait for doc to update PSI before reformat |
479 | 484 | }
|
480 | 485 | });
|
481 | 486 | final StringBuilder queryResultText = new StringBuilder(virtualFile.getName()).
|
|
0 commit comments