-
Notifications
You must be signed in to change notification settings - Fork 10.5k
introduce a @_documentation(...)
attribute to influence SymbolGraphGen
#60242
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,6 +121,27 @@ extension Text { | |
} | ||
``` | ||
|
||
## `@_documentation(metadata: ...)` | ||
|
||
Adds "documentation metadata" to the symbol. The identifier in the attribute is | ||
added to the symbol graph in the `"metadata"` field of the symbol. This can be | ||
used to add an arbitrary grouping or other indicator to symbols for use in | ||
documentation. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you able to specify multiple There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure; i'll have to check. Offhand, i think the answer is "no" because of checks for duplicate attributes, but i'm not confident about it. |
||
|
||
## `@_documentation(visibility: ...)` | ||
|
||
Forces the symbol to be treated as the given access level when checking | ||
visibility. This can be used to, for example, force a symbol with an underscored | ||
name to appear in `public` symbol graphs, or treat an otherwise-`public` symbol | ||
as being `internal` or `private` for the purposes of documentation, to hide it | ||
from `public` docs. | ||
|
||
This can also be applied to `@_exported import` statements to only include the | ||
imported symbols in symbol graphs with the given minimum access level. For | ||
example, applying `@_documentation(visibility: internal)` to an `@_exported | ||
import` statement will hide the imported symbols from `public` symbol graphs and | ||
documentation, but show them on `internal` symbol graphs and documentation. | ||
|
||
## `@_dynamicReplacement(for: targetFunc(label:))` | ||
|
||
Marks a function as the dynamic replacement for another `dynamic` function. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//===--- DocumentationCategory.h - Accessors for @_documentation ----------===// | ||
// | ||
// This source file is part of the Swift.org open source project | ||
// | ||
// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef SWIFT_SYMBOLGRAPHGEN_DOCUMENTATIONCATEGORY_H | ||
#define SWIFT_SYMBOLGRAPHGEN_DOCUMENTATIONCATEGORY_H | ||
|
||
#include "swift/AST/Decl.h" | ||
|
||
#include "llvm/Support/Compiler.h" | ||
|
||
namespace swift { | ||
namespace symbolgraphgen { | ||
|
||
LLVM_ATTRIBUTE_USED | ||
static StringRef documentationMetadataForDecl(const Decl *D) { | ||
if (!D) return {}; | ||
|
||
if (const auto *DC = D->getAttrs().getAttribute<DocumentationAttr>()) { | ||
return DC->Metadata; | ||
} | ||
|
||
return {}; | ||
} | ||
|
||
LLVM_ATTRIBUTE_USED | ||
static Optional<AccessLevel> documentationVisibilityForDecl(const Decl *D) { | ||
if (!D) return None; | ||
|
||
if (const auto *DC = D->getAttrs().getAttribute<DocumentationAttr>()) { | ||
return DC->Visibility; | ||
} | ||
|
||
return None; | ||
} | ||
|
||
} // namespace symbolgraphgen | ||
} // namespace swift | ||
|
||
#endif // SWIFT_SYMBOLGRAPHGEN_DOCUMENTATIONCATEGORY_H |
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 assume the value of the
metadata
parameter is just a string that be specified with or without quotes?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.
Right now it can only be an identifier, but i could see about making it a quoted string as well.
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.
If it's a string in quotes, developers could stick in useful metadata like JSON, CSV, or hex encoded images which would be fun 👌🏼