Skip to content

Commit a47b90d

Browse files
committed
Move nameForDiagnostics from SyntaxEnum to SyntaxKind
1 parent 5b64d60 commit a47b90d

File tree

8 files changed

+587
-585
lines changed

8 files changed

+587
-585
lines changed

Sources/SwiftParserDiagnostics/SyntaxExtensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ extension SyntaxProtocol {
6767
if !allowBlockNames && (syntax.is(CodeBlockSyntax.self) || syntax.is(MemberDeclBlockSyntax.self)) {
6868
return nil
6969
}
70-
return syntax.as(SyntaxEnum.self).nameForDiagnostics
70+
return syntax.kind.nameForDiagnostics
7171
}
7272

7373
/// A short description of this node that can be displayed inline in a single line.

Sources/SwiftSyntax/Misc.swift.gyb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,23 @@ extension SyntaxKind {
4242
case .unknown: return UnknownSyntax.self
4343
% for node in NON_BASE_SYNTAX_NODES:
4444
case .${node.swift_syntax_kind}: return ${node.name}.self
45+
% end
46+
}
47+
}
48+
49+
public var nameForDiagnostics: String? {
50+
switch self {
51+
case .unknown:
52+
return nil
53+
case .token:
54+
return "token"
55+
% for node in NON_BASE_SYNTAX_NODES:
56+
case .${node.swift_syntax_kind}:
57+
% if node.name_for_diagnostics:
58+
return "${node.name_for_diagnostics}"
59+
% else:
60+
return nil
61+
% end
4562
% end
4663
}
4764
}

Sources/SwiftSyntax/Syntax.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ extension SyntaxProtocol {
225225
return _syntaxNode.data.raw
226226
}
227227

228+
public var kind: SyntaxKind {
229+
return raw.kind
230+
}
231+
228232
public var syntaxNodeType: SyntaxProtocol.Type {
229233
return self.raw.kind.syntaxNodeType
230234
}

Sources/SwiftSyntax/SyntaxEnum.swift.gyb

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,6 @@ public enum SyntaxEnum {
3030
case ${node.swift_syntax_kind}(${node.name})
3131
% end
3232
% end
33-
34-
public var nameForDiagnostics: String? {
35-
switch self {
36-
case .unknown:
37-
return nil
38-
case .token:
39-
return "token"
40-
% for node in NON_BASE_SYNTAX_NODES:
41-
case .${node.swift_syntax_kind}:
42-
% if node.name_for_diagnostics:
43-
return "${node.name_for_diagnostics}"
44-
% else:
45-
return nil
46-
% end
47-
% end
48-
}
49-
}
5033
}
5134

5235
public extension Syntax {

Sources/SwiftSyntax/SyntaxKind.swift.gyb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
//===----------------------------------------------------------------------===//
2020

2121
/// Enumerates the known kinds of Syntax represented in the Syntax tree.
22-
@_spi(RawSyntax)
2322
public enum SyntaxKind {
2423
case token
2524
case unknown

0 commit comments

Comments
 (0)