Support for method overloading

This commit is contained in:
Deukhoofd 2019-01-20 21:00:14 +01:00
parent 89f3db509d
commit 14b84ab4d8
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
10 changed files with 94 additions and 65 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using System.Text.RegularExpressions;
using Newtonsoft.Json.Linq;
@ -68,9 +69,14 @@ namespace UpsilonLanguageServer
private static void ParseMethod(JObject value, IDictionary<string, UserDataBoundProperty> dic,
string propertyName, string type, string comment)
{
var returnType = value.GetValue("returns", StringComparison.InvariantCultureIgnoreCase)?.ToString();
var options = value.GetValue("options", StringComparison.InvariantCultureIgnoreCase);
var listOptions = new List<UserDataBoundMethodOption>();
foreach (var jToken in options)
{
if (!(jToken is JObject option)) continue;
var returnType = option.GetValue("returns", StringComparison.InvariantCultureIgnoreCase)?.ToString();
var parameters = new List<UserDataBoundFunctionParameter>();
if (value.GetValue("Parameters", StringComparison.InvariantCultureIgnoreCase) is JObject parameterJson)
if (option.GetValue("Parameters", StringComparison.InvariantCultureIgnoreCase) is JObject parameterJson)
{
var properties = parameterJson.Properties();
foreach (var property in properties)
@ -93,15 +99,14 @@ namespace UpsilonLanguageServer
});
}
}
listOptions.Add(new UserDataBoundMethodOption(ParseType(returnType), parameters.ToArray()));
}
dic.Add(propertyName.ToLowerInvariant(), new UserDataBoundMethod()
var t = value.GetValue("type", StringComparison.InvariantCultureIgnoreCase).Value<string>();
dic.Add(propertyName.ToLowerInvariant(), new UserDataBoundMethod(propertyName, listOptions)
{
Name = propertyName,
ActualType = type,
Comment = comment,
Type = ParseType(type),
ResultType = ParseType(returnType),
Parameters = parameters.ToArray()
Type = ParseType(t)
});
}
@ -134,9 +139,14 @@ namespace UpsilonLanguageServer
}
else if (type == Type.Function)
{
var returnType = obj.GetValue("returns", StringComparison.InvariantCultureIgnoreCase).ToString().ToLowerInvariant();
var options = obj.GetValue("options", StringComparison.InvariantCultureIgnoreCase).Children();
var listOptions = new List<FunctionVariableSymbolOption>();
foreach (var jToken in options)
{
if (!(jToken is JObject option)) continue;
var returnType = option.GetValue("returns", StringComparison.InvariantCultureIgnoreCase).ToString().ToLowerInvariant();
var parameters = new List<InternalFunctionVariableSymbol.InternalFunctionParameter>();
if (obj.GetValue("Parameters", StringComparison.InvariantCultureIgnoreCase) is JObject parameterJson)
if (option.GetValue("Parameters", StringComparison.InvariantCultureIgnoreCase) is JObject parameterJson)
{
var properties = parameterJson.Properties();
foreach (var prop in properties)
@ -154,8 +164,9 @@ namespace UpsilonLanguageServer
}
}
var parsedReturnType = ParseType(returnType);
StaticScope.BoundScope.AssignToNearest(new InternalFunctionVariableSymbol(name, false,
parsedReturnType, parameters.ToArray(), null)
listOptions.Add(new InternalFunctionVariableOption(parsedReturnType, parameters.ToArray(), null));
}
StaticScope.BoundScope.AssignToNearest(new InternalFunctionVariableSymbol(name, false, Type.Function, listOptions)
{
CommentValue = comments
});
@ -174,6 +185,8 @@ namespace UpsilonLanguageServer
private static readonly Regex TableMatcher = new Regex(@"table *\((?'catch'.*)\)", RegexOptions.IgnoreCase);
private static TypeContainer ParseType(string input)
{
if (input == null)
Debugger.Break();
input = input.Trim();
if (string.Equals(input, "string", StringComparison.InvariantCultureIgnoreCase))
return Type.String;

View File

@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using JsonRpc.Standard;
@ -15,6 +16,8 @@ namespace UpsilonLanguageServer.Services
[JsonRpcMethod(AllowExtensionData = true)]
public InitializeResult Initialize(int processId, Uri rootUri, ClientCapabilities capabilities,
JToken initializationOptions = null, string trace = null)
{
try
{
WorkspaceService.RootUri = rootUri?.AbsolutePath;
if (rootUri != null)
@ -25,6 +28,7 @@ namespace UpsilonLanguageServer.Services
{
BoundTypeParser.LoadBoundTypes(File.ReadAllText(typesConfigFile));
}
var staticConfigFile = configPath + "/static.json";
if (File.Exists(staticConfigFile))
{
@ -32,7 +36,13 @@ namespace UpsilonLanguageServer.Services
}
Session.Settings.ModuleDirectory =
new DirectoryInfo(Path.Combine(rootUri.AbsolutePath, Session.Settings.ModuleDirectory)).FullName;
new DirectoryInfo(Path.Combine(rootUri.AbsolutePath, Session.Settings.ModuleDirectory))
.FullName;
}
}
catch (Exception e)
{
Client.Window.ShowMessage(MessageType.Error, e.ToString());
}
return new InitializeResult(new ServerCapabilities
{
@ -59,6 +69,7 @@ namespace UpsilonLanguageServer.Services
{
Client.Window.ShowMessage(MessageType.Info, "Upsilon Language Server exited");
Session.StopServer();
Process.GetCurrentProcess().Kill();
}
[JsonRpcMethod("$/cancelRequest", IsNotification = true)]

View File

@ -45,7 +45,7 @@ namespace UpsilonLanguageServer.Services
if (varSymbol.VariableSymbol is FunctionVariableSymbol fVar)
{
contents.Append($"\n\nReturns: {fVar.ResultType}");
contents.Append($"\n\nReturns: {fVar.FunctionOption.First().ResultType}");
}
}
else if (findNode is BoundFunctionExpression fe)
@ -90,7 +90,7 @@ namespace UpsilonLanguageServer.Services
var n = new SignatureHelp(new List<SignatureInformation>()
{
new SignatureInformation(exp.Name, string.Join(" \n", exp.CommentValue),
internalFunction.FunctionParameters.Select(
((InternalFunctionVariableOption)internalFunction.FunctionOption.First()).FunctionParameters.Select(
x => new ParameterInformation("", $"{x.Name} ({x.ValidTypes})")).ToList())
}, 0, functionCall.Parameters.Length);
return n;
@ -247,10 +247,15 @@ namespace UpsilonLanguageServer.Services
switch (fun)
{
case InternalFunctionVariableSymbol internalFunctionVariableSymbol:
data.Add("varCount", internalFunctionVariableSymbol.FunctionParameters.Count(x => !x.IsOptional));
data.Add("varCount",
((InternalFunctionVariableOption) internalFunctionVariableSymbol.FunctionOption.First())
.FunctionParameters.Count(x => !x.IsOptional));
break;
case ScriptFunctionVariableSymbol scriptFunctionVariableSymbol:
data.Add("varCount", scriptFunctionVariableSymbol.Parameters.Length);
data.Add("varCount",
((ScriptFunctionVariableOption) scriptFunctionVariableSymbol.FunctionOption.First())
.Parameters.Length);
break;
}
}
@ -280,7 +285,7 @@ namespace UpsilonLanguageServer.Services
{
var fun = (UserDataBoundMethod)property;
kind = CompletionItemKind.Function;
data.Add("varCount", fun.Parameters.Count(x => !x.IsOptional));
data.Add("varCount", fun.Options.First().Parameters.Count(x => !x.IsOptional));
}
const string documentation = "";