Handle enums

This commit is contained in:
Deukhoofd 2018-12-14 16:49:34 +01:00
parent bab3cff7df
commit 214e2259b2
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
4 changed files with 26 additions and 5 deletions

View File

@ -17,12 +17,25 @@ namespace UpsilonLanguageServer
foreach (var prop in json.Properties())
{
var typeName = prop.Name;
if (!(prop.Value is JObject obj))
continue;
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)
{
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 comment = value.GetValue("comment", StringComparison.InvariantCultureIgnoreCase)?.ToString();
if (string.Equals("function", type, StringComparison.InvariantCultureIgnoreCase))

View File

@ -233,6 +233,10 @@ namespace UpsilonLanguageServer.Services
{
var kind = CompletionItemKind.Variable;
var data = new JObject();
var documentation = symbol.CommentValue == null
? ""
: $"{string.Join(" \n", symbol.CommentValue)}";
if (symbol is FunctionVariableSymbol fun)
{
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);
}