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

Add API to infer the indentation of a syntax tree #2514

Merged
merged 1 commit into from
Feb 28, 2024

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Feb 27, 2024

Part of rdar://123600798

@ahoppen ahoppen requested a review from bnbarham as a code owner February 27, 2024 01:30
@ahoppen
Copy link
Member Author

ahoppen commented Feb 27, 2024

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Feb 27, 2024

@swift-ci Please test macOS

1 similar comment
@ahoppen
Copy link
Member Author

ahoppen commented Feb 28, 2024

@swift-ci Please test macOS

// Pick biggest indentation that encompasses at least 90% of the source lines.
let threshold = Int(Double(visitor.linesProcessed) * 0.9)

for spaceIndentation in [8, 4, 2] {
Copy link
Contributor

Choose a reason for hiding this comment

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

Poor 3 space users 😅. Is 8 actually a thing that people use?

I think one issue we're likely to run into here is that for highly nested snippets, this is often going to return 8 even if it's eg. 2 space. Is the idea that this would only be run on entire files/functions/something else?

Copy link
Member Author

Choose a reason for hiding this comment

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

That shouldn’t be an issue. If we have 4 lines indented with 8 spaces and 1 line indented with 10 spaces, we’ll infer the indentation to 2 spaces because only 80% of the lines have an indentation that’s a multiple of 8 but all lines have an indentation that’s a multiple of 2.

And I think I’ve seen codebases with 8 spaces of indentation. Can’t remember where and when, though.

@ahoppen ahoppen merged commit 1b07654 into swiftlang:main Feb 28, 2024
3 checks passed
@ahoppen ahoppen deleted the ahoppen/infer-indentation branch February 28, 2024 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants