Handle enums
This commit is contained in:
parent
bab3cff7df
commit
214e2259b2
Binary file not shown.
Binary file not shown.
|
@ -17,12 +17,25 @@ namespace UpsilonLanguageServer
|
||||||
foreach (var prop in json.Properties())
|
foreach (var prop in json.Properties())
|
||||||
{
|
{
|
||||||
var typeName = prop.Name;
|
var typeName = prop.Name;
|
||||||
|
if (!(prop.Value is JObject obj))
|
||||||
|
continue;
|
||||||
|
|
||||||
var dic = new Dictionary<string, UserDataBoundProperty>();
|
var dic = new Dictionary<string, UserDataBoundProperty>();
|
||||||
var innerProperties = ((JObject)prop.Value).Properties();
|
var specialMod = obj.GetValue("__type", StringComparison.InvariantCultureIgnoreCase)?.ToString();
|
||||||
|
if (string.Equals(specialMod, "enum", StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
{
|
||||||
|
var values = obj.GetValue("values", StringComparison.InvariantCultureIgnoreCase)?.ToObject<string[]>();
|
||||||
|
if (values == null)
|
||||||
|
continue;
|
||||||
|
BoundTypeHandler.LoadUserDataTypeDefinition(new UserDataBoundEnumDefinition(values, typeName));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
var innerProperties = obj.Properties();
|
||||||
foreach (var innerProperty in innerProperties)
|
foreach (var innerProperty in innerProperties)
|
||||||
{
|
{
|
||||||
var propertyName = innerProperty.Name;
|
var propertyName = innerProperty.Name;
|
||||||
var value = (JObject)innerProperty.Value;
|
if (!(innerProperty.Value is JObject value))
|
||||||
|
continue;
|
||||||
var type = value.GetValue("type", StringComparison.InvariantCultureIgnoreCase)?.ToString();
|
var type = value.GetValue("type", StringComparison.InvariantCultureIgnoreCase)?.ToString();
|
||||||
var comment = value.GetValue("comment", StringComparison.InvariantCultureIgnoreCase)?.ToString();
|
var comment = value.GetValue("comment", StringComparison.InvariantCultureIgnoreCase)?.ToString();
|
||||||
if (string.Equals("function", type, StringComparison.InvariantCultureIgnoreCase))
|
if (string.Equals("function", type, StringComparison.InvariantCultureIgnoreCase))
|
||||||
|
|
|
@ -233,6 +233,10 @@ namespace UpsilonLanguageServer.Services
|
||||||
{
|
{
|
||||||
var kind = CompletionItemKind.Variable;
|
var kind = CompletionItemKind.Variable;
|
||||||
var data = new JObject();
|
var data = new JObject();
|
||||||
|
var documentation = symbol.CommentValue == null
|
||||||
|
? ""
|
||||||
|
: $"{string.Join(" \n", symbol.CommentValue)}";
|
||||||
|
|
||||||
if (symbol is FunctionVariableSymbol fun)
|
if (symbol is FunctionVariableSymbol fun)
|
||||||
{
|
{
|
||||||
kind = CompletionItemKind.Function;
|
kind = CompletionItemKind.Function;
|
||||||
|
@ -252,11 +256,15 @@ namespace UpsilonLanguageServer.Services
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
else if (boundVar.Type == Type.UserData)
|
||||||
|
{
|
||||||
|
if (boundVar.BoundTypeDefinition is UserDataBoundEnumDefinition)
|
||||||
|
{
|
||||||
|
kind = CompletionItemKind.Enum;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var documentation = symbol.CommentValue == null
|
|
||||||
? ""
|
|
||||||
: $"{string.Join(" \n", symbol.CommentValue)}";
|
|
||||||
return new CompletionItem(symbol.Name, kind, symbol.Type.ToString(), documentation, data);
|
return new CompletionItem(symbol.Name, kind, symbol.Type.ToString(), documentation, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue