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.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
@ -68,40 +69,44 @@ 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 parameters = new List<UserDataBoundFunctionParameter>();
|
||||
if (value.GetValue("Parameters", StringComparison.InvariantCultureIgnoreCase) is JObject parameterJson)
|
||||
var options = value.GetValue("options", StringComparison.InvariantCultureIgnoreCase);
|
||||
var listOptions = new List<UserDataBoundMethodOption>();
|
||||
foreach (var jToken in options)
|
||||
{
|
||||
var properties = parameterJson.Properties();
|
||||
foreach (var property in properties)
|
||||
if (!(jToken is JObject option)) continue;
|
||||
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 parameterValue = (JObject) property.Value;
|
||||
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()
|
||||
var properties = parameterJson.Properties();
|
||||
foreach (var property in properties)
|
||||
{
|
||||
Name = parameterName,
|
||||
Type = ParseType(parType),
|
||||
Comment = parComment,
|
||||
IsOptional = isOptional.HasValue && isOptional.Value,
|
||||
ActualType = parType
|
||||
});
|
||||
var parameterName = property.Name;
|
||||
var parameterValue = (JObject) property.Value;
|
||||
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,
|
||||
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,
|
||||
ActualType = type,
|
||||
Comment = comment,
|
||||
Type = ParseType(type),
|
||||
ResultType = ParseType(returnType),
|
||||
Parameters = parameters.ToArray()
|
||||
Type = ParseType(t)
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -134,28 +139,34 @@ namespace UpsilonLanguageServer
|
|||
}
|
||||
else if (type == Type.Function)
|
||||
{
|
||||
var returnType = obj.GetValue("returns", StringComparison.InvariantCultureIgnoreCase).ToString().ToLowerInvariant();
|
||||
var parameters = new List<InternalFunctionVariableSymbol.InternalFunctionParameter>();
|
||||
if (obj.GetValue("Parameters", StringComparison.InvariantCultureIgnoreCase) is JObject parameterJson)
|
||||
var options = obj.GetValue("options", StringComparison.InvariantCultureIgnoreCase).Children();
|
||||
var listOptions = new List<FunctionVariableSymbolOption>();
|
||||
foreach (var jToken in options)
|
||||
{
|
||||
var properties = parameterJson.Properties();
|
||||
foreach (var prop in properties)
|
||||
if (!(jToken is JObject option)) continue;
|
||||
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 parName = parameterValue.GetValue("name", StringComparison.InvariantCultureIgnoreCase)
|
||||
?.ToString();
|
||||
var parType = parameterValue.GetValue("type", StringComparison.InvariantCultureIgnoreCase)
|
||||
?.ToString();
|
||||
var parsedType = ParseType(parType);
|
||||
var isOptional = parameterValue.GetValue("IsOptional", StringComparison.InvariantCultureIgnoreCase)
|
||||
?.ToObject<bool>();
|
||||
parameters.Add(new InternalFunctionVariableSymbol.InternalFunctionParameter(parName, parsedType,
|
||||
isOptional.HasValue && isOptional.Value));
|
||||
var properties = parameterJson.Properties();
|
||||
foreach (var prop in properties)
|
||||
{
|
||||
var parameterValue = (JObject) prop.Value;
|
||||
var parName = parameterValue.GetValue("name", StringComparison.InvariantCultureIgnoreCase)
|
||||
?.ToString();
|
||||
var parType = parameterValue.GetValue("type", StringComparison.InvariantCultureIgnoreCase)
|
||||
?.ToString();
|
||||
var parsedType = ParseType(parType);
|
||||
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,
|
||||
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;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using JsonRpc.Standard;
|
||||
|
@ -16,28 +17,37 @@ namespace UpsilonLanguageServer.Services
|
|||
public InitializeResult Initialize(int processId, Uri rootUri, ClientCapabilities capabilities,
|
||||
JToken initializationOptions = null, string trace = null)
|
||||
{
|
||||
WorkspaceService.RootUri = rootUri?.AbsolutePath;
|
||||
if (rootUri != null)
|
||||
try
|
||||
{
|
||||
var configPath = rootUri.AbsolutePath + "/.upsilon";
|
||||
var typesConfigFile = configPath + "/types.json";
|
||||
if (File.Exists(typesConfigFile))
|
||||
WorkspaceService.RootUri = rootUri?.AbsolutePath;
|
||||
if (rootUri != null)
|
||||
{
|
||||
BoundTypeParser.LoadBoundTypes(File.ReadAllText(typesConfigFile));
|
||||
}
|
||||
var staticConfigFile = configPath + "/static.json";
|
||||
if (File.Exists(staticConfigFile))
|
||||
{
|
||||
BoundTypeParser.LoadStaticVariables(File.ReadAllText(staticConfigFile));
|
||||
}
|
||||
var configPath = rootUri.AbsolutePath + "/.upsilon";
|
||||
var typesConfigFile = configPath + "/types.json";
|
||||
if (File.Exists(typesConfigFile))
|
||||
{
|
||||
BoundTypeParser.LoadBoundTypes(File.ReadAllText(typesConfigFile));
|
||||
}
|
||||
|
||||
Session.Settings.ModuleDirectory =
|
||||
new DirectoryInfo(Path.Combine(rootUri.AbsolutePath, Session.Settings.ModuleDirectory)).FullName;
|
||||
var staticConfigFile = configPath + "/static.json";
|
||||
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
|
||||
{
|
||||
HoverProvider = true,
|
||||
SignatureHelpProvider = new SignatureHelpOptions( new[]{'(', ','}),
|
||||
SignatureHelpProvider = new SignatureHelpOptions(new[] {'(', ','}),
|
||||
CompletionProvider = new CompletionOptions(true, "."),
|
||||
TextDocumentSync = new TextDocumentSyncOptions
|
||||
{
|
||||
|
@ -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)]
|
||||
|
|
|
@ -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 = "";
|
||||
|
|
Loading…
Reference in New Issue