Skip to content

Commit 24f2d4f

Browse files
committed
Added macro
1 parent 02a5e5a commit 24f2d4f

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

Sources/SwiftDocCoverage/DeclProtocol.swift

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,21 @@ public enum AccessLevel: Int {
4848
}
4949

5050
protocol DeclProtocol: SyntaxProtocol {
51-
var id: String { get }
51+
52+
// `attributes`: ``AttributeListSyntax``
5253
var modifiers: DeclModifierListSyntax { get }
54+
// `classKeyword`: `'class'`
55+
//var name: TokenSyntax { get }
56+
// `genericParameterClause`: ``GenericParameterClauseSyntax``?
57+
// `inheritanceClause`: ``InheritanceClauseSyntax``?
58+
// `genericWhereClause`: ``GenericWhereClauseSyntax``?
59+
// `memberBlock`: ``MemberBlockSyntax``
60+
61+
var id: String { get }
5362
}
5463

5564
extension DeclProtocol {
56-
65+
5766
var comments: [Comment] {
5867
return leadingTrivia.compactMap {
5968
switch $0 {
@@ -136,6 +145,10 @@ extension ExtensionDeclSyntax: DeclProtocol {
136145
var id: String {
137146
extendedType.trimmed.description
138147
}
148+
149+
var name: TokenSyntax {
150+
TokenSyntax(.identifier(extendedType.trimmedDescription), presence: .present)
151+
}
139152
}
140153

141154
extension FunctionDeclSyntax: DeclProtocol {
@@ -188,3 +201,10 @@ extension PrecedenceGroupDeclSyntax: DeclProtocol {
188201
"\(precedencegroupKeyword.trimmed) \(name.trimmed)"
189202
}
190203
}
204+
205+
extension MacroDeclSyntax: DeclProtocol {
206+
var id: String {
207+
let generic = genericParameterClause?.trimmed.description ?? ""
208+
return "\(name.trimmed)\(generic)\(signature.trimmed)"
209+
}
210+
}

Sources/SwiftDocCoverage/Declaration.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ import SwiftSyntax
2626

2727
fileprivate extension String {
2828

29-
static let regexNewLine = try! NSRegularExpression(pattern: "\\n\\s+", options: [])
29+
static let regexNewLine = try! NSRegularExpression(pattern: #"\n\s*"#, options: [])
3030

3131
func refine() -> String {
3232
let range = NSRange(startIndex..., in: self)
33-
return Self.regexNewLine.stringByReplacingMatches(in: self, options: [], range: range, withTemplate: " ")
33+
return Self.regexNewLine.stringByReplacingMatches(in: self, options: [], range: range, withTemplate: "")
3434
}
3535
}
3636

Sources/SwiftDocCoverage/Source.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ fileprivate class Visitor: SyntaxVisitor {
4545
}
4646

4747
let startLocation = decl.startLocation(converter: converter, afterLeadingTrivia: true)
48-
let declaration = Declaration(decl: decl,
49-
context: context,
50-
line: startLocation.line,
51-
column: startLocation.column)
48+
let declaration = Declaration(decl: decl, context: context, line: startLocation.line, column: startLocation.column)
5249
declarations.append(declaration)
5350
}
5451

@@ -143,6 +140,11 @@ fileprivate class Visitor: SyntaxVisitor {
143140
return .skipChildren
144141
}
145142

143+
override func visit(_ node: MacroDeclSyntax) -> SyntaxVisitorContinueKind {
144+
append(decl: node)
145+
return .skipChildren
146+
}
147+
146148
// MARK: -
147149

148150
override func visitPost(_ node: ClassDeclSyntax) {

0 commit comments

Comments
 (0)