Skip to content

Indentation fix for multi-line call expression #3179

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

Merged
merged 8 commits into from
Jun 24, 2015

Conversation

saschanaz
Copy link
Contributor

(Related to #1888)

I don't know how to name them, but this fixes a remaining indenting problem with array/function/object literals. This problem is not covered by #3001.

Promise
    .resolve()
    .then(() => {
        "";/**/
    });

// A newline inserted at the marker should get 8-space indentation
// while the indenter currently gives it only 4 spaces.

@DanielRosenwasser
Copy link
Member

Hey @saschanaz, thanks for the PR - could you take a look at this as well @vladima?

case SyntaxKind.ArrowFunction:
case SyntaxKind.FunctionExpression:
case SyntaxKind.ArrayLiteralExpression:
case SyntaxKind.ObjectLiteralExpression:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getContainingList already covers all these cases. Perhaps the logic should be moved into there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I'll think about this more.

@saschanaz
Copy link
Contributor Author

I tried some generalization.

@saschanaz saschanaz changed the title Indentation fix for block-form items Indentation fix for multi-line call expression May 16, 2015
}
return Value.Unknown;

function getStartingExpression(expression: CallExpression) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

argument type should really be a union of PropertyAccessExpression | CallExpression | ElementAccessExpression. Now it works by chance because all these types have similarly named property expression.

@vladima
Copy link
Contributor

vladima commented May 23, 2015

@saschanaz Hey, sorry for the delay, thanks for reporting this issue and submitting the fix proposal! The idea of the fix (take actual indentation if expression part of CallExpression is composite and spread across multiple lines) looks like a right direction to go, there are just a few items that should be addressed before the fix should be considered complete - I've left them as comments.

@saschanaz
Copy link
Contributor Author

It seems I need some help to make a decision, as my latest commit breaks consistenceOnIndentionsOfChainedFunctionCalls test.

var ig: ig;
ig.module(
   'mything'
).requires(
   'otherstuff'
).defines(/*0*//*1*/
});

Inserting newline on 1 gives the line an indentation and so this becomes:

var ig: ig;
ig.module(
   'mything'
).requires(
   'otherstuff'
   ).defines(/*0*/ // (indented)
        /*1*/ // Problem: Test expects 4 spaces here but now there are 8.
});

It now gets 8-space indentation because the previous line already have 4 spaces. Should I just fix the test value and move on? Post it as a separate issue? Or should I fix the indentation?

PS: Oh, now there is a post for this. #3436

@saschanaz
Copy link
Contributor Author

Let's just fix the test as there is no other opinion.

@DanielRosenwasser
Copy link
Member

Sorry for the delay @saschanaz, sometimes it's easy for us to lose track. @vladima has been especially busy on certain critical bugs, but I'll see if I can discuss it with him tomorrow.

@mhegazy
Copy link
Contributor

mhegazy commented Jun 5, 2015

@saschanaz sorry for the delay. @vladima is the best one to review this change. he has been heads down on some perf and memory issues and he should be back online early next week. sorry again for the delay.

return Value.Unknown;

function getStartingExpression(expression: PropertyAccessExpression | CallExpression | ElementAccessExpression) {
while (expression.expression)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrap loop body in curlies and add a check that Node.kind is equal to PropertyAccess / ElementAccess / CallExpression

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add tests for that will touch all codepaths

@mhegazy mhegazy merged commit 4d91fff into microsoft:master Jun 24, 2015
@mhegazy
Copy link
Contributor

mhegazy commented Jun 24, 2015

Thanks @saschanaz! and sorry for the long delay. between release-1.5 stabilization and issues, and release-1.6 planning and feature work thing just fell through. hopefully future PRs would not have to wait that long. thanks again.

@vladima
Copy link
Contributor

vladima commented Jun 24, 2015

Thanks @saschanaz !

@saschanaz
Copy link
Contributor Author

Great! Should I PR some more changes as @vladima commented?

@mhegazy
Copy link
Contributor

mhegazy commented Jun 25, 2015

I took care of the comments as I manually merged it.

@saschanaz saschanaz deleted the blockFormParameterIndentation branch August 28, 2015 11:10
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants