From 3c531b820e23f3e82b4d2e12f1ee87ebe4669f7e Mon Sep 17 00:00:00 2001 From: m0rkeulv Date: Mon, 19 Aug 2024 18:36:52 +0200 Subject: [PATCH] Fixing minor formatting bug & issue with type completion when using Haxe 3.1 extensions annotations in typedefs --- .../ide/formatter/HaxeIndentProcessor.java | 1 - .../plugins/haxe/lang/parser/haxe.bnf | 5 +++-- .../lang/psi/impl/AbstractHaxePsiClass.java | 2 +- .../plugins/haxe/lang/HaxeFormatterTest.java | 4 ++++ .../testData/formatter/IndentTypedef.hx | 21 +++++++++++++++++++ .../testData/formatter/IndentTypedef.txt | 20 ++++++++++++++++++ 6 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 src/test/resources/testData/formatter/IndentTypedef.hx create mode 100644 src/test/resources/testData/formatter/IndentTypedef.txt diff --git a/src/main/java/com/intellij/plugins/haxe/ide/formatter/HaxeIndentProcessor.java b/src/main/java/com/intellij/plugins/haxe/ide/formatter/HaxeIndentProcessor.java index aa4053175..7f865bd44 100644 --- a/src/main/java/com/intellij/plugins/haxe/ide/formatter/HaxeIndentProcessor.java +++ b/src/main/java/com/intellij/plugins/haxe/ide/formatter/HaxeIndentProcessor.java @@ -134,7 +134,6 @@ private static boolean needIndent(@Nullable IElementType type, IElementType elem result = result || type == CLASS_BODY; result = result || type == ABSTRACT_BODY; result = result || (type == ARRAY_LITERAL && elementType != PLBRACK && elementType != PRBRACK); - result = result || type == ANONYMOUS_TYPE_FIELD_LIST || type == TYPE_EXTENDS_LIST; result = result || type == OBJECT_LITERAL; result = result || type == MAP_INITIALIZER_EXPRESSION; result = result || type == MAP_LOOP_INITIALIZER_EXPRESSION; diff --git a/src/main/java/com/intellij/plugins/haxe/lang/parser/haxe.bnf b/src/main/java/com/intellij/plugins/haxe/lang/parser/haxe.bnf index 5c28b48c7..ad2975e70 100644 --- a/src/main/java/com/intellij/plugins/haxe/lang/parser/haxe.bnf +++ b/src/main/java/com/intellij/plugins/haxe/lang/parser/haxe.bnf @@ -982,10 +982,11 @@ anonymousTypeBody ::= anonymousTypeWithEmptyBody | regularAnonymousTypeBody private anonymousTypeWithEmptyBody ::= '{' '}' {pin=2} private regularAnonymousTypeBody ::= '{' anonymousTypeBodyContents '}' {pin=2} private anonymousTypeBodyContents ::= extendedAnonymousTypeBody | simpleAnonymousTypeBody | anonymousInterfaceBodyList -private extendedAnonymousTypeBody ::= typeExtendsList ',' (anonymousTypeFieldList)? (anonymousInterfaceBodyList)? +private extendedAnonymousTypeBody ::= typeExtendsList ',' (anonymousTypeFieldList)? (anonymousInterfaceBodyList)? {pin=1} private anonymousInterfaceBodyList ::= (optionalFieldDeclaration | interfaceBodyPart )+ {recoverWhile="interface_body_part_recover"} private simpleAnonymousTypeBody ::= anonymousTypeFieldList (sep anonymousInterfaceBodyList)? -typeExtendsList ::= '>' type (',' '>' type)* {pin=1} +typeExtendsList ::= '>' type (',' '>' type)* {pin=1 recoverWhile=type_extends_list_recover} +private type_extends_list_recover ::= !(',' | '}' | '>') anonymousTypeFieldList ::= anonymousTypeField (',' anonymousTypeField)* ','? {recoverWhile="object_literal_part_recover" pin=1} private sep ::= ',' | ';' diff --git a/src/main/java/com/intellij/plugins/haxe/lang/psi/impl/AbstractHaxePsiClass.java b/src/main/java/com/intellij/plugins/haxe/lang/psi/impl/AbstractHaxePsiClass.java index 013e87fbf..7b6411622 100644 --- a/src/main/java/com/intellij/plugins/haxe/lang/psi/impl/AbstractHaxePsiClass.java +++ b/src/main/java/com/intellij/plugins/haxe/lang/psi/impl/AbstractHaxePsiClass.java @@ -97,7 +97,7 @@ public String getQualifiedName() { } PsiFile file = getContainingFile(); - if (file == null) return name; + if (file == null) return name == null ? "" : name; final String fileName = FileUtil.getNameWithoutExtension(file.getName()); String packageName = HaxeResolveUtil.getPackageName(file); diff --git a/src/test/java/com/intellij/plugins/haxe/lang/HaxeFormatterTest.java b/src/test/java/com/intellij/plugins/haxe/lang/HaxeFormatterTest.java index 574549d14..a4c963bb5 100644 --- a/src/test/java/com/intellij/plugins/haxe/lang/HaxeFormatterTest.java +++ b/src/test/java/com/intellij/plugins/haxe/lang/HaxeFormatterTest.java @@ -189,6 +189,10 @@ public void testSpaceOthers() throws Exception { myTestStyleSettings.SPACE_AFTER_SEMICOLON = false; doTest(); } + @Test + public void testIndentTypedef() throws Exception { + doTest(); + } @Test public void testWrappingMeth() throws Exception { diff --git a/src/test/resources/testData/formatter/IndentTypedef.hx b/src/test/resources/testData/formatter/IndentTypedef.hx new file mode 100644 index 000000000..5cc2913c0 --- /dev/null +++ b/src/test/resources/testData/formatter/IndentTypedef.hx @@ -0,0 +1,21 @@ +typedef Point2D = { x:Int, y:Int } +typedef Point3D = { + > Point2D, +z:Int +} +typedef FormattingTest = { + var x = 0 ; + var y = 0 ; +var z = 0 ; + +function dummy(point:Point3D) { +x= point.x; + y= point.y; + z = point.z; +} +} + +class MyClass +{ + var point:T = {x:1,y:2}; +} \ No newline at end of file diff --git a/src/test/resources/testData/formatter/IndentTypedef.txt b/src/test/resources/testData/formatter/IndentTypedef.txt new file mode 100644 index 000000000..4241e0403 --- /dev/null +++ b/src/test/resources/testData/formatter/IndentTypedef.txt @@ -0,0 +1,20 @@ +typedef Point2D = {x:Int, y:Int} +typedef Point3D = { + > Point2D, + z:Int +} +typedef FormattingTest = { + var x = 0 ; + var y = 0 ; + var z = 0 ; + + function dummy(point:Point3D) { + x = point.x; + y = point.y; + z = point.z; + } +} + +class MyClass { + var point:T = {x:1, y:2} ; +} \ No newline at end of file