Add symbolName property for some syntax nodes#2583
Add symbolName property for some syntax nodes#2583Matejkob wants to merge 2 commits intoswiftlang:mainfrom
Conversation
Matejkob
left a comment
There was a problem hiding this comment.
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 |
ahoppen
left a comment
There was a problem hiding this comment.
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 |
hamishknight
left a comment
There was a problem hiding this comment.
A small nit over the naming in the documentation, but otherwise this LGTM
| ## 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.
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.
| /// 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.
| /// 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.
| /// 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.
| /// 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.
| /// 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, andMacroDeclgained a new computed property:symbolNameThe
symbolNameproperty 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