Skip to content

[Swiftify] Copy doc comment from clang node #81584

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 6 commits into from
May 20, 2025

Conversation

hnrklssn
Copy link
Contributor

Swift nodes imported from clang don't have doc comments carried over, but IDEs are clever enough to fetch the comments from the associated clang node. The swift node in the macro expansion from _SwiftifyImport doesn't have a clang node directly associated with it however.

This patch adds the same comment from the clang node to the _SwiftifyImport macro invocation node. Since the macro has access to this node, it can easily copy over its leading trivia.

For now the comment is not altered at all, meaning @param still remains even if the parmeter is removed.

rdar://151346977

@hnrklssn
Copy link
Contributor Author

@swift-ci please smoke test

1 similar comment
@hnrklssn
Copy link
Contributor Author

@swift-ci please smoke test

Copy link
Contributor

@j-hui j-hui left a comment

Choose a reason for hiding this comment

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

This looks good to me, but I'm wondering whether it's easy to write a test to make sure that SourceKit picks up the comment attached to the macro-generated overload?

Copy link
Contributor

@delcypher delcypher left a comment

Choose a reason for hiding this comment

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

Seems reasonable. I do have a suggestion about tweaking the doc comment a little though

// to. Waiting until we know that the macro will be attached before
// emitting the comment to the string, despite the comment occurring
// first, avoids copying a bunch of potentially long comments for nodes
// that don't end up with wrappers.
Copy link
Contributor

@delcypher delcypher May 17, 2025

Choose a reason for hiding this comment

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

We might want to add a comment here that references an issue (or radar) about the fact that@param and might need to be rewritten.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this is a minor enough potential future QoL improvement that it doesn't warrant polluting the code with discussion around it

@hnrklssn
Copy link
Contributor Author

@swift-ci please smoke test

@hnrklssn
Copy link
Contributor Author

This looks good to me, but I'm wondering whether it's easy to write a test to make sure that SourceKit picks up the comment attached to the macro-generated overload?

It was actually easier than I thought! And I was able to verify that adding our custom line comment still is considered part of the same docs even if the rest uses block comments, which simplifies that implementation a lot.

@hnrklssn
Copy link
Contributor Author

@swift-ci please smoke test

hnrklssn added 5 commits May 17, 2025 20:44
Swift nodes imported from clang don't have doc comments carried over,
but IDEs are clever enough to fetch the comments from the associated
clang node. The swift node in the macro expansion from _SwiftifyImport
doesn't have a clang node directly associated with it however.

This patch adds the same comment from the clang node to the
_SwiftifyImport macro invocation node. Since the macro has access to
this node, it can easily copy over its leading trivia.

For now the comment is not altered at all, meaning @param still remains
even if the parmeter is removed.

rdar://151346977
@hnrklssn hnrklssn force-pushed the swiftify-doccomment branch from 900eb32 to a907481 Compare May 18, 2025 03:54
@hnrklssn
Copy link
Contributor Author

@swift-ci please smoke test

@hnrklssn
Copy link
Contributor Author

@swift-ci please smoke test windows

@hnrklssn
Copy link
Contributor Author

@swift-ci please smoke test

@hnrklssn hnrklssn merged commit 6534b9b into swiftlang:main May 20, 2025
3 checks passed
hnrklssn added a commit to hnrklssn/swift that referenced this pull request May 20, 2025
Swift nodes imported from clang don't have doc comments carried over,
but IDEs are clever enough to fetch the comments from the associated
clang node. The swift node in the macro expansion from _SwiftifyImport
doesn't have a clang node directly associated with it however.

This patch adds the same comment from the clang node to the
_SwiftifyImport macro invocation node. Since the macro has access to
this node, it can easily copy over its leading trivia.

For now the comment is not altered at all, meaning @param still remains
even if the parmeter is removed.

rdar://151346977
(cherry picked from commit 6534b9b)
hamishknight added a commit to hamishknight/swift that referenced this pull request May 22, 2025
hnrklssn added a commit to hnrklssn/swift that referenced this pull request May 24, 2025
Swift nodes imported from clang don't have doc comments carried over,
but IDEs are clever enough to fetch the comments from the associated
clang node. The swift node in the macro expansion from _SwiftifyImport
doesn't have a clang node directly associated with it however.

This patch adds the same comment from the clang node to the
_SwiftifyImport macro invocation node. Since the macro has access to
this node, it can easily copy over its leading trivia.

For now the comment is not altered at all, meaning @param still remains
even if the parmeter is removed.

rdar://151346977
(cherry picked from commit 6534b9b)
hnrklssn added a commit to hnrklssn/swift that referenced this pull request May 29, 2025
Swift nodes imported from clang don't have doc comments carried over,
but IDEs are clever enough to fetch the comments from the associated
clang node. The swift node in the macro expansion from _SwiftifyImport
doesn't have a clang node directly associated with it however.

This patch adds the same comment from the clang node to the
_SwiftifyImport macro invocation node. Since the macro has access to
this node, it can easily copy over its leading trivia.

For now the comment is not altered at all, meaning @param still remains
even if the parmeter is removed.

rdar://151346977
(cherry picked from commit 6534b9b)
hnrklssn added a commit to hnrklssn/swift that referenced this pull request May 29, 2025
Swift nodes imported from clang don't have doc comments carried over,
but IDEs are clever enough to fetch the comments from the associated
clang node. The swift node in the macro expansion from _SwiftifyImport
doesn't have a clang node directly associated with it however.

This patch adds the same comment from the clang node to the
_SwiftifyImport macro invocation node. Since the macro has access to
this node, it can easily copy over its leading trivia.

For now the comment is not altered at all, meaning @param still remains
even if the parmeter is removed.

rdar://151346977
(cherry picked from commit 6534b9b)
(cherry picked from commit c9d51aa)
hnrklssn added a commit to hnrklssn/swift that referenced this pull request May 29, 2025
Swift nodes imported from clang don't have doc comments carried over,
but IDEs are clever enough to fetch the comments from the associated
clang node. The swift node in the macro expansion from _SwiftifyImport
doesn't have a clang node directly associated with it however.

This patch adds the same comment from the clang node to the
_SwiftifyImport macro invocation node. Since the macro has access to
this node, it can easily copy over its leading trivia.

For now the comment is not altered at all, meaning @param still remains
even if the parmeter is removed.

rdar://151346977
(cherry picked from commit 6534b9b)
hnrklssn added a commit to hnrklssn/swift that referenced this pull request May 29, 2025
Swift nodes imported from clang don't have doc comments carried over,
but IDEs are clever enough to fetch the comments from the associated
clang node. The swift node in the macro expansion from _SwiftifyImport
doesn't have a clang node directly associated with it however.

This patch adds the same comment from the clang node to the
_SwiftifyImport macro invocation node. Since the macro has access to
this node, it can easily copy over its leading trivia.

For now the comment is not altered at all, meaning @param still remains
even if the parmeter is removed.

rdar://151346977
(cherry picked from commit 6534b9b)
hnrklssn added a commit that referenced this pull request May 30, 2025
[Swiftify] Copy doc comment from clang node (#81584)
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.

5 participants