Exemple #1
0
    public static void GenerateVSCodeSnippets()
    {
        StringBuilder snippets = new StringBuilder();
        VSCodeSnippet snippet  = new VSCodeSnippet {
            body = new string[1]
        };

        foreach (LuaApiInfo api in GetAllApiInfo())
        {
            // Write out the header for the api type
            LuaApi luaApiDetails = api.Attribute;

            // Iterate all methods
            foreach (LuaFunction_Info method in api.functions)
            {
                // Grab the LuaApiFunction if it exists
                LuaApiFunction luaMethodDetails = method.Attribute;

                snippet.prefix = string.Format("{0}.{1}", luaApiDetails.luaName, luaMethodDetails.name);

                string paramString = string.Empty;

                var paramArray = method.MethodInfo.GetParameters();
                for (int i = 0; i < paramArray.Length; i++)
                {
                    var param = paramArray[i];

                    paramString += string.Format("${{{0}:{1}}}, ", i, param.Name);
                }

                if (!string.IsNullOrEmpty(paramString))
                {
                    paramString = paramString.Remove(paramString.Length - 2, 2);
                }

                snippet.body[0] = string.Format("{0}({1})", snippet.prefix, paramString);

                snippet.description = luaMethodDetails.description;

                string finalBlock = string.Format("\"{0}\": {1},", snippet.prefix, JsonUtility.ToJson(snippet, true));

                snippets.AppendLine(finalBlock);
            }

            foreach (LuaVariableInfo fieldInfo in api.variables)
            {
                LuaApiVariable luaVariableDetails = fieldInfo.Attribute;

                snippet.prefix      = string.Format("{0}.{1}", luaApiDetails.luaName, luaVariableDetails.name);
                snippet.body[0]     = snippet.prefix;
                snippet.description = luaVariableDetails.description;

                string finalBlock = string.Format("\"{0}\" : {1},", snippet.prefix, JsonUtility.ToJson(snippet, true));

                snippets.AppendLine(finalBlock);
            }
        }

        EditorGUIUtility.systemCopyBuffer = snippets.ToString();
    }
Exemple #2
0
    public static void GenerateAtomSnippets()
    {
        StringBuilder snippets = new StringBuilder();
        AtomSnippet   snippet  = new AtomSnippet();

        snippets.AppendLine("'.source.lua':");

        // Iterate all types deriving from LuaApiBase
        foreach (LuaApiInfo api in GetAllApiInfo())
        {
            // Write out the header for the api type
            LuaApi luaApiDetails = api.Attribute;

            // Iterate all methods
            foreach (LuaFunction_Info method in api.functions)
            {
                // Grab the LuaApiFunction if it exists
                LuaApiFunction luaMethodDetails = method.Attribute;

                snippet.Prefix = string.Format("{0}.{1}", luaApiDetails.luaName, luaMethodDetails.name);

                string paramString = string.Empty;

                var paramArray = method.MethodInfo.GetParameters();
                for (int i = 0; i < paramArray.Length; i++)
                {
                    var param = paramArray[i];

                    paramString += string.Format("${{{0}:{1}}}, ", i, param.Name);
                }

                if (!string.IsNullOrEmpty(paramString))
                {
                    paramString = paramString.Remove(paramString.Length - 2, 2);
                }

                snippet.Body = string.Format("{0}({1})", snippet.Prefix, paramString);

                snippet.Description = luaMethodDetails.description;

                snippets.AppendLine(snippet.ConstructCSONString());
            }

            foreach (LuaVariableInfo fieldInfo in api.variables)
            {
                LuaApiVariable luaVariableDetails = fieldInfo.Attribute;

                snippet.Prefix      = string.Format("{0}.{1}", luaApiDetails.luaName, luaVariableDetails.name);
                snippet.Body        = snippet.Prefix;
                snippet.Description = luaVariableDetails.description;

                snippets.AppendLine(snippet.ConstructCSONString());
            }
        }

        foreach (LuaEnumInfo enumInfo in GetAllEnums())
        {
            foreach (LuaEnumValueInfo enumValueInfo in enumInfo.values)
            {
                if (enumValueInfo.Attribute != null && enumValueInfo.Attribute.hidden)
                {
                    continue;
                }

                snippet.Prefix      = string.Format("{0}.{1}", enumInfo.Attribute.name, enumValueInfo.StringValue);
                snippet.Body        = snippet.Prefix;
                snippet.Description = enumValueInfo.Attribute != null ? enumValueInfo.Attribute.description : string.Empty;

                snippet.DescriptionMoreUrl = string.Empty;

                snippets.AppendLine(snippet.ConstructCSONString());
            }
        }

        EditorGUIUtility.systemCopyBuffer = snippets.ToString();
    }
