package com.andresdominguez.ngsort.sort;

import com.intellij.lang.javascript.psi.JSParameterList;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.command.CommandProcessor;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.PsiTreeUtil;

public class SortParamListAction extends AnAction {

  @Override
  public void actionPerformed(AnActionEvent e) {
    final Editor editor = e.getData(PlatformDataKeys.EDITOR);
    PsiFile psiFile = e.getData(CommonDataKeys.PSI_FILE);
    if (editor == null || psiFile == null) {
      return;
    }

    PsiElement element = psiFile.findElementAt(editor.getCaretModel().getOffset());
    final JSParameterList parameterList = PsiTreeUtil.getParentOfType(element, JSParameterList.class);
    if (parameterList == null) {
      return;
    }

    final Document document = editor.getDocument();
    CommandProcessor.getInstance().executeCommand(getEventProject(e), new Runnable() {
      @Override
      public void run() {
        NgSorter.sortFunctionArgs(parameterList, document);
      }
    }, "ng sort", null);
  }
}

@@ -35,16 +35,115 @@
 .sort;%0A%0A
+import com.andresdominguez.ngsort.CommandRunner;%0Aimport com.intellij.codeInsight.hint.HintManager;%0A
 import c
@@ -418,62 +418,8 @@
 ys;%0A
-import com.intellij.openapi.command.CommandProcessor;%0A
 impo
@@ -1126,32 +1126,116 @@
 List == null) %7B%0A
+      HintManager.getInstance().showErrorHint(editor, %22Can't find parameter list%22);%0A
       return;%0A  
@@ -1306,39 +1306,18 @@
 mand
-Processor.getInstance().execute
+Runner.run
 Comm
@@ -1476,25 +1476,8 @@
    %7D
-, %22ng sort%22, null
 );%0A 

add error, use runCommand