Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Haxe][CodeComplete] Added completion for 'using haxe.EnumTools'. fixes #2759 #2760

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions External/Plugins/HaXeContext/Completion/CodeComplete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1319,7 +1319,16 @@ protected override void GetInstanceMembers(bool autoHide, ASResult expr, ClassMo
return;
}
}
Context.TryResolveStaticExtensions(exprType, ASContext.Context.CurrentModel, out exprType);
if (expr.IsStatic && (exprType.Flags & FlagType.Enum) != 0 && (exprType.Flags & FlagType.Abstract) == 0)
{
var type = ResolveType("Enum", null);
if (Context.TryResolveStaticExtensions(type, ASContext.Context.CurrentModel, out var tmp))
{
foreach (MemberModel it in tmp.Members) it.Flags |= FlagType.Static;
exprType.Members.Merge(tmp.Members);
}
}
else Context.TryResolveStaticExtensions(exprType, ASContext.Context.CurrentModel, out exprType);
base.GetInstanceMembers(autoHide, expr, exprType, mask, dotIndex, result);
}

Expand Down Expand Up @@ -1518,7 +1527,27 @@ protected override void FindMemberEx(string token, ClassModel inClass, ASResult
*/
if (result.IsNull() && !string.IsNullOrEmpty(result.Path) && result.RelClass != null && !result.RelClass.IsVoid())
{
if (Context.TryResolveStaticExtensions(inClass, ASContext.Context.CurrentModel, out inClass))
var hasStaticExtensions = false;

/**
* for example:
* EnumType.createAll(<complete>
*/
// if (result.IsStatic
// && inClass.Flags.HasFlag(FlagType.Enum)
// && !inClass.Flags.HasFlag(FlagType.Abstract))
// {
// var type = ResolveType("Enum", null);
// if (Context.TryResolveStaticExtensions(type, ASContext.Context.CurrentModel, out var tmp))
// {
// foreach (MemberModel it in tmp.Members) it.Flags |= FlagType.Static;
// inClass.Members.Merge(tmp.Members);
// hasStaticExtensions = true;
// }
// }
// else
hasStaticExtensions = Context.TryResolveStaticExtensions(inClass, ASContext.Context.CurrentModel, out inClass);
if (hasStaticExtensions)
{
base.FindMemberEx(token, inClass, result, mask, access);
if (result.Member != null && result.Member.Flags.HasFlag(FlagType.Using))
Expand Down
52 changes: 44 additions & 8 deletions External/Plugins/HaXeContext/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1503,12 +1503,32 @@ 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);
/**
* for example:
* ```
* enum EEnum {}
* ...
* EEnum.<complete>
* ```
*/
if ((type.Flags & FlagType.Class) != 0 && type.Name == "Enum")
{
var @using = ResolveUsing("haxe.EnumTools", null);
if (!@using.IsVoid()) imports.Add(@using);
}
/**
* for example:
* ```
* enum EEnum {}
* ...
* var e:EEnum;
* e.<complete>
* ```
*/
else if ((type.Flags & FlagType.Enum) != 0 && (type.Flags & FlagType.Abstract) == 0)
{
var @using = ResolveUsing("haxe.EnumTools.EnumValueTools", null);
if (!@using.IsVoid()) imports.Add(@using);
}
if (imports.Count == 0) return false;
var extensions = new MemberList();
Expand Down Expand Up @@ -1573,10 +1593,18 @@ bool CanBeExtended(ClassModel target, MemberModel extension, Visibility access)
break;
}
}
if ((target.Flags & (FlagType.Abstract | FlagType.Class)) == (FlagType.Abstract | FlagType.Class)
&& target.Name == "Enum" && target.Type == "Enum")
{
// for example: Enum.<complete>
return firstParamType.StartsWithOrdinal("Enum<");
}
if ((target.Flags & FlagType.Enum) != 0 && (target.Flags & FlagType.Abstract) == 0 && firstParamType == "EnumValue")
{
// for example: EnumValue.<complete>
return true;
}
else if (firstParamType != "Dynamic" && !firstParamType.StartsWithOrdinal("Dynamic<"))
if (firstParamType != "Dynamic" && !firstParamType.StartsWithOrdinal("Dynamic<"))
{
var targetType = type.Type;
var index = targetType.IndexOf('<');
Expand Down Expand Up @@ -1623,6 +1651,14 @@ bool CanBeExtended(ClassModel target, MemberModel extension, Visibility access)
}
return true;
}
ClassModel ResolveUsing(string name, FileModel file)
{
var @using = Context.ResolveType(name, file);
if (@using.IsVoid()) return ClassModel.VoidClass;
@using = (ClassModel) @using.Clone();
@using.Flags |= FlagType.Using;
return @using;
}
}

public override string GetDefaultValue(string type)
Expand Down Expand Up @@ -1746,7 +1782,7 @@ public override IEnumerable<string> DecomposeTypes(IEnumerable<string> types)
/// <summary>
/// Checks completion mode changes to start/restart/stop the haXe completion server if needed.
/// </summary>
private void OnCompletionModeChange()
void OnCompletionModeChange()
{
if (completionModeHandler != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,18 @@ static IEnumerable<TestCaseData> OnCharAndReplaceTextIssue2757TestCases
}
}

static IEnumerable<TestCaseData> OnCharAndReplaceTextIssue2759TestCases
{
get
{
yield return new TestCaseData("BeforeOnCharAndReplaceText_issue2759_1", '.', false)
.Returns(CodeCompleteTests.ReadAllText("AfterOnCharAndReplaceText_issue2759_1"))
.SetName("ConcreteEnum.<complete> Issue 2759. Case 1")
.SetDescription("https://github.com/fdorg/flashdevelop/issues/2759");

}
}

[
Test,
TestCaseSource(nameof(OnCharAndReplaceTextTestCases)),
Expand All @@ -1263,6 +1275,7 @@ static IEnumerable<TestCaseData> OnCharAndReplaceTextIssue2757TestCases
TestCaseSource(nameof(OnCharAndReplaceTextIssue2726TestCases)),
TestCaseSource(nameof(OnCharAndReplaceTextIssue2750TestCases)),
TestCaseSource(nameof(OnCharAndReplaceTextIssue2757TestCases)),
TestCaseSource(nameof(OnCharAndReplaceTextIssue2759TestCases)),
]
public string OnCharAndReplaceText(string fileName, char addedChar, bool autoHide)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1275,6 +1275,8 @@
<EmbeddedResource Include="Test Files\coderefactor\rename\BeforeRename_issue2764_1.hx" />
<EmbeddedResource Include="Test Files\coderefactor\rename\BeforeRename_issue2764_1_withoutEntryPoint.hx" />
<EmbeddedResource Include="Test Files\coderefactor\rename\AfterRename_issue2764_1.hx" />
<EmbeddedResource Include="Test Files\completion\BeforeOnCharAndReplaceText_issue2759_1.hx" />
<EmbeddedResource Include="Test Files\completion\AfterOnCharAndReplaceText_issue2759_1.hx" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package;
class Bar {
static function main() {
EType.EnumInstance
EType.AEnumInstance
}
}

enum EType {
EnumInstance;
AEnumInstance;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package;
using haxe.EnumTools;
private enum PIssue2759 {}
class Issue2759_1 {
function foo() {
PIssue2759.createAll
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ class Bar {
}

enum EType {
EnumInstance;
AEnumInstance;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package;
using haxe.EnumTools;
private enum PIssue2759 {}
class Issue2759_1 {
function foo() {
PIssue2759.$(EntryPoint)
}
}