Skip to content

Commit cf30b55

Browse files
committed
Eliminate 'keyPathInParent usage
Replace with propertyInParent
1 parent f037921 commit cf30b55

File tree

3 files changed

+22
-25
lines changed

3 files changed

+22
-25
lines changed

Sources/SwiftIDEUtils/SyntaxClassification.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,35 +63,35 @@ extension SyntaxClassification {
6363
/// - childKind: The node syntax kind.
6464
/// - Returns: A pair of classification and whether it is "forced", or nil if
6565
/// no classification is attached.
66-
internal static func classify(_ keyPath: AnyKeyPath) -> (SyntaxClassification, Bool)? {
67-
switch keyPath {
68-
case \AttributeSyntax.attributeName:
66+
internal static func classify(_ property: SyntaxLayoutProperty) -> (SyntaxClassification, Bool)? {
67+
switch property {
68+
case AttributeSyntax.layout[.attributeName]:
6969
return (.attribute, true)
70-
case \PlatformVersionItemSyntax.platformVersion:
70+
case PlatformVersionItemSyntax.layout[.platformVersion]:
7171
return (.keyword, false)
72-
case \AvailabilityVersionRestrictionSyntax.platform:
72+
case PlatformVersionSyntax.layout[.platform]:
7373
return (.keyword, false)
74-
case \DeclModifierSyntax.name:
74+
case DeclModifierSyntax.layout[.name]:
7575
return (.attribute, false)
76-
case \IfConfigClauseSyntax.poundKeyword:
76+
case IfConfigClauseSyntax.layout[.poundKeyword]:
7777
return (.ifConfigDirective, false)
78-
case \IfConfigClauseSyntax.condition:
78+
case IfConfigClauseSyntax.layout[.condition]:
7979
return (.ifConfigDirective, false)
80-
case \IfConfigDeclSyntax.poundEndif:
80+
case IfConfigDeclSyntax.layout[.poundEndif]:
8181
return (.ifConfigDirective, false)
82-
case \MemberTypeIdentifierSyntax.name:
82+
case MemberTypeSyntax.layout[.name]:
8383
return (.type, false)
84-
case \OperatorDeclSyntax.name:
84+
case OperatorDeclSyntax.layout[.name]:
8585
return (.operator, false)
86-
case \PrecedenceGroupAssociativitySyntax.associativityLabel:
86+
case PrecedenceGroupAssociativitySyntax.layout[.associativityLabel]:
8787
return (.keyword, false)
88-
case \PrecedenceGroupRelationSyntax.higherThanOrLowerThanLabel:
88+
case PrecedenceGroupRelationSyntax.layout[.higherThanOrLowerThanLabel]:
8989
return (.keyword, false)
90-
case \SimpleTypeIdentifierSyntax.name:
90+
case IdentifierTypeSyntax.layout[.name]:
9191
return (.type, false)
92-
case \FunctionParameterSyntax.firstName:
92+
case FunctionParameterSyntax.layout[.firstName]:
9393
return (.argumentLabel, false)
94-
case \LabeledExprSyntax.label:
94+
case LabeledExprSyntax.layout[.label]:
9595
return (.argumentLabel, false)
9696
default:
9797
return nil

Sources/SwiftIDEUtils/SyntaxClassifier.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ fileprivate extension SyntaxProtocol {
2121
var contextualClassif: (SyntaxClassification, Bool)? = nil
2222
var curData = Syntax(self)
2323
repeat {
24-
guard let parent = curData.parent, let keyPath = curData.keyPathInParent else { break }
25-
contextualClassif = SyntaxClassification.classify(keyPath)
24+
guard let parent = curData.parent, let property = curData.propertyInParent else { break }
25+
contextualClassif = SyntaxClassification.classify(property)
2626
curData = parent
2727
} while contextualClassif == nil
2828
return contextualClassif
@@ -202,11 +202,8 @@ private struct ClassificationVisitor {
202202
for case (let index, let child?) in children.enumerated() {
203203

204204
let classification: (classification: SyntaxClassification, force: Bool)?
205-
if case .layout(let layout) = descriptor.node.kind.syntaxNodeType.structure {
206-
classification = SyntaxClassification.classify(layout[index])
207-
} else {
208-
classification = nil
209-
}
205+
let property = SyntaxLayoutProperty(baseKind: child.kind, index: .init(UInt32(index)))
206+
classification = SyntaxClassification.classify(property)
210207

211208
if let classification, classification.force {
212209
// Leading trivia.

Sources/SwiftSyntax/SyntaxLayout.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/// Represent an index in a layout.
1414
public struct SyntaxLayoutIndex: Equatable, Comparable {
1515
let value: UInt32
16-
init(_ value: UInt32) {
16+
public init(_ value: UInt32) {
1717
self.value = value
1818
}
1919
public static func == (lhs: Self, rhs: Self) -> Bool {
@@ -31,7 +31,7 @@ public struct SyntaxLayoutProperty: Equatable {
3131
/// Index in the parent node layout.
3232
let index: SyntaxLayoutIndex
3333

34-
init(baseKind: SyntaxKind, index: SyntaxLayoutIndex) {
34+
public init(baseKind: SyntaxKind, index: SyntaxLayoutIndex) {
3535
self.baseKind = baseKind
3636
self.index = index
3737
}

0 commit comments

Comments
 (0)