Support for method overloading
This commit is contained in:
parent
89f3db509d
commit
14b84ab4d8
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,6 +1,7 @@
|
||||||
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;
|
||||||
|
@ -68,9 +69,14 @@ namespace UpsilonLanguageServer
|
||||||
private static void ParseMethod(JObject value, IDictionary<string, UserDataBoundProperty> dic,
|
private static void ParseMethod(JObject value, IDictionary<string, UserDataBoundProperty> dic,
|
||||||
string propertyName, string type, string comment)
|
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>();
|
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();
|
var properties = parameterJson.Properties();
|
||||||
foreach (var property in 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,
|
Type = ParseType(t)
|
||||||
ActualType = type,
|
|
||||||
Comment = comment,
|
|
||||||
Type = ParseType(type),
|
|
||||||
ResultType = ParseType(returnType),
|
|
||||||
Parameters = parameters.ToArray()
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,9 +139,14 @@ namespace UpsilonLanguageServer
|
||||||
}
|
}
|
||||||
else if (type == Type.Function)
|
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>();
|
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();
|
var properties = parameterJson.Properties();
|
||||||
foreach (var prop in properties)
|
foreach (var prop in properties)
|
||||||
|
@ -154,8 +164,9 @@ namespace UpsilonLanguageServer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var parsedReturnType = ParseType(returnType);
|
var parsedReturnType = ParseType(returnType);
|
||||||
StaticScope.BoundScope.AssignToNearest(new InternalFunctionVariableSymbol(name, false,
|
listOptions.Add(new InternalFunctionVariableOption(parsedReturnType, parameters.ToArray(), null));
|
||||||
parsedReturnType, parameters.ToArray(), null)
|
}
|
||||||
|
StaticScope.BoundScope.AssignToNearest(new InternalFunctionVariableSymbol(name, false, Type.Function, listOptions)
|
||||||
{
|
{
|
||||||
CommentValue = comments
|
CommentValue = comments
|
||||||
});
|
});
|
||||||
|
@ -174,6 +185,8 @@ 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 TypeContainer ParseType(string input)
|
private static TypeContainer ParseType(string input)
|
||||||
{
|
{
|
||||||
|
if (input == null)
|
||||||
|
Debugger.Break();
|
||||||
input = input.Trim();
|
input = input.Trim();
|
||||||
if (string.Equals(input, "string", StringComparison.InvariantCultureIgnoreCase))
|
if (string.Equals(input, "string", StringComparison.InvariantCultureIgnoreCase))
|
||||||
return Type.String;
|
return Type.String;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using JsonRpc.Standard;
|
using JsonRpc.Standard;
|
||||||
|
@ -15,6 +16,8 @@ namespace UpsilonLanguageServer.Services
|
||||||
[JsonRpcMethod(AllowExtensionData = true)]
|
[JsonRpcMethod(AllowExtensionData = true)]
|
||||||
public InitializeResult Initialize(int processId, Uri rootUri, ClientCapabilities capabilities,
|
public InitializeResult Initialize(int processId, Uri rootUri, ClientCapabilities capabilities,
|
||||||
JToken initializationOptions = null, string trace = null)
|
JToken initializationOptions = null, string trace = null)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
WorkspaceService.RootUri = rootUri?.AbsolutePath;
|
WorkspaceService.RootUri = rootUri?.AbsolutePath;
|
||||||
if (rootUri != null)
|
if (rootUri != null)
|
||||||
|
@ -25,6 +28,7 @@ namespace UpsilonLanguageServer.Services
|
||||||
{
|
{
|
||||||
BoundTypeParser.LoadBoundTypes(File.ReadAllText(typesConfigFile));
|
BoundTypeParser.LoadBoundTypes(File.ReadAllText(typesConfigFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
var staticConfigFile = configPath + "/static.json";
|
var staticConfigFile = configPath + "/static.json";
|
||||||
if (File.Exists(staticConfigFile))
|
if (File.Exists(staticConfigFile))
|
||||||
{
|
{
|
||||||
|
@ -32,7 +36,13 @@ namespace UpsilonLanguageServer.Services
|
||||||
}
|
}
|
||||||
|
|
||||||
Session.Settings.ModuleDirectory =
|
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
|
return new InitializeResult(new ServerCapabilities
|
||||||
{
|
{
|
||||||
|
@ -59,6 +69,7 @@ namespace UpsilonLanguageServer.Services
|
||||||
{
|
{
|
||||||
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)]
|
||||||
|
|
|
@ -45,7 +45,7 @@ namespace UpsilonLanguageServer.Services
|
||||||
|
|
||||||
if (varSymbol.VariableSymbol is FunctionVariableSymbol fVar)
|
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)
|
else if (findNode is BoundFunctionExpression fe)
|
||||||
|
@ -90,7 +90,7 @@ namespace UpsilonLanguageServer.Services
|
||||||
var n = new SignatureHelp(new List<SignatureInformation>()
|
var n = new SignatureHelp(new List<SignatureInformation>()
|
||||||
{
|
{
|
||||||
new SignatureInformation(exp.Name, string.Join(" \n", exp.CommentValue),
|
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())
|
x => new ParameterInformation("", $"{x.Name} ({x.ValidTypes})")).ToList())
|
||||||
}, 0, functionCall.Parameters.Length);
|
}, 0, functionCall.Parameters.Length);
|
||||||
return n;
|
return n;
|
||||||
|
@ -247,10 +247,15 @@ namespace UpsilonLanguageServer.Services
|
||||||
switch (fun)
|
switch (fun)
|
||||||
{
|
{
|
||||||
case InternalFunctionVariableSymbol internalFunctionVariableSymbol:
|
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;
|
break;
|
||||||
case ScriptFunctionVariableSymbol scriptFunctionVariableSymbol:
|
case ScriptFunctionVariableSymbol scriptFunctionVariableSymbol:
|
||||||
data.Add("varCount", scriptFunctionVariableSymbol.Parameters.Length);
|
data.Add("varCount",
|
||||||
|
((ScriptFunctionVariableOption) scriptFunctionVariableSymbol.FunctionOption.First())
|
||||||
|
.Parameters.Length);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -280,7 +285,7 @@ namespace UpsilonLanguageServer.Services
|
||||||
{
|
{
|
||||||
var fun = (UserDataBoundMethod)property;
|
var fun = (UserDataBoundMethod)property;
|
||||||
kind = CompletionItemKind.Function;
|
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 = "";
|
const string documentation = "";
|
||||||
|
|
Loading…
Reference in New Issue