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,40 +69,44 @@ 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 parameters = new List<UserDataBoundFunctionParameter>();
|
var listOptions = new List<UserDataBoundMethodOption>();
|
||||||
if (value.GetValue("Parameters", StringComparison.InvariantCultureIgnoreCase) is JObject parameterJson)
|
foreach (var jToken in options)
|
||||||
{
|
{
|
||||||
var properties = parameterJson.Properties();
|
if (!(jToken is JObject option)) continue;
|
||||||
foreach (var property in properties)
|
var returnType = option.GetValue("returns", StringComparison.InvariantCultureIgnoreCase)?.ToString();
|
||||||
|
var parameters = new List<UserDataBoundFunctionParameter>();
|
||||||
|
if (option.GetValue("Parameters", StringComparison.InvariantCultureIgnoreCase) is JObject parameterJson)
|
||||||
{
|
{
|
||||||
var parameterName = property.Name;
|
var properties = parameterJson.Properties();
|
||||||
var parameterValue = (JObject) property.Value;
|
foreach (var property in properties)
|
||||||
var parType = parameterValue.GetValue("type", StringComparison.InvariantCultureIgnoreCase)
|
|
||||||
?.ToString();
|
|
||||||
var parComment = parameterValue.GetValue("comment", StringComparison.InvariantCultureIgnoreCase)
|
|
||||||
?.ToString();
|
|
||||||
var isOptional = parameterValue.GetValue("IsOptional", StringComparison.InvariantCultureIgnoreCase)
|
|
||||||
?.ToObject<bool>();
|
|
||||||
parameters.Add(new UserDataBoundFunctionParameter()
|
|
||||||
{
|
{
|
||||||
Name = parameterName,
|
var parameterName = property.Name;
|
||||||
Type = ParseType(parType),
|
var parameterValue = (JObject) property.Value;
|
||||||
Comment = parComment,
|
var parType = parameterValue.GetValue("type", StringComparison.InvariantCultureIgnoreCase)
|
||||||
IsOptional = isOptional.HasValue && isOptional.Value,
|
?.ToString();
|
||||||
ActualType = parType
|
var parComment = parameterValue.GetValue("comment", StringComparison.InvariantCultureIgnoreCase)
|
||||||
});
|
?.ToString();
|
||||||
|
var isOptional = parameterValue.GetValue("IsOptional", StringComparison.InvariantCultureIgnoreCase)
|
||||||
|
?.ToObject<bool>();
|
||||||
|
parameters.Add(new UserDataBoundFunctionParameter()
|
||||||
|
{
|
||||||
|
Name = parameterName,
|
||||||
|
Type = ParseType(parType),
|
||||||
|
Comment = parComment,
|
||||||
|
IsOptional = isOptional.HasValue && isOptional.Value,
|
||||||
|
ActualType = parType
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
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,28 +139,34 @@ 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 parameters = new List<InternalFunctionVariableSymbol.InternalFunctionParameter>();
|
var listOptions = new List<FunctionVariableSymbolOption>();
|
||||||
if (obj.GetValue("Parameters", StringComparison.InvariantCultureIgnoreCase) is JObject parameterJson)
|
foreach (var jToken in options)
|
||||||
{
|
{
|
||||||
var properties = parameterJson.Properties();
|
if (!(jToken is JObject option)) continue;
|
||||||
foreach (var prop in properties)
|
var returnType = option.GetValue("returns", StringComparison.InvariantCultureIgnoreCase).ToString().ToLowerInvariant();
|
||||||
|
var parameters = new List<InternalFunctionVariableSymbol.InternalFunctionParameter>();
|
||||||
|
if (option.GetValue("Parameters", StringComparison.InvariantCultureIgnoreCase) is JObject parameterJson)
|
||||||
{
|
{
|
||||||
var parameterValue = (JObject) prop.Value;
|
var properties = parameterJson.Properties();
|
||||||
var parName = parameterValue.GetValue("name", StringComparison.InvariantCultureIgnoreCase)
|
foreach (var prop in properties)
|
||||||
?.ToString();
|
{
|
||||||
var parType = parameterValue.GetValue("type", StringComparison.InvariantCultureIgnoreCase)
|
var parameterValue = (JObject) prop.Value;
|
||||||
?.ToString();
|
var parName = parameterValue.GetValue("name", StringComparison.InvariantCultureIgnoreCase)
|
||||||
var parsedType = ParseType(parType);
|
?.ToString();
|
||||||
var isOptional = parameterValue.GetValue("IsOptional", StringComparison.InvariantCultureIgnoreCase)
|
var parType = parameterValue.GetValue("type", StringComparison.InvariantCultureIgnoreCase)
|
||||||
?.ToObject<bool>();
|
?.ToString();
|
||||||
parameters.Add(new InternalFunctionVariableSymbol.InternalFunctionParameter(parName, parsedType,
|
var parsedType = ParseType(parType);
|
||||||
isOptional.HasValue && isOptional.Value));
|
var isOptional = parameterValue.GetValue("IsOptional", StringComparison.InvariantCultureIgnoreCase)
|
||||||
|
?.ToObject<bool>();
|
||||||
|
parameters.Add(new InternalFunctionVariableSymbol.InternalFunctionParameter(parName, parsedType,
|
||||||
|
isOptional.HasValue && isOptional.Value));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
var parsedReturnType = ParseType(returnType);
|
||||||
|
listOptions.Add(new InternalFunctionVariableOption(parsedReturnType, parameters.ToArray(), null));
|
||||||
}
|
}
|
||||||
var parsedReturnType = ParseType(returnType);
|
StaticScope.BoundScope.AssignToNearest(new InternalFunctionVariableSymbol(name, false, Type.Function, listOptions)
|
||||||
StaticScope.BoundScope.AssignToNearest(new InternalFunctionVariableSymbol(name, false,
|
|
||||||
parsedReturnType, parameters.ToArray(), null)
|
|
||||||
{
|
{
|
||||||
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;
|
||||||
|
@ -16,28 +17,37 @@ namespace UpsilonLanguageServer.Services
|
||||||
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)
|
||||||
{
|
{
|
||||||
WorkspaceService.RootUri = rootUri?.AbsolutePath;
|
try
|
||||||
if (rootUri != null)
|
|
||||||
{
|
{
|
||||||
var configPath = rootUri.AbsolutePath + "/.upsilon";
|
WorkspaceService.RootUri = rootUri?.AbsolutePath;
|
||||||
var typesConfigFile = configPath + "/types.json";
|
if (rootUri != null)
|
||||||
if (File.Exists(typesConfigFile))
|
|
||||||
{
|
{
|
||||||
BoundTypeParser.LoadBoundTypes(File.ReadAllText(typesConfigFile));
|
var configPath = rootUri.AbsolutePath + "/.upsilon";
|
||||||
}
|
var typesConfigFile = configPath + "/types.json";
|
||||||
var staticConfigFile = configPath + "/static.json";
|
if (File.Exists(typesConfigFile))
|
||||||
if (File.Exists(staticConfigFile))
|
{
|
||||||
{
|
BoundTypeParser.LoadBoundTypes(File.ReadAllText(typesConfigFile));
|
||||||
BoundTypeParser.LoadStaticVariables(File.ReadAllText(staticConfigFile));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Session.Settings.ModuleDirectory =
|
var staticConfigFile = configPath + "/static.json";
|
||||||
new DirectoryInfo(Path.Combine(rootUri.AbsolutePath, Session.Settings.ModuleDirectory)).FullName;
|
if (File.Exists(staticConfigFile))
|
||||||
|
{
|
||||||
|
BoundTypeParser.LoadStaticVariables(File.ReadAllText(staticConfigFile));
|
||||||
|
}
|
||||||
|
|
||||||
|
Session.Settings.ModuleDirectory =
|
||||||
|
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
|
||||||
{
|
{
|
||||||
HoverProvider = true,
|
HoverProvider = true,
|
||||||
SignatureHelpProvider = new SignatureHelpOptions( new[]{'(', ','}),
|
SignatureHelpProvider = new SignatureHelpOptions(new[] {'(', ','}),
|
||||||
CompletionProvider = new CompletionOptions(true, "."),
|
CompletionProvider = new CompletionOptions(true, "."),
|
||||||
TextDocumentSync = new TextDocumentSyncOptions
|
TextDocumentSync = new TextDocumentSyncOptions
|
||||||
{
|
{
|
||||||
|
@ -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