package com.tang.intellij.lua.editor;

import com.intellij.codeInsight.hints.InlayInfo;
import com.intellij.codeInsight.hints.InlayParameterHintsProvider;
import com.intellij.codeInsight.hints.MethodInfo;
import com.intellij.lang.Language;
import com.intellij.psi.PsiElement;
import com.tang.intellij.lua.psi.LuaArgs;
import com.tang.intellij.lua.psi.LuaCallExpr;
import com.tang.intellij.lua.psi.LuaExpr;
import com.tang.intellij.lua.psi.LuaExprList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 *
 * Created by TangZX on 2016/12/14.
 */
public class LuaParameterHintsProvider implements InlayParameterHintsProvider {
    @NotNull
    @Override
    public List<InlayInfo> getParameterHints(PsiElement psiElement) {
        List<InlayInfo> list = new ArrayList<>();
        if (psiElement instanceof LuaCallExpr) {
            LuaCallExpr callExpr = (LuaCallExpr) psiElement;
            LuaArgs args = callExpr.getArgs();
            if (args != null) {
                LuaExprList luaExprList = args.getExprList();
                if (luaExprList != null) {
                    List<LuaExpr> exprList = luaExprList.getExprList();
                    for (LuaExpr expr : exprList) {
                        list.add(new InlayInfo("AAA", expr.getTextOffset()));
                    }
                }
            }
        }

        return list;
    }

    @Nullable
    @Override
    public MethodInfo getMethodInfo(PsiElement psiElement) {
        if (psiElement instanceof LuaCallExpr) {
            List<String> list = new ArrayList<>();
            //list.add("aaa");
            return new MethodInfo("", list);
        }
        return null;
    }

    @NotNull
    @Override
    public Set<String> getDefaultBlackList() {
        Set<String> stringSet = new HashSet<>();
        stringSet.add("test");
        return stringSet;
    }

    @Nullable
    @Override
    public Language getBlackListDependencyLanguage() {
        return null;
    }
}

@@ -1015,16 +1015,17 @@
 lement;%0A
+%0A
         
@@ -1297,16 +1297,79 @@
    for (
+int i = 0; i %3C exprList.size(); i++) %7B%0A                        
 LuaExpr 
@@ -1377,9 +1377,9 @@
 xpr 
-:
+=
  exp
@@ -1383,19 +1383,24 @@
 exprList
-) %7B
+.get(i);
 %0A       
@@ -1756,39 +1756,8 @@
 ();%0A
-            //list.add(%22aaa%22);%0A
     
@@ -1787,16 +1787,26 @@
 odInfo(%22
+MethodInfo
 %22, list)

test parameter name hints