Skip to content

Commit

Permalink
[Haxe][CodeComplete] Added completion for 'EnumValue'. fixes fdorg#2757
Browse files Browse the repository at this point in the history
  • Loading branch information
SlavaRa authored Apr 15, 2019
1 parent 307b713 commit d69e630
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 4 deletions.
35 changes: 31 additions & 4 deletions External/Plugins/HaXeContext/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ public override FileModel GetCodeModel(FileModel result, string src, bool script
{
result.haXe = true;
base.GetCodeModel(result, src, scriptMode);
if (result.Members != null)
// members
{
for (var i = 0; i < result.Members.Count; i++)
{
Expand All @@ -726,9 +726,9 @@ public override FileModel GetCodeModel(FileModel result, string src, bool script
}
}
}
if (result.Classes != null)
// classes
{
for (int i = 0, length = result.Classes.Count; i < length; i++)
for (var i = 0; i < result.Classes.Count; i++)
{
var @class = result.Classes[i];
var flags = @class.Flags;
Expand Down Expand Up @@ -758,6 +758,7 @@ public override FileModel GetCodeModel(FileModel result, string src, bool script
}
}
}
else if ((flags & FlagType.Enum) != 0) @class.ExtendsType = "EnumValue";
else if (flags == FlagType.Class && @class.Members.Count > 0)
{
/**
Expand Down Expand Up @@ -1502,6 +1503,13 @@ internal static bool TryResolveStaticExtensions(ClassModel type, FileModel inFil
{
result = type;
var imports = Context.ResolveImports(inFile);
if ((type.Flags & FlagType.Enum) != 0 && (type.Flags & FlagType.Abstract) == 0
&& Context.ResolveType("haxe.EnumTools.EnumValueTools", null) is ClassModel @using && !@using.IsVoid())
{
@using = (ClassModel)@using.Clone();
@using.Flags |= FlagType.Using;
imports.Add(@using);
}
if (imports.Count == 0) return false;
var extensions = new MemberList();
for (var i = imports.Count - 1; i >= 0; i--)
Expand Down Expand Up @@ -1549,7 +1557,26 @@ bool CanBeExtended(ClassModel target, MemberModel extension, Visibility access)
{
var firstParamType = extension.Parameters[0].Type;
if (string.IsNullOrEmpty(firstParamType)) return false;
if (firstParamType != "Dynamic" && !firstParamType.StartsWithOrdinal("Dynamic<"))
if (!string.IsNullOrEmpty(extension.Template) && Context.ResolveType(firstParamType, null).IsVoid())
{
// transform methodName<T:ConcreteType>(a:T, b) to methodName<T:ConcreteType>(a:ConcreteType, b)
var template = extension.Template.Substring(1, extension.Template.Length - 2);
var parts = Context is Context ctx && ctx.GetCurrentSDKVersion() >= "4.0.0"
? template.Split(new[] {'&'}, StringSplitOptions.RemoveEmptyEntries)
: template.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries);
foreach (var part in parts)
{
if (!part.Contains(':')) continue;
var templateToType = part.Split(new[] {':'}, StringSplitOptions.RemoveEmptyEntries);
if (templateToType[0] != firstParamType) continue;
if (templateToType.Length == 2) firstParamType = templateToType[1];
break;
}
}
if ((target.Flags & FlagType.Enum) != 0 && (target.Flags & FlagType.Abstract) == 0 && firstParamType == "EnumValue")
{
}
else if (firstParamType != "Dynamic" && !firstParamType.StartsWithOrdinal("Dynamic<"))
{
var targetType = type.Type;
var index = targetType.IndexOf('<');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,18 @@ static IEnumerable<TestCaseData> OnCharAndReplaceTextIssue2750TestCases
}
}

static IEnumerable<TestCaseData> OnCharAndReplaceTextIssue2757TestCases
{
get
{
yield return new TestCaseData("BeforeOnCharAndReplaceText_issue2757_1", '.', false)
.Returns(CodeCompleteTests.ReadAllText("AfterOnCharAndReplaceText_issue2757_1"))
.SetName("enumValue.<complete> Issue 2757. Case 1")
.SetDescription("https://github.com/fdorg/flashdevelop/issues/2757");

}
}

[
Test,
TestCaseSource(nameof(OnCharAndReplaceTextTestCases)),
Expand All @@ -1250,6 +1262,7 @@ static IEnumerable<TestCaseData> OnCharAndReplaceTextIssue2750TestCases
TestCaseSource(nameof(OnCharAndReplaceTextIssue2577TestCases)),
TestCaseSource(nameof(OnCharAndReplaceTextIssue2726TestCases)),
TestCaseSource(nameof(OnCharAndReplaceTextIssue2750TestCases)),
TestCaseSource(nameof(OnCharAndReplaceTextIssue2757TestCases)),
]
public string OnCharAndReplaceText(string fileName, char addedChar, bool autoHide)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1270,6 +1270,8 @@
<EmbeddedResource Include="Test Files\parser\TypeDefsTest.hx" />
<EmbeddedResource Include="Test Files\parser\WrongSyntaxCompilerMetaAfterMethodWithNoType.hx" />
<EmbeddedResource Include="Test Files\parser\WrongSyntaxCompilerMetaAfterVarWithNoType.hx" />
<EmbeddedResource Include="Test Files\completion\BeforeOnCharAndReplaceText_issue2757_1.hx" />
<EmbeddedResource Include="Test Files\completion\AfterOnCharAndReplaceText_issue2757_1.hx" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package;
class Issue2757_1 {
function foo() {
var e:PIssue2757;
e.equals
}
}

private enum PIssue2757 {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package;
class Issue2757_1 {
function foo() {
var e:PIssue2757;
e.$(EntryPoint)
}
}

private enum PIssue2757 {}

0 comments on commit d69e630

Please sign in to comment.