Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .swift-format
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"version": 1,
"lineLength": 160,
"lineLength": 120,
"indentation": {
"spaces": 2
},
Expand Down
29 changes: 22 additions & 7 deletions CodeGeneration/Sources/SyntaxSupport/AttributeNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,11 @@ public let ATTRIBUTE_NODES: [Node] = [
Child(
name: "availabilityArguments",
deprecatedName: "availabilityList",
kind: .collection(kind: .availabilityArgumentList, collectionElementName: "AvailabilityArgument", deprecatedCollectionElementName: "Availability")
kind: .collection(
kind: .availabilityArgumentList,
collectionElementName: "AvailabilityArgument",
deprecatedCollectionElementName: "Availability"
)
),
Child(
name: "semicolon",
Expand Down Expand Up @@ -236,7 +240,11 @@ public let ATTRIBUTE_NODES: [Node] = [
Child(
name: "platforms",
deprecatedName: "versionList",
kind: .collection(kind: .platformVersionItemList, collectionElementName: "Platform", deprecatedCollectionElementName: "Availability"),
kind: .collection(
kind: .platformVersionItemList,
collectionElementName: "Platform",
deprecatedCollectionElementName: "Availability"
),
documentation: "The list of OS versions in which the declaration became ABI stable."
),
]
Expand Down Expand Up @@ -357,7 +365,8 @@ public let ATTRIBUTE_NODES: [Node] = [
kind: .differentiabilityArgument,
base: .syntax,
nameForDiagnostics: "differentiability argument",
documentation: "A differentiability argument: either the \"self\" identifier, a function parameter name, or a function parameter index.",
documentation:
"A differentiability argument: either the \"self\" identifier, a function parameter name, or a function parameter index.",
Copy link
Contributor

@bnbarham bnbarham Mar 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with this change in general (I think 120 is a nice compromise between 80 and massive lines), though it really seems like we need to teach swift-format to split both strings and comments - the split here doesn't really make sense.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't agree more. It would be amazing if swift-format could split it in a better way 🥺

traits: [
"WithTrailingComma"
],
Expand Down Expand Up @@ -471,7 +480,8 @@ public let ATTRIBUTE_NODES: [Node] = [
name: "genericWhereClause",
deprecatedName: "whereClause",
kind: .node(kind: .genericWhereClause),
documentation: "A `where` clause that places additional constraints on generic parameters like `where T: Differentiable`.",
documentation:
"A `where` clause that places additional constraints on generic parameters like `where T: Differentiable`.",
isOptional: true
),
]
Expand Down Expand Up @@ -588,7 +598,8 @@ public let ATTRIBUTE_NODES: [Node] = [
kind: .implementsAttributeArguments,
base: .syntax,
nameForDiagnostics: "@_implements arguemnts",
documentation: "The arguments for the `@_implements` attribute of the form `Type, methodName(arg1Label:arg2Label:)`",
documentation:
"The arguments for the `@_implements` attribute of the form `Type, methodName(arg1Label:arg2Label:)`",
children: [
Child(
name: "type",
Expand Down Expand Up @@ -738,14 +749,18 @@ public let ATTRIBUTE_NODES: [Node] = [
base: .syntaxCollection,
nameForDiagnostics: "argument to '@_specialize",
documentation: "A collection of arguments for the `@_specialize` attribute",
elementChoices: [.labeledSpecializeArgument, .specializeAvailabilityArgument, .specializeTargetFunctionArgument, .genericWhereClause]
elementChoices: [
.labeledSpecializeArgument, .specializeAvailabilityArgument, .specializeTargetFunctionArgument,
.genericWhereClause,
]
),

Node(
kind: .specializeTargetFunctionArgument,
base: .syntax,
nameForDiagnostics: "attribute argument",
documentation: "A labeled argument for the `@_specialize` attribute with a function decl value like `target: myFunc(_:)`",
documentation:
"A labeled argument for the `@_specialize` attribute with a function decl value like `target: myFunc(_:)`",
traits: [
"WithTrailingComma"
],
Expand Down
15 changes: 10 additions & 5 deletions CodeGeneration/Sources/SyntaxSupport/AvailabilityNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public let AVAILABILITY_NODES: [Node] = [
kind: .availabilityArgument,
base: .syntax,
nameForDiagnostics: "availability argument",
documentation: "A single argument to an `@available` argument like `*`, `iOS 10.1`, or `message: \"This has been deprecated\"`.",
documentation:
"A single argument to an `@available` argument like `*`, `iOS 10.1`, or `message: \"This has been deprecated\"`.",
traits: ["WithTrailingComma"],
children: [
Child(
Expand Down Expand Up @@ -54,7 +55,8 @@ public let AVAILABILITY_NODES: [Node] = [
kind: .availabilityLabeledArgument,
base: .syntax,
nameForDiagnostics: "availability argument",
documentation: "An argument to an `@available` attribute that consists of a label and a value, e.g. `message: \"This has been deprecated\"`.",
documentation:
"An argument to an `@available` attribute that consists of a label and a value, e.g. `message: \"This has been deprecated\"`.",
children: [
Child(
name: "label",
Expand Down Expand Up @@ -102,7 +104,8 @@ public let AVAILABILITY_NODES: [Node] = [
kind: .platformVersion,
base: .syntax,
nameForDiagnostics: "version restriction",
documentation: "An argument to `@available` that restricts the availability on a certain platform to a version, e.g. `iOS 10` or `swift 3.4`.",
documentation:
"An argument to `@available` that restricts the availability on a certain platform to a version, e.g. `iOS 10` or `swift 3.4`.",
children: [
Child(
name: "platform",
Expand Down Expand Up @@ -157,7 +160,8 @@ public let AVAILABILITY_NODES: [Node] = [
kind: .versionTuple,
base: .syntax,
nameForDiagnostics: "version tuple",
documentation: "A version number like `1.2.0`. Only the first version component is required. There might be an arbitrary number of following components.",
documentation:
"A version number like `1.2.0`. Only the first version component is required. There might be an arbitrary number of following components.",
parserFunction: "parseVersionTuple",
children: [
Child(
Expand All @@ -168,7 +172,8 @@ public let AVAILABILITY_NODES: [Node] = [
Child(
name: "components",
kind: .collection(kind: .versionComponentList, collectionElementName: "VersionComponent"),
documentation: "Any version components that are not the major version . For example, for `1.2.0`, this will contain `.2.0`."
documentation:
"Any version components that are not the major version . For example, for `1.2.0`, this will contain `.2.0`."
),
]
),
Expand Down
12 changes: 10 additions & 2 deletions CodeGeneration/Sources/SyntaxSupport/Child.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ public enum ChildKind {
/// The child always contains a node that matches one of the `choices`.
case nodeChoices(choices: [Child])
/// The child is a collection of `kind`.
case collection(kind: SyntaxNodeKind, collectionElementName: String, defaultsToEmpty: Bool = false, deprecatedCollectionElementName: String? = nil)
case collection(
kind: SyntaxNodeKind,
collectionElementName: String,
defaultsToEmpty: Bool = false,
deprecatedCollectionElementName: String? = nil
)
/// The child is a token that matches one of the given `choices`.
/// If `requiresLeadingSpace` or `requiresTrailingSpace` is not `nil`, it
/// overrides the default leading/trailing space behavior of the token.
Expand Down Expand Up @@ -259,7 +264,10 @@ public class Child {
isOptional: Bool = false
) {
precondition(name.first?.isLowercase ?? true, "The first letter of a child’s name should be lowercase")
precondition(deprecatedName?.first?.isLowercase ?? true, "The first letter of a child’s deprecatedName should be lowercase")
precondition(
deprecatedName?.first?.isLowercase ?? true,
"The first letter of a child’s deprecatedName should be lowercase"
)
self.name = name
self.deprecatedName = deprecatedName
self.kind = kind
Expand Down
18 changes: 12 additions & 6 deletions CodeGeneration/Sources/SyntaxSupport/CommonNodes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ public let COMMON_NODES: [Node] = [
kind: .missingDecl,
base: .decl,
nameForDiagnostics: "declaration",
documentation: "In case the source code is missing a declaration, this node stands in place of the missing declaration.",
documentation:
"In case the source code is missing a declaration, this node stands in place of the missing declaration.",
traits: [
"MissingNode",
"WithAttributes",
Expand All @@ -201,12 +202,14 @@ public let COMMON_NODES: [Node] = [
Child(
name: "attributes",
kind: .collection(kind: .attributeList, collectionElementName: "Attribute", defaultsToEmpty: true),
documentation: "If there were standalone attributes without a declaration to attach them to, the ``MissingDeclSyntax`` will contain these."
documentation:
"If there were standalone attributes without a declaration to attach them to, the ``MissingDeclSyntax`` will contain these."
),
Child(
name: "modifiers",
kind: .collection(kind: .declModifierList, collectionElementName: "Modifier", defaultsToEmpty: true),
documentation: "If there were standalone modifiers without a declaration to attach them to, the ``MissingDeclSyntax`` will contain these."
documentation:
"If there were standalone modifiers without a declaration to attach them to, the ``MissingDeclSyntax`` will contain these."
),
Child(
name: "placeholder",
Expand All @@ -224,7 +227,8 @@ public let COMMON_NODES: [Node] = [
kind: .missingExpr,
base: .expr,
nameForDiagnostics: "expression",
documentation: "In case the source code is missing an expression, this node stands in place of the missing expression.",
documentation:
"In case the source code is missing an expression, this node stands in place of the missing expression.",
traits: [
"MissingNode"
],
Expand Down Expand Up @@ -266,7 +270,8 @@ public let COMMON_NODES: [Node] = [
kind: .missingStmt,
base: .stmt,
nameForDiagnostics: "statement",
documentation: "In case the source code is missing a statement, this node stands in place of the missing statement.",
documentation:
"In case the source code is missing a statement, this node stands in place of the missing statement.",
traits: [
"MissingNode"
],
Expand Down Expand Up @@ -372,7 +377,8 @@ public let COMMON_NODES: [Node] = [
kind: .unexpectedNodes,
base: .syntaxCollection,
nameForDiagnostics: nil,
documentation: "A collection of syntax nodes that occurred in the source code but could not be used to form a valid syntax tree.",
documentation:
"A collection of syntax nodes that occurred in the source code but could not be used to form a valid syntax tree.",
elementChoices: [.syntax]
),

Expand Down
Loading