From 2938a8f311be2cdf7578fa60981e635a53c08d24 Mon Sep 17 00:00:00 2001 From: "r.miklashevski" Date: Mon, 27 Jan 2020 18:10:51 +0300 Subject: [PATCH 1/4] support haxe `final` keyword, resolves #2775 and partially #1925 (does not support `final` as method modifier) --- External/Plugins/HaXeContext/Context.cs | 5 +++-- External/Plugins/HaXeContext/Model/FileParser.cs | 2 +- FlashDevelop/Bin/Debug/Settings/Languages/Haxe.xml | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/External/Plugins/HaXeContext/Context.cs b/External/Plugins/HaXeContext/Context.cs index ea5ef16b00..238dd53729 100644 --- a/External/Plugins/HaXeContext/Context.cs +++ b/External/Plugins/HaXeContext/Context.cs @@ -170,6 +170,7 @@ public Context(HaXeSettings initSettings, Func getCustomSD features.importKey = "import"; features.importKeyAlt = "using"; features.varKey = "var"; + //features.finalKey = "final"; features.overrideKey = "override"; features.functionKey = "function"; features.staticKey = "static"; @@ -184,11 +185,11 @@ public Context(HaXeSettings initSettings, Func getCustomSD features.ConstructorKey = "new"; features.typesPreKeys = new[] {features.importKey, features.importKeyAlt, features.ConstructorKey, features.ExtendsKey, features.ImplementsKey}; features.codeKeywords = new[] { - "var", "function", "new", "cast", "return", "break", + "var", "final", "function", "new", "cast", "return", "break", "continue", "if", "else", "for", "in", "while", "do", "switch", "case", "default", "$type", "null", "untyped", "true", "false", "try", "catch", "throw", "trace", "macro" }; - features.declKeywords = new[] {features.varKey, features.functionKey}; + features.declKeywords = new[] {features.varKey, features.functionKey, features.finalKey}; features.accessKeywords = new[] {features.intrinsicKey, features.inlineKey, "dynamic", "macro", features.overrideKey, features.publicKey, features.privateKey, features.staticKey}; features.typesKeywords = new[] {features.importKey, features.importKeyAlt, "class", "interface", "typedef", "enum", "abstract" }; features.ArithmeticOperators = new HashSet {'+', '-', '*', '/', '%'}; diff --git a/External/Plugins/HaXeContext/Model/FileParser.cs b/External/Plugins/HaXeContext/Model/FileParser.cs index d1dc9b3be1..e69af4337c 100644 --- a/External/Plugins/HaXeContext/Model/FileParser.cs +++ b/External/Plugins/HaXeContext/Model/FileParser.cs @@ -1678,7 +1678,7 @@ bool EvalToken(bool evalContext, bool evalKeyword) if (dotIndex > 0) token = token.Substring(dotIndex + 1); // members - if (token == "var") + if (token == "var" || token == "final") { foundKeyword = FlagType.Variable; } diff --git a/FlashDevelop/Bin/Debug/Settings/Languages/Haxe.xml b/FlashDevelop/Bin/Debug/Settings/Languages/Haxe.xml index 3223b40840..058b421e74 100644 --- a/FlashDevelop/Bin/Debug/Settings/Languages/Haxe.xml +++ b/FlashDevelop/Bin/Debug/Settings/Languages/Haxe.xml @@ -3,7 +3,7 @@ abstract break case catch class continue default do else enum extends for in function if implements import - interface new package return switch throw try typedef using var while $type + interface new package return switch throw try typedef using var final while $type null true false From e2f68b2fb811bb439ef549812c31116aa405415b Mon Sep 17 00:00:00 2001 From: romamik Date: Mon, 27 Jan 2020 18:32:06 +0300 Subject: [PATCH 2/4] Update Context.cs --- External/Plugins/HaXeContext/Context.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/External/Plugins/HaXeContext/Context.cs b/External/Plugins/HaXeContext/Context.cs index 238dd53729..5ebd226987 100644 --- a/External/Plugins/HaXeContext/Context.cs +++ b/External/Plugins/HaXeContext/Context.cs @@ -170,7 +170,7 @@ public Context(HaXeSettings initSettings, Func getCustomSD features.importKey = "import"; features.importKeyAlt = "using"; features.varKey = "var"; - //features.finalKey = "final"; + features.finalKey = "final"; features.overrideKey = "override"; features.functionKey = "function"; features.staticKey = "static"; @@ -2634,4 +2634,4 @@ public HaxeCompletionCache(IASContext context, MemberList elements, MemberList o OtherElements = otherElements; } } -} \ No newline at end of file +} From 3dde45bfb5a7b7164bfedf3e06fe15d2bb451d86 Mon Sep 17 00:00:00 2001 From: "r.miklashevski" Date: Fri, 31 Jan 2020 13:16:50 +0300 Subject: [PATCH 3/4] show `final` in completion only for haxe >= 4 --- External/Plugins/HaXeContext/Context.cs | 32 +++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/External/Plugins/HaXeContext/Context.cs b/External/Plugins/HaXeContext/Context.cs index 5ebd226987..b5ae84ca87 100644 --- a/External/Plugins/HaXeContext/Context.cs +++ b/External/Plugins/HaXeContext/Context.cs @@ -170,7 +170,6 @@ public Context(HaXeSettings initSettings, Func getCustomSD features.importKey = "import"; features.importKeyAlt = "using"; features.varKey = "var"; - features.finalKey = "final"; features.overrideKey = "override"; features.functionKey = "function"; features.staticKey = "static"; @@ -185,11 +184,11 @@ public Context(HaXeSettings initSettings, Func getCustomSD features.ConstructorKey = "new"; features.typesPreKeys = new[] {features.importKey, features.importKeyAlt, features.ConstructorKey, features.ExtendsKey, features.ImplementsKey}; features.codeKeywords = new[] { - "var", "final", "function", "new", "cast", "return", "break", + "var", "function", "new", "cast", "return", "break", "continue", "if", "else", "for", "in", "while", "do", "switch", "case", "default", "$type", "null", "untyped", "true", "false", "try", "catch", "throw", "trace", "macro" }; - features.declKeywords = new[] {features.varKey, features.functionKey, features.finalKey}; + features.declKeywords = new[] {features.varKey, features.functionKey}; features.accessKeywords = new[] {features.intrinsicKey, features.inlineKey, "dynamic", "macro", features.overrideKey, features.publicKey, features.privateKey, features.staticKey}; features.typesKeywords = new[] {features.importKey, features.importKeyAlt, "class", "interface", "typedef", "enum", "abstract" }; features.ArithmeticOperators = new HashSet {'+', '-', '*', '/', '%'}; @@ -379,10 +378,35 @@ public void SetHaxeEnvironment(string sdkPath) LoadMetadata(); - features.SpecialPostfixOperators = GetCurrentSDKVersion() >= "3.3.0" + var version = GetCurrentSDKVersion(); + + features.SpecialPostfixOperators = version >= "3.3.0" ? new[] {'!'} : Array.Empty(); + if(version >= "4") + { + features.finalKey = "final"; + + if (Array.IndexOf(features.codeKeywords, "final") < 0) + { + Array.Resize(ref features.codeKeywords, features.codeKeywords.Length + 1); + features.codeKeywords[features.codeKeywords.Length - 1] = "final"; + } + + if (Array.IndexOf(features.declKeywords, "final") < 0) + { + Array.Resize(ref features.declKeywords, features.declKeywords.Length + 1); + features.declKeywords[features.declKeywords.Length - 1] = "final"; + } + } + else + { + features.finalKey = null; + features.codeKeywords = features.codeKeywords.Where(w => w != "final").ToArray(); + features.declKeywords = features.declKeywords.Where(w => w != "final").ToArray(); + } + UseGenericsShortNotationChange(); } From f2834db7445e0642c968b42080e2797d57c3f3c4 Mon Sep 17 00:00:00 2001 From: "r.miklashevski" Date: Fri, 31 Jan 2020 13:55:09 +0300 Subject: [PATCH 4/4] code style fix --- External/Plugins/HaXeContext/Context.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/External/Plugins/HaXeContext/Context.cs b/External/Plugins/HaXeContext/Context.cs index b5ae84ca87..74d99c0a5c 100644 --- a/External/Plugins/HaXeContext/Context.cs +++ b/External/Plugins/HaXeContext/Context.cs @@ -384,7 +384,7 @@ public void SetHaxeEnvironment(string sdkPath) ? new[] {'!'} : Array.Empty(); - if(version >= "4") + if (version >= "4") { features.finalKey = "final";