From 43a44e8f3133f9c169c969f0aaf02c4099a0394b Mon Sep 17 00:00:00 2001 From: Philippe Elsass Date: Mon, 28 Mar 2016 23:38:29 +0100 Subject: [PATCH] Improving function generator --- External/Plugins/AS3Context/Context.cs | 3 +- .../ASCompletion/Completion/ASGenerator.cs | 53 ++++++++++--------- .../Completion/ContextFeatures.cs | 1 + External/Plugins/HaXeContext/Context.cs | 1 + 4 files changed, 31 insertions(+), 27 deletions(-) diff --git a/External/Plugins/AS3Context/Context.cs b/External/Plugins/AS3Context/Context.cs index 0535613767..ad9f4e9e99 100644 --- a/External/Plugins/AS3Context/Context.cs +++ b/External/Plugins/AS3Context/Context.cs @@ -99,7 +99,8 @@ public Context(AS3Settings initSettings) features.dot = "."; features.voidKey = "void"; features.objectKey = "Object"; - features.booleanKey = "Boolean"; + features.booleanKey = "Boolean"; + features.intKey = "Int"; features.numberKey = "Number"; features.stringKey = "String"; features.arrayKey = "Array"; diff --git a/External/Plugins/ASCompletion/Completion/ASGenerator.cs b/External/Plugins/ASCompletion/Completion/ASGenerator.cs index c31fe1b4a3..424635756f 100644 --- a/External/Plugins/ASCompletion/Completion/ASGenerator.cs +++ b/External/Plugins/ASCompletion/Completion/ASGenerator.cs @@ -2443,7 +2443,7 @@ private static List ParseFunctionParameters(ScintillaControl writeParam = false; string trimmed = sb.ToString().Trim(charsToTrim); if (trimmed.Length > 0) - { + { result = ASComplete.GetExpressionType(sci, lastMemberPos + 1); if (result != null && !result.IsNull()) { @@ -2458,32 +2458,37 @@ private static List ParseFunctionParameters(ScintillaControl } else { - double d = double.MaxValue; - try - { - d = double.Parse(trimmed, CultureInfo.InvariantCulture); - } - catch (Exception) - { - } - if (d != double.MaxValue && d.ToString().Length == trimmed.Length) - { - result = new ASResult(); - result.Type = ctx.ResolveType(ctx.Features.numberKey, null); - types.Insert(0, result); - } - else if (trimmed.Equals("true") || trimmed.Equals("false")) + if (trimmed.Equals("true") || trimmed.Equals("false")) { - result = new ASResult(); + result = new ASResult(); result.Type = ctx.ResolveType(ctx.Features.booleanKey, null); types.Insert(0, result); + } + else if (trimmed[0] == '-' || char.IsDigit(trimmed[0])) + { + try + { + double d = double.Parse(trimmed, CultureInfo.InvariantCulture); + result = new ASResult(); + if (Math.Floor(d) == d && d.ToString() == trimmed && !string.IsNullOrEmpty(ctx.Features.intKey)) + result.Type = ctx.ResolveType(ctx.Features.intKey, null); + else + result.Type = ctx.ResolveType(ctx.Features.numberKey, null); + types.Insert(0, result); + } + catch (Exception) + { + } } } if (types.Count == 0) { - result = new ASResult(); - result.Type = ctx.ResolveType(ctx.Features.objectKey, null); + result = new ASResult(); + Match m = Regex.Match(trimmed, "(^|\\.)([a-z0-9_$]+)$"); + if (m.Success) result.Member = new MemberModel { Name = m.Groups[2].Value }; + if (IsHaxe) result.Type = ClassModel.VoidClass; + else result.Type = ctx.ResolveType(ctx.Features.objectKey, null); types.Add(result); } @@ -2529,13 +2534,9 @@ private static List ParseFunctionParameters(ScintillaControl } for (int i = 0; i < prms.Count; i++) - { - if (prms[i].paramType == "void") - { - prms[i].paramName = "object"; - prms[i].paramType = null; - } - else prms[i].paramName = GuessVarName(prms[i].paramName, FormatType(GetShortType(prms[i].paramType))); + { + if (string.IsNullOrEmpty(prms[i].paramName)) prms[i].paramName = "param"; + if (prms[i].paramType == "void") prms[i].paramType = null; } for (int i = 0; i < prms.Count; i++) diff --git a/External/Plugins/ASCompletion/Completion/ContextFeatures.cs b/External/Plugins/ASCompletion/Completion/ContextFeatures.cs index 979e835ed3..8637198d6c 100644 --- a/External/Plugins/ASCompletion/Completion/ContextFeatures.cs +++ b/External/Plugins/ASCompletion/Completion/ContextFeatures.cs @@ -71,6 +71,7 @@ public class ContextFeatures public string voidKey; public string objectKey; public string booleanKey; + public string intKey; public string numberKey; public string stringKey; public string arrayKey; diff --git a/External/Plugins/HaXeContext/Context.cs b/External/Plugins/HaXeContext/Context.cs index b477611fc8..9cd87b512c 100644 --- a/External/Plugins/HaXeContext/Context.cs +++ b/External/Plugins/HaXeContext/Context.cs @@ -114,6 +114,7 @@ public Context(HaXeSettings initSettings) features.voidKey = "Void"; features.objectKey = "Dynamic"; features.booleanKey = "Bool"; + features.intKey = "Int"; features.numberKey = "Float"; features.stringKey = "String"; features.arrayKey = "Array";