Exemple #3
0
    private static void GenerateMediaWikiDocs()
    {
        Logger.Log(Channel.Lua, "Beginning Lua doc generation for MediaWiki");

        string documentationPath =
            EditorUtility.OpenFolderPanel("Choose a location to place wiki files", string.Empty, string.Empty);

        if (!string.IsNullOrEmpty(documentationPath))
        {
            // Iterate all types deriving from LuaApiBase
            foreach (LuaApiInfo api in GetAllApiInfo())
            {
                // Write out the header for the api type
                LuaApi luaApiDetails = api.Attribute;

                string apiDocPath = string.Format("{0}/{1}.mediawiki", documentationPath, luaApiDetails.luaName);

                StreamWriter documentation = File.CreateText(apiDocPath);

                Logger.Log(Channel.Lua, "Generating documentation for api: {0}", luaApiDetails.luaName);

                documentation.WriteLine("= {0} =", luaApiDetails.luaName);

                if (!string.IsNullOrEmpty(luaApiDetails.description))
                {
                    documentation.WriteLine("== Description ==");
                    documentation.WriteLine(luaApiDetails.description);
                }
                if (!string.IsNullOrEmpty(luaApiDetails.notes))
                {
                    documentation.WriteLine("== Notes ==");
                    documentation.WriteLine(luaApiDetails.notes);
                }


                documentation.WriteLine("== Functions ==");

                // Iterate all methods
                foreach (LuaFunction_Info method in api.functions)
                {
                    // Grab the LuaApiFunction if it exists
                    LuaApiFunction luaMethodDetails = method.Attribute;

                    Logger.Log(Channel.Lua, "\t {0}", luaMethodDetails.name);

                    documentation.WriteLine("=== {0} ===", luaMethodDetails.name);

                    string functionSig = GetCleanFunctionSignature(method.MethodInfo, luaMethodDetails, luaApiDetails);

                    documentation.WriteLine("<syntaxhighlight source lang=\"lua\">{0}</syntaxhighlight>", functionSig);

                    bool hasParams = method.MethodInfo.GetParameters().Length != 0;

                    if (hasParams)
                    {
                        documentation.WriteLine("'''Expected parameter types'''");
                        documentation.WriteLine("{| class=\"wikitable\"");
                    }

                    // Expected param types
                    foreach (ParameterInfo param in method.MethodInfo.GetParameters())
                    {
                        documentation.WriteLine("|-");
                        documentation.WriteLine("| {0} || {1}", param.Name, GetCleanTypeName(param.ParameterType));
                    }

                    if (hasParams)
                    {
                        documentation.WriteLine("|}");
                    }

                    documentation.WriteLine("'''Description''': {0}\n", luaMethodDetails.description);

                    // Use custom return description if exists, else generate one
                    documentation.WriteLine("'''Returns''': {0}\n",
                                            !string.IsNullOrEmpty(luaMethodDetails.returns)
                        ? luaMethodDetails.returns
                        : GetCleanTypeName(method.MethodInfo.ReturnType));

                    if (!string.IsNullOrEmpty(luaMethodDetails.notes))
                    {
                        documentation.WriteLine("'''Notes''': {0}",
                                                luaMethodDetails.notes);
                    }

                    if (!string.IsNullOrEmpty(luaMethodDetails.warning))
                    {
                        documentation.WriteLine("<span style=\"color:#ff0000\">'''Warning'''</span>: {0}",
                                                luaMethodDetails.warning);
                    }

                    if (!string.IsNullOrEmpty(luaMethodDetails.success))
                    {
                        documentation.WriteLine("<span style=\"color:#009000\">'''Tip'''</span>: {0}",
                                                luaMethodDetails.success);
                    }
                }

                bool wroteTitle = false;
                foreach (LuaVariableInfo fieldInfo in api.variables)
                {
                    if (!wroteTitle)
                    {
                        documentation.WriteLine("== Variables ==");
                        wroteTitle = true;
                    }

                    LuaApiVariable luaVariableDetails = fieldInfo.Attribute;

                    documentation.WriteLine("=== {0} ===", luaVariableDetails.name);

                    string varibleSig = string.Format("{0}.{1}", luaApiDetails.luaName, luaVariableDetails.name);
                    documentation.WriteLine("<syntaxhighlight source lang=\"lua\">{0}</syntaxhighlight>", varibleSig);

                    documentation.WriteLine("'''Description''': {0}\n", luaVariableDetails.description);
                }

                // Add time stamp
                documentation.WriteLine("\n\n'''Docs last hacked together on''': {0:dd/MM/yyyy H:mm}", DateTime.Now);

                documentation.Close();
            }

            // TODO Enum docs

            string enumDocPath = string.Format("{0}/Constants.mediawiki", documentationPath);

            StreamWriter enumDocumentation = File.CreateText(enumDocPath);

            enumDocumentation.WriteLine("= Constants =");

            enumDocumentation.WriteLine("== Enums ==");
            foreach (LuaEnumInfo enumInfo in GetAllEnums())
            {
                enumDocumentation.WriteLine("=== {0} ===", enumInfo.Attribute.name);
                if (!string.IsNullOrEmpty(enumInfo.Attribute.description))
                {
                    enumDocumentation.WriteLine(enumInfo.Attribute.description);
                }

                enumDocumentation.WriteLine("{| class=\"wikitable\"");
                enumDocumentation.WriteLine("|-");
                enumDocumentation.WriteLine("! Usage !! Description");

                foreach (LuaEnumValueInfo value in enumInfo.values)
                {
                    if (value.Attribute != null && value.Attribute.hidden)
                    {
                        continue;
                    }
                    enumDocumentation.WriteLine("|-");
                    enumDocumentation.WriteLine("| {0}.{1} || {2}",
                                                enumInfo.Attribute.name,
                                                value.StringValue,
                                                value.Attribute != null ? value.Attribute.description : string.Empty);
                }

                enumDocumentation.WriteLine("|}");
            }

            enumDocumentation.Close();
        }

        Logger.Log(Channel.Lua, "Completed Lua doc generation");
    }