From 5a565b1b7f816ab1e3c83cd9bb8d6d4c6aba66d5 Mon Sep 17 00:00:00 2001 From: Arpple Date: Sat, 3 Aug 2019 15:15:41 +0700 Subject: [PATCH 1/2] generate enum for vscode --- Documentation/LuaDocGenerator.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Documentation/LuaDocGenerator.cs b/Documentation/LuaDocGenerator.cs index d0c5927..02d5749 100644 --- a/Documentation/LuaDocGenerator.cs +++ b/Documentation/LuaDocGenerator.cs @@ -401,7 +401,26 @@ public static void GenerateVSCodeSnippets() snippets.AppendLine(finalBlock); } } + + 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[0] = snippet.prefix; + snippet.description = enumValueInfo.Attribute != null ? enumValueInfo.Attribute.description : string.Empty; + string finalBlock = string.Format("\"{0}\" : {1},", snippet.prefix, JsonUtility.ToJson(snippet, true)); + + snippets.AppendLine(finalBlock); + } + } + EditorGUIUtility.systemCopyBuffer = snippets.ToString(); } From f0b910d11bebddebf42b2e0c125cc815dd2c1d17 Mon Sep 17 00:00:00 2001 From: Arpple Date: Sat, 3 Aug 2019 15:43:08 +0700 Subject: [PATCH 2/2] generate vscode snippet as file --- Documentation/LuaDocGenerator.cs | 37 ++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/Documentation/LuaDocGenerator.cs b/Documentation/LuaDocGenerator.cs index 02d5749..b770532 100644 --- a/Documentation/LuaDocGenerator.cs +++ b/Documentation/LuaDocGenerator.cs @@ -167,6 +167,27 @@ private static List GetAllEnums() return result; } + + private class Config + { + public string LuaProjectPath; + } + + private static Config GetConfig() + { + var configFile = Path.Combine(Application.dataPath, "..", ".unity-lua.json"); + if (File.Exists(configFile)) { + var file = File.ReadAllText(configFile); + return JsonUtility.FromJson(file); + } + + var defaultConfig = new Config { + LuaProjectPath = Path.Combine(Application.dataPath, "Scripts", "Lua") + }; + + File.WriteAllText(configFile, JsonUtility.ToJson(defaultConfig)); + return defaultConfig; + } /// /// Generate MediaWiki pages for all Lua apis and enums @@ -420,8 +441,21 @@ public static void GenerateVSCodeSnippets() snippets.AppendLine(finalBlock); } } + + Config config = GetConfig(); + + string snippetDir = Path.Combine(config.LuaProjectPath, ".vscode"); + Directory.CreateDirectory(snippetDir); - EditorGUIUtility.systemCopyBuffer = snippets.ToString(); + string snippetFilePath = Path.Combine(snippetDir, "lua.code-snippets"); + + StreamWriter file = File.CreateText(snippetFilePath); + + file.WriteLine("{"); + file.Write(snippets); + file.WriteLine("}"); + + file.Close(); } private class AtomSnippet @@ -616,6 +650,5 @@ private static string GetCleanTypeName(Type type) return result; } - } #endif // UNITY_EDITOR \ No newline at end of file