-
Notifications
You must be signed in to change notification settings - Fork 416
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 symbolName property for some syntax nodes #2583
base: main
Are you sure you want to change the base?
Conversation
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.
Which other nodes should have a symbolName property?
- enum, protocol, struct, class, actor?
- typealias?
- property - this one for sure.
- deinit ?
- macro ?
- operator ?
I think it only makes sense to offer it for nodes that have a
|
Depending on: #2593 |
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.
Thank you. Looks great, I’m just being nitpicky again.
Thanks for the review Alex 🫶 |
`FunctionDecl`, `InitializerDecl`, `SubscriptDecl`, `EnumCaseElement`, and `MacroDecl` gained a new computed property: `symbolName` The `symbolName` property provides a string representation of the declaration's name along with its parameter labels. For example, a function `func greet(name: String)` will have the symbol name `greet(name:)`.
@swift-ci please smoke 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.
A small nit over the naming in the documentation, but otherwise this LGTM
@@ -2,6 +2,11 @@ | |||
|
|||
## New APIs | |||
|
|||
- `FunctionDecl`, `InitializerDecl`, `SubscriptDecl`, `EnumCaseElement`, and `MacroDecl` gained a new computed property: `symbolName` | |||
- Description: The `symbolName` property provides a string representation of the declaration's name along with its parameter labels. For example, a function `func greet(name: String)` will have the symbol name `greet(name:)`. |
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.
Nit: These are called argument labels in TSPL, and we have e.g SyntaxClassification.argumentLabel
, I think we probably ought to be consistent.
- Description: The `symbolName` property provides a string representation of the declaration's name along with its parameter labels. For example, a function `func greet(name: String)` will have the symbol name `greet(name:)`. | |
- Description: The `symbolName` property provides a string representation of the declaration's name along with its argument labels. For example, a function `func greet(name: String)` will have the symbol name `greet(name:)`. |
extension FunctionDeclSyntax { | ||
/// The symbol name of the function declaration. | ||
/// | ||
/// The symbol name is a string representation of the function name along with its parameter labels. |
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 symbol name is a string representation of the function name along with its parameter labels. | |
/// The symbol name is a string representation of the function name along with its argument labels. |
extension InitializerDeclSyntax { | ||
/// The symbol name of the initializer declaration. | ||
/// | ||
/// The symbol name is a string representation of the initializer along with its parameter labels. |
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 symbol name is a string representation of the initializer along with its parameter labels. | |
/// The symbol name is a string representation of the initializer along with its argument labels. |
extension SubscriptDeclSyntax { | ||
/// The symbol name of the subscript declaration. | ||
/// | ||
/// The symbol name is a string representation of the subscript along with its parameter labels. |
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 symbol name is a string representation of the subscript along with its parameter labels. | |
/// The symbol name is a string representation of the subscript along with its argument labels. |
extension MacroDeclSyntax { | ||
/// The symbol name of the macro declaration. | ||
/// | ||
/// The symbol name is a string representation of the macro name along with its parameter labels. |
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 symbol name is a string representation of the macro name along with its parameter labels. | |
/// The symbol name is a string representation of the macro name along with its argument labels. |
} | ||
} | ||
|
||
/// Generates the symbol name by combining the base name and parameter labels. |
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.
/// Generates the symbol name by combining the base name and parameter labels. | |
/// Generates the symbol name by combining the base name and argument labels. |
This resembles struct SymbolBaseName {
enum Kind { case normal, subscript, initializer, deinitializer }
var asString: String {get}
var kind: Kind {get}
var isOperator: Bool {get}
}
struct SymbolName {
var asString: String {get}
var baseName: SymbolBaseName {get}
var argumentLabels: some Collection<String> {get}
} WDYT? |
That is a great idea, @rintaro. |
FunctionDecl
,InitializerDecl
,SubscriptDecl
,EnumCaseElement
, andMacroDecl
gained a new computed property:symbolName
The
symbolName
property provides a string representation of the declaration's name along with its parameter labels. For example, a functionfunc greet(name: String)
will have the symbol namegreet(name:)
.Resolves #2488