-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SymbolGraphGen] Add filename and module name to symbols' doc comments #58857
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
Conversation
@swift-ci Please smoke test |
lib/SymbolGraphGen/Symbol.cpp
Outdated
auto Loc = DocCommentProvidingDecl->getLoc(/*SerializedOK=*/true); | ||
if (Loc.isValid()) { | ||
auto FileName = DocCommentProvidingDecl->getASTContext().SourceMgr.getDisplayNameForLoc(Loc); | ||
if (!FileName.empty()) { |
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.
Maybe this pattern could be refactored to avoid code duplication?
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've pushed up an attempt to split out the file name collection and serialization so that serializeLocation
can use the same code paths as serializeDocComment
here. It was a bit awkward to work it around serializeLocation
, but maybe i could re-duplicate the file-name collection but keep the serialization refactored like this. 🤷♀️
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.
The second option is what I had in mind (just deduplicating the code that is now in serializeFileURI
). However the new version is kinda nice, I don't think it is awkward to read. Maybe the functions shouldn't be called getFileURI
since they don't actually return URIs but rather pathnames.
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.
Good call! I've amended the commit to rename the functions.
@swift-ci Please smoke test |
75d9acf
to
ef15476
Compare
@swift-ci Please test |
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.
LGTM
I added a test to double-check that docs inherited from an external module (in this case, the standard library) correctly identifies the source module of the comment. @swift-ci Please smoke test |
Resolves rdar://81190369
Currently, doc comments in the symbol graph only include information about line/column numbers when referring to its location. However, if docs are inherited (and source information is available), these locations may point to a different file than the one for the symbol's declaration. In addition, the inherited doc comment might have been written with its original module in mind, for example by using Swift-DocC symbol links that point to other symbols in the module. These symbols may not be able to resolve in the inheriting module, which causes spurious errors when building documentation.
This PR adds two new sub-fields to the
docComment
field:uri
andmodule
. Theuri
field points to the file from which the doc comment was declared, and themodule
field indicates which module it's in. This can be used for more accurate diagnostics (even in docs are inherited within the same module) and to determine when a doc comment is inherited from a different module than the one being documented.