|
11 | 11 | import com.google.common.collect.Maps;
|
12 | 12 | import com.google.gson.Gson;
|
13 | 13 | import com.google.gson.JsonSyntaxException;
|
| 14 | +import com.intellij.codeInsight.CodeSmellInfo; |
14 | 15 | import com.intellij.codeInsight.actions.ReformatCodeProcessor;
|
15 | 16 | import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
|
| 17 | +import com.intellij.codeInsight.hint.HintManager; |
| 18 | +import com.intellij.codeInsight.hint.HintManagerImpl; |
| 19 | +import com.intellij.codeInsight.hint.HintUtil; |
16 | 20 | import com.intellij.execution.filters.UrlFilter;
|
17 | 21 | import com.intellij.execution.process.OSProcessHandler;
|
18 | 22 | import com.intellij.execution.process.ProcessAdapter;
|
|
63 | 67 | import com.intellij.openapi.ui.ComboBox;
|
64 | 68 | import com.intellij.openapi.util.Disposer;
|
65 | 69 | import com.intellij.openapi.util.Key;
|
| 70 | +import com.intellij.openapi.vcs.CodeSmellDetector; |
66 | 71 | import com.intellij.openapi.vfs.VirtualFile;
|
67 | 72 | import com.intellij.openapi.vfs.VirtualFileManager;
|
68 | 73 | import com.intellij.openapi.wm.ToolWindow;
|
|
71 | 76 | import com.intellij.psi.PsiFile;
|
72 | 77 | import com.intellij.psi.util.PsiUtilCore;
|
73 | 78 | import com.intellij.testFramework.LightVirtualFile;
|
74 |
| -import com.intellij.ui.EditorNotifications; |
75 |
| -import com.intellij.ui.IdeBorderFactory; |
76 |
| -import com.intellij.ui.OnePixelSplitter; |
77 |
| -import com.intellij.ui.SideBorder; |
| 79 | +import com.intellij.ui.*; |
78 | 80 | import com.intellij.ui.components.JBLabel;
|
79 | 81 | import com.intellij.ui.components.panels.NonOpaquePanel;
|
80 | 82 | import com.intellij.ui.content.Content;
|
@@ -409,16 +411,27 @@ public void executeGraphQL(Editor editor, VirtualFile virtualFile) {
|
409 | 411 | try {
|
410 | 412 | requestData.put("variables", getQueryVariables(editor));
|
411 | 413 | } catch (JsonSyntaxException jse) {
|
412 |
| - if (myToolWindowManagerInitialized) { |
413 |
| - myToolWindowManager.logCurrentErrors(ContainerUtil.immutableList( |
414 |
| - new JSGraphQLErrorResult( |
415 |
| - "Failed to parse variables as JSON: " + jse.getMessage(), |
416 |
| - virtualFile.getPath(), |
417 |
| - "Error", |
418 |
| - 0, |
419 |
| - 0)) |
420 |
| - , true); |
| 414 | + Editor errorEditor = editor.getUserData(GRAPH_QL_VARIABLES_EDITOR); |
| 415 | + String errorMessage = jse.getMessage(); |
| 416 | + if(errorEditor != null) { |
| 417 | + errorEditor.getContentComponent().grabFocus(); |
| 418 | + final VirtualFile errorFile = FileDocumentManager.getInstance().getFile(errorEditor.getDocument()); |
| 419 | + if (errorFile != null) { |
| 420 | + final List<CodeSmellInfo> errors = CodeSmellDetector.getInstance(myProject).findCodeSmells(ContainerUtil.list(errorFile)); |
| 421 | + for (CodeSmellInfo error : errors) { |
| 422 | + errorMessage = error.getDescription(); |
| 423 | + errorEditor.getCaretModel().moveToOffset(error.getTextRange().getStartOffset()); |
| 424 | + break; |
| 425 | + } |
| 426 | + } |
| 427 | + } else { |
| 428 | + errorEditor = editor; |
421 | 429 | }
|
| 430 | + final HintManagerImpl hintManager = HintManagerImpl.getInstanceImpl(); |
| 431 | + final JComponent label = HintUtil.createErrorLabel("Failed to parse variables as JSON:\n" + errorMessage); |
| 432 | + final LightweightHint lightweightHint = new LightweightHint(label); |
| 433 | + final Point hintPosition = hintManager.getHintPosition(lightweightHint, errorEditor, HintManager.UNDER); |
| 434 | + hintManager.showEditorHint(lightweightHint, editor, hintPosition, 0, 10000, false, HintManager.UNDER); |
422 | 435 | return;
|
423 | 436 | }
|
424 | 437 | final String requestJson = new Gson().toJson(requestData);
|
|
0 commit comments