Skip to content

Commit

Permalink
fixed indentation of anon function body, fixes #577
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexHaxe committed Apr 12, 2020
1 parent b1a9b15 commit a84c93c
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Fixed broken indentation after case with OpOr pattern, fixes [#576](https://github.com/HaxeCheckstyle/haxe-formatter/issues/576)
- Fixed missing linebreak between metadata and doc comment, fixes [#578](https://github.com/HaxeCheckstyle/haxe-formatter/issues/578)
- Fixed indentation in anon function body, fixes [#577](https://github.com/HaxeCheckstyle/haxe-formatter/issues/577)
- Changed default wrapping location of `casePattern` to `afterLast`, fixes [#579](https://github.com/HaxeCheckstyle/haxe-formatter/issues/579)

## version 1.10.0 (2020-04-11)
Expand Down
14 changes: 10 additions & 4 deletions src/formatter/marker/Indenter.hx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package formatter.marker;

import formatter.config.Config;
import formatter.config.IndentationConfig;
#if debugIndent
import haxe.PosInfos;
import sys.io.File;
import sys.io.FileOutput;
#end
import formatter.config.IndentationConfig;

class Indenter {
var config:IndentationConfig;
var parsedCode:Null<ParsedCode>;

public function new(config:IndentationConfig) {
this.config = config;
public function new(config:Config) {
this.config = fconfig;
if (config.character.toLowerCase() == "tab") {
config.character = "\t";
}
Expand Down Expand Up @@ -311,6 +311,12 @@ class Indenter {
while (firstToken != null && !parsedCode.tokenList.isNewLineBefore(firstToken.token)) {
firstToken = parsedCode.tokenList.getPreviousToken(firstToken.token);
}
var brOpen:Null<TokenTree> = prevToken.access().firstOf(BrOpen).token;
if (brOpen != null) {
if (!parsedCode.tokenList.isSameLineBetween(prevToken, brOpen, false)) {
continue;
}
}
return count + calcIndent(firstToken.token);
}
default:
Expand Down
5 changes: 1 addition & 4 deletions src/formatter/marker/MarkTokenText.hx
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package formatter.marker;

import haxe.zip.Entry;
import haxeparser.HaxeLexer;
import tokentree.TokenStream;
import tokentree.TokenStreamProgress;
import tokentree.walk.WalkStatement;
import tokentree.TokenStream;
import formatter.codedata.CodeLines;
import formatter.codedata.FormatterInputData;
import formatter.codedata.ParseFile;
import formatter.codedata.ParsedCode;
import formatter.codedata.TokenData;

class MarkTokenText extends MarkerBase {
public function run() {
Expand Down
32 changes: 32 additions & 0 deletions test/testcases/indentation/issue_577_anon_function_body.hxtest
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{}

---

class PlayState extends FlxState
{
function createAttachmentControls():Void
{
add(attachmentDropDown = new FlxUIDropDownMenu(modelDropDownLoc.x, modelDropDownLoc.y - 30,
FlxUIDropDownMenu.makeStrIdLabelArray(FlxGamepadAttachment.getConstructors()), function(attachment)
{
var gamepad = FlxG.gamepads.lastActive;
if (gamepad != null)
gamepad.attachment = FlxGamepadAttachment.createByName(attachment);
updateConnectedGamepads(true);
}, new FlxUIDropDownHeader(150)));
}
}

---

class PlayState extends FlxState {
function createAttachmentControls():Void {
add(attachmentDropDown = new FlxUIDropDownMenu(modelDropDownLoc.x, modelDropDownLoc.y - 30,
FlxUIDropDownMenu.makeStrIdLabelArray(FlxGamepadAttachment.getConstructors()), function(attachment) {
var gamepad = FlxG.gamepads.lastActive;
if (gamepad != null)
gamepad.attachment = FlxGamepadAttachment.createByName(attachment);
updateConnectedGamepads(true);
}, new FlxUIDropDownHeader(150)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"lineEnds": {
"leftCurly": "both"
}
}

---

class PlayState extends FlxState
{
function createAttachmentControls():Void
{
add(attachmentDropDown = new FlxUIDropDownMenu(modelDropDownLoc.x, modelDropDownLoc.y - 30,
FlxUIDropDownMenu.makeStrIdLabelArray(FlxGamepadAttachment.getConstructors()), function(attachment)
{
var gamepad = FlxG.gamepads.lastActive;
if (gamepad != null)
gamepad.attachment = FlxGamepadAttachment.createByName(attachment);
updateConnectedGamepads(true);
}, new FlxUIDropDownHeader(150)));
}
}

---

class PlayState extends FlxState
{
function createAttachmentControls():Void
{
add(attachmentDropDown = new FlxUIDropDownMenu(modelDropDownLoc.x, modelDropDownLoc.y - 30,
FlxUIDropDownMenu.makeStrIdLabelArray(FlxGamepadAttachment.getConstructors()), function(attachment)
{
var gamepad = FlxG.gamepads.lastActive;
if (gamepad != null)
gamepad.attachment = FlxGamepadAttachment.createByName(attachment);
updateConnectedGamepads(true);
}, new FlxUIDropDownHeader(150)));
}
}

0 comments on commit a84c93c

Please sign in to comment.