Skip to content

Commit

Permalink
Get more documentation comments into the CodeGeneration lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeehut committed Dec 19, 2024
1 parent 7b1c82b commit 33227e1
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 32 deletions.
58 changes: 34 additions & 24 deletions CodeGeneration/Sources/SyntaxSupport/ExprNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ public let EXPR_NODES: [Node] = [
nameForDiagnostics: nil,
documentation: """
An interpolated expression segment inside a string literal.
This case represents interpolated expressions like `\\(name)` in `"Hello \\(name)"`.
- SeeAlso: ``StringSegmentSyntax``
Expand Down Expand Up @@ -1847,27 +1847,11 @@ public let EXPR_NODES: [Node] = [
base: .syntax,
nameForDiagnostics: nil,
documentation: """
A string literal segment that represents plain text content within a string literal expression.
In a string literal `"Hello \\(name)"`, the `"Hello "` part is represented by a `StringSegmentSyntax`, while `\\(name)` is represented by an `ExpressionSegmentSyntax`.
Creating a string segment requires special attention to use `.stringSegment()` for the content token to ensure proper formatting.
### Examples
```swift
let segment = StringSegmentSyntax(content: .stringSegment("Hello World"))
A literal text segment inside a string literal.
let stringLiteral = StringLiteralExprSyntax(
openingQuote: .stringQuoteToken(),
segments: StringLiteralSegmentListSyntax([.stringSegment(segment)]),
closingQuote: .stringQuoteToken()
)
```
This case represents static text content like `"Hello "` in `"Hello \\(name)"`.
- Important: When creating a string segment from a string literal, always use `.stringSegment(string)` rather than just passing the string directly. Using the raw string will create an identifier token instead of a string segment token, which can lead to formatting issues.
- SeeAlso: ``ExpressionSegmentSyntax`` for segments containing string interpolations
- SeeAlso: ``ExpressionSegmentSyntax``
""",
children: [
Child(
Expand Down Expand Up @@ -2175,11 +2159,37 @@ public let EXPR_NODES: [Node] = [
base: .syntax,
nameForDiagnostics: nil,
documentation: """
An expression that is prefixed by a label.
An expression with an optional label and colon, used in function calls, tuple elements, and macro arguments.
This type represents labeled expressions in Swift syntax, commonly used for:
- Function call arguments with parameter labels
- Tuple elements with names
- Macro arguments with labels
For example, labeled expressions occur in
- Function calls, where the label is the parameter label.
- Tuples, where the label is the name of the tuple element.
### Examples
```swift
// Creating a labeled argument
let labeledArg = LabeledExprSyntax(
label: .identifier("localized"),
colon: .colonToken(),
expression: stringLiteral
)
// Creating a list of labeled arguments
let arguments = LabeledExprListSyntax([
LabeledExprSyntax(
label: .identifier("name"),
colon: .colonToken(),
expression: nameExpr
),
LabeledExprSyntax(
label: .identifier("value"),
colon: .colonToken(),
expression: valueExpr,
trailingComma: .commaToken()
)
])
```
""",
traits: [
"WithTrailingComma"
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftSyntax/generated/SyntaxCollections.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1482,9 +1482,9 @@ public struct StringLiteralSegmentListSyntax: SyntaxCollection, SyntaxHashable {
/// ```
public enum Element: SyntaxChildChoices, SyntaxHashable {
/// A literal text segment inside a string literal.
///
///
/// This case represents static text content like `"Hello "` in `"Hello \(name)"`.
///
///
/// - SeeAlso: ``ExpressionSegmentSyntax``
case stringSegment(StringSegmentSyntax)
/// An interpolated expression segment inside a string literal.
Expand Down
8 changes: 6 additions & 2 deletions Sources/SwiftSyntax/generated/raw/RawSyntaxNodesQRS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1345,11 +1345,15 @@ public struct RawStringLiteralExprSyntax: RawExprSyntaxNodeProtocol {
@_spi(RawSyntax)
public struct RawStringLiteralSegmentListSyntax: RawSyntaxNodeProtocol {
public enum Element: RawSyntaxNodeProtocol {
/// A literal segment inside a string segment.
/// A literal text segment inside a string literal.
///
/// This case represents static text content like `"Hello "` in `"Hello \(name)"`.
///
/// - SeeAlso: ``ExpressionSegmentSyntax``
case stringSegment(RawStringSegmentSyntax)
/// An interpolated expression inside a string literal.
/// An interpolated expression segment inside a string literal.
///
/// This case represents interpolated expressions like `\(name)` in `"Hello \(name)"`.
///
/// - SeeAlso: ``StringSegmentSyntax``
case expressionSegment(RawExpressionSegmentSyntax)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1798,7 +1798,9 @@ public struct ExpressionPatternSyntax: PatternSyntaxProtocol, SyntaxHashable, _L

// MARK: - ExpressionSegmentSyntax

/// An interpolated expression inside a string literal.
/// An interpolated expression segment inside a string literal.
///
/// This case represents interpolated expressions like `\(name)` in `"Hello \(name)"`.
///
/// - SeeAlso: ``StringSegmentSyntax``
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -789,12 +789,12 @@ public struct KeyPathSubscriptComponentSyntax: SyntaxProtocol, SyntaxHashable, _
// MARK: - LabeledExprSyntax

/// An expression with an optional label and colon, used in function calls, tuple elements, and macro arguments.
///
///
/// This type represents labeled expressions in Swift syntax, commonly used for:
/// - Function call arguments with parameter labels
/// - Tuple elements with names
/// - Macro arguments with labels
///
///
/// ### Examples
/// ```swift
/// // Creating a labeled argument
Expand All @@ -803,7 +803,7 @@ public struct KeyPathSubscriptComponentSyntax: SyntaxProtocol, SyntaxHashable, _
/// colon: .colonToken(),
/// expression: stringLiteral
/// )
///
///
/// // Creating a list of labeled arguments
/// let arguments = LabeledExprListSyntax([
/// LabeledExprSyntax(
Expand Down

0 comments on commit 33227e1

Please sign in to comment.