Fix tables not properly parsing their key, value types when working with nested tables
This commit is contained in:
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;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Immutable;
|
using System.Collections.Immutable;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using Newtonsoft.Json.Linq;
|
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 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)
|
private static TypeContainer ParseType(string input)
|
||||||
{
|
{
|
||||||
input = input.Trim();
|
input = input.Trim();
|
||||||
@@ -193,8 +197,7 @@ namespace UpsilonLanguageServer
|
|||||||
if (string.Equals(input, "bool", StringComparison.InvariantCultureIgnoreCase))
|
if (string.Equals(input, "bool", StringComparison.InvariantCultureIgnoreCase))
|
||||||
return Type.Boolean;
|
return Type.Boolean;
|
||||||
if (string.Equals(input, "table", StringComparison.InvariantCultureIgnoreCase))
|
if (string.Equals(input, "table", StringComparison.InvariantCultureIgnoreCase))
|
||||||
{
|
return Type.Table;
|
||||||
}
|
|
||||||
if (string.Equals(input, "function", StringComparison.InvariantCultureIgnoreCase))
|
if (string.Equals(input, "function", StringComparison.InvariantCultureIgnoreCase))
|
||||||
return Type.Function;
|
return Type.Function;
|
||||||
if (string.Equals(input, "unknown", StringComparison.InvariantCultureIgnoreCase))
|
if (string.Equals(input, "unknown", StringComparison.InvariantCultureIgnoreCase))
|
||||||
@@ -203,13 +206,27 @@ namespace UpsilonLanguageServer
|
|||||||
if (match.Success)
|
if (match.Success)
|
||||||
{
|
{
|
||||||
var group = match.Groups["catch"].Value;
|
var group = match.Groups["catch"].Value;
|
||||||
var split = group.Split(',', StringSplitOptions.RemoveEmptyEntries);
|
return ParseTableKeyValue(group);
|
||||||
return new CompositeTypeContainer()
|
|
||||||
{
|
|
||||||
Types = split.Select(ParseType).ToImmutableArray()
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
return new TypeContainer(input);
|
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");
|
await Client.Window.ShowMessage(MessageType.Info, "Upsilon Language Server Initialized");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Shutdown()
|
||||||
|
{
|
||||||
|
Session.StopServer();
|
||||||
|
}
|
||||||
|
|
||||||
[JsonRpcMethod(IsNotification = true)]
|
[JsonRpcMethod(IsNotification = true)]
|
||||||
public void Exit()
|
public void Exit()
|
||||||
{
|
{
|
||||||
Client.Window.ShowMessage(MessageType.Info, "Upsilon Language Server exited");
|
Client.Window.ShowMessage(MessageType.Info, "Upsilon Language Server exited");
|
||||||
Session.StopServer();
|
Session.StopServer();
|
||||||
Process.GetCurrentProcess().Kill();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonRpcMethod("$/cancelRequest", IsNotification = true)]
|
[JsonRpcMethod("$/cancelRequest", IsNotification = true)]
|
||||||
|
|||||||
@@ -48,6 +48,10 @@ namespace UpsilonLanguageServer.Services
|
|||||||
contents.Append($"\n\nReturns: {fVar.FunctionOption.First().ResultType}");
|
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)
|
else if (findNode is BoundFunctionExpression fe)
|
||||||
{
|
{
|
||||||
contents.Append($"\n\nReturns: {fe.ReturnType}");
|
contents.Append($"\n\nReturns: {fe.ReturnType}");
|
||||||
|
|||||||
Reference in New Issue
Block a user