Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vscode geneator #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 54 additions & 2 deletions Documentation/LuaDocGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,27 @@ private static List<LuaEnumInfo> 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<Config>(file);
}

var defaultConfig = new Config {
LuaProjectPath = Path.Combine(Application.dataPath, "Scripts", "Lua")
};

File.WriteAllText(configFile, JsonUtility.ToJson(defaultConfig));
return defaultConfig;
}

/// <summary>
/// Generate MediaWiki pages for all Lua apis and enums
Expand Down Expand Up @@ -401,8 +422,40 @@ 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;

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

snippets.AppendLine(finalBlock);
}
}

Config config = GetConfig();

string snippetDir = Path.Combine(config.LuaProjectPath, ".vscode");
Directory.CreateDirectory(snippetDir);

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
Expand Down Expand Up @@ -597,6 +650,5 @@ private static string GetCleanTypeName(Type type)

return result;
}

}
#endif // UNITY_EDITOR