Fix tables not properly parsing their key, value types when working with nested tables
This commit is contained in:
parent
57b7fd1c69
commit
6b2db3f169
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
@ -183,6 +182,11 @@ namespace UpsilonLanguageServer
|
|||
}
|
||||
|
||||
private static readonly Regex TableMatcher = new Regex(@"table *\((?'catch'.*)\)", RegexOptions.IgnoreCase);
|
||||
|
||||
private static readonly Regex TableKeyValueMatcher =
|
||||
new Regex(
|
||||
@"(?'keyType'(?:\w| )+) *(?:\((?'keyInternalType'.*)\))* *, *(?'valueType'(?:\w| )+)(?:\((?'valueInternalType'.*)\))*",
|
||||
RegexOptions.IgnoreCase);
|
||||
private static TypeContainer ParseType(string input)
|
||||
{
|
||||
input = input.Trim();
|
||||
|
@ -193,8 +197,7 @@ namespace UpsilonLanguageServer
|
|||
if (string.Equals(input, "bool", StringComparison.InvariantCultureIgnoreCase))
|
||||
return Type.Boolean;
|
||||
if (string.Equals(input, "table", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
}
|
||||
return Type.Table;
|
||||
if (string.Equals(input, "function", StringComparison.InvariantCultureIgnoreCase))
|
||||
return Type.Function;
|
||||
if (string.Equals(input, "unknown", StringComparison.InvariantCultureIgnoreCase))
|
||||
|
@ -203,13 +206,27 @@ namespace UpsilonLanguageServer
|
|||
if (match.Success)
|
||||
{
|
||||
var group = match.Groups["catch"].Value;
|
||||
var split = group.Split(',', StringSplitOptions.RemoveEmptyEntries);
|
||||
return new CompositeTypeContainer()
|
||||
{
|
||||
Types = split.Select(ParseType).ToImmutableArray()
|
||||
};
|
||||
return ParseTableKeyValue(group);
|
||||
}
|
||||
return new TypeContainer(input);
|
||||
}
|
||||
|
||||
private static CompositeTypeContainer ParseTableKeyValue(string s)
|
||||
{
|
||||
var match = TableKeyValueMatcher.Match(s);
|
||||
var dictionary = match.Groups.Where(x => x.Success).ToDictionary(x => x.Name, x => x.Value);
|
||||
var keyType = ParseType(dictionary["keyType"]);
|
||||
var valueType = ParseType(dictionary["valueType"]);
|
||||
if (keyType == Type.Table && dictionary.TryGetValue("keyInternalType", out var keyInternalType))
|
||||
{
|
||||
keyType = ParseTableKeyValue(keyInternalType);
|
||||
}
|
||||
if (valueType == Type.Table && dictionary.TryGetValue("valueInternalType", out var valueInternalType))
|
||||
{
|
||||
valueType = ParseTableKeyValue(valueInternalType);
|
||||
}
|
||||
|
||||
return new CompositeTypeContainer(new[] {keyType, valueType}.ToImmutableArray());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -64,12 +64,16 @@ namespace UpsilonLanguageServer.Services
|
|||
await Client.Window.ShowMessage(MessageType.Info, "Upsilon Language Server Initialized");
|
||||
}
|
||||
|
||||
public void Shutdown()
|
||||
{
|
||||
Session.StopServer();
|
||||
}
|
||||
|
||||
[JsonRpcMethod(IsNotification = true)]
|
||||
public void Exit()
|
||||
{
|
||||
Client.Window.ShowMessage(MessageType.Info, "Upsilon Language Server exited");
|
||||
Session.StopServer();
|
||||
Process.GetCurrentProcess().Kill();
|
||||
}
|
||||
|
||||
[JsonRpcMethod("$/cancelRequest", IsNotification = true)]
|
||||
|
|
|
@ -48,6 +48,10 @@ namespace UpsilonLanguageServer.Services
|
|||
contents.Append($"\n\nReturns: {fVar.FunctionOption.First().ResultType}");
|
||||
}
|
||||
}
|
||||
else if (findNode is BoundVariableAssignment variableAssignment)
|
||||
{
|
||||
contents.Append($"\n\nType: {variableAssignment.Variable.Type}");
|
||||
}
|
||||
else if (findNode is BoundFunctionExpression fe)
|
||||
{
|
||||
contents.Append($"\n\nReturns: {fe.ReturnType}");
|
||||
|
|
Loading…
Reference in New Issue