Keep original indentation for converted preprocessor directives

Description

See this comment from for details:
https://swiftify.atlassian.net/browse/SWC-340?focusedCommentId=36821

✔️1. For nested directives, can we either
a) Keep the original indentation, or
b) re-indent nested blocks
... so that the result looks similar to the original Objective-C code?

✔️2. Indent code inside successfully converted availability directives (implemented via postprocessor in ).

Environment

None

Activity

Show:
Dmitry Rassadin
August 11, 2020, 7:25 PM
Edited

1.

a) It seems to be possible only if indentations are kept during conversion. If they were set immediately there, it would affect main indents or break SwiftPostProcessor methods where these directives are considered as starters in respective lines(perhaps it might be changed).

b) There are so many directives, I’m no sure it would be possible for all nested cases.

2.

I implemented plain indentations for the non-nested availability directives in the Feature/IndentConvertedDirectives branch.

Converted fragment from GCHTTPRequestOperation.m

If you consider such approach as appropriate, I’ll continue(and merge it into the AvailabilitySupportbranch or stay as a completely separate task).

Alex Petuschak
August 12, 2020, 3:39 PM
Edited

1. Just made this test, and the result looks awesome.

Nested directives are supported.

Add a unit test and we’re done here.

2. This looks awesome to me.

Please add unit test(s) for your sample case(s) and I guess we are done with this part.

3. With the sample.m file that you provided, I see extra indents in the code:

https://take.ms/6M6y9

See if you can fix this.

I guess that’s because some code blocks are repeatedly indented.

That’s the difference between Indent(context, level) and IndentBy(level).

Dmitry Rassadin
August 12, 2020, 4:43 PM

Thanks, yes I indented branches' lines inaccurately and manually instead of just using `IndentBy`. I’ll refactor it.

Assignee

Dmitry Rassadin

Reporter

Alex Petuschak

Labels

None

Git Branch Name

None

GitHub Issue

None

Components

Fix versions

Priority

Medium
Configure