-
Notifications
You must be signed in to change notification settings - Fork 441
Add commentValue
property to Trivia
for cleaned comments
#2966
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
base: main
Are you sure you want to change the base?
Conversation
- Copied changes from PR swiftlang#2578 (swiftlang#2578) - Original work by @adammcarter - Manual copy due to inaccessible original branch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing the issue, @zyadtaha. I think the PR still needs some polishing regarding indentation handling. I left a few comments inline.
3ad450f
to
c23e3dc
Compare
Thanks for the feedback, @ahoppen! I've addressed the comments—let me know if anything else needs attention. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the adjustments. I left a few more edge cases to consider as comments.
Add release note for Trivia.commentValue Address PR review Address second review
c23e3dc
to
04f700e
Compare
Hey @ahoppen, just wanted to check if there's anything else needed from my side on this PR. Let me know if you have any concerns. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates. I think there are still a few more issues that need to be addressed.
Sources/SwiftSyntax/Trivia.swift
Outdated
text.hasPrefix("/*\n") | ||
? processMultilineBlockComment(text) | ||
: processBlockComment(text, prefix: "/*", suffix: "*/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think we need a general distinction here. Say if you have
/* abc
def
ghi
*/
We should still be able to strip the indentation. We just need to exclude the first line from the indentation stripping.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But even if we exclude the first line from indentation stripping, wouldn't the minimum indentation still be 3 due to the last line? That would result in:
abc
def
ghi
Maybe we should consider excluding the last line from indentation stripping as well?
Hey @ahoppen, I've pushed my updates. For your last two comments, I've added responses—let me know your feedback when you get a chance. Thanks! |
8df001d
to
52fdc83
Compare
} | ||
} | ||
|
||
return (Swift.min(currentMin.0, spaceCount), Swift.min(currentMin.1, tabCount)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this doesn’t work if you have one line that contains a space as indentation and another one that only contains a tab as indentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case:
/* comment
\tcomment*/
The minIndentation
would be 1 because it only starts checking from the second line, which contains a tab. Since the first line is ignored during trimming if it contains the /*
, the output would be:
comment
comment
But in this case:
/*
comment
\tcomment*/
The minIndentation
would be 0, as expected, and the output would be:
comment
\tcomment
If we want both cases to produce consistent output, maybe we could insert a \n
after the /*
if it's not already present, to ensure that minIndentation
is 0. What do you think?
This PR continues the work from #2578, addressing the review comments and refining the behavior of
Trivia.commentValue
.