Skip to content
Open
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
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ var targets: [PackageDescription.Target] = [
dependencies: [
.target(name: "Configuration"),
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SystemPackage", package: "swift-system"),
.target(name: "Shared"),
]
),
Expand Down
1 change: 1 addition & 0 deletions Sources/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ swift_library(
"//Sources:Configuration",
"//Sources:Shared",
"@swift-syntax//:SwiftSyntax",
"@swift-system//:SystemPackage",
],
)

Expand Down
17 changes: 3 additions & 14 deletions Sources/PeripheryKit/Results/OutputDeclarationFilter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,9 @@ public final class OutputDeclarationFilter {
var path = $0.declaration.location.file.path

// If the declaration has a location override, use it as the path for filtering.
for command in $0.declaration.commentCommands {
switch command {
case let .override(overrides):
for override in overrides {
switch override {
case let .location(overridePath, _, _):
path = FilePath(overridePath)
default:
break
}
}
default:
break
}
if let override = $0.declaration.commentCommands.locationOverride {
let (overridePath, _, _) = override
path = FilePath(overridePath)
}

if configuration.reportIncludeMatchers.isEmpty {
Expand Down
53 changes: 9 additions & 44 deletions Sources/PeripheryKit/Results/OutputFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,8 @@ extension OutputFormatter {
func declarationKind(from declaration: Declaration) -> String {
var kind = declaration.kind.rawValue

for command in declaration.commentCommands {
switch command {
case let .override(overrides):
for override in overrides {
switch override {
case let .kind(overrideKind):
kind = overrideKind
default:
break
}
}
default:
break
}
if let overrideKind = declaration.commentCommands.kindOverride {
kind = overrideKind
}

return kind
Expand All @@ -117,20 +105,8 @@ extension OutputFormatter {
func declarationKindDisplayName(from declaration: Declaration) -> String {
var kind = declaration.kind.displayName

for command in declaration.commentCommands {
switch command {
case let .override(overrides):
for override in overrides {
switch override {
case let .kind(overrideKind):
kind = overrideKind
default:
break
}
}
default:
break
}
if let overrideKind = declaration.commentCommands.kindOverride {
kind = overrideKind
}

return kind
Expand All @@ -139,22 +115,11 @@ extension OutputFormatter {
func declarationLocation(from declaration: Declaration) -> Location {
var location = declaration.location

for command in declaration.commentCommands {
switch command {
case let .override(overrides):
for override in overrides {
switch override {
case let .location(file, line, column):
let sourceFile = SourceFile(path: FilePath(String(file)), modules: [])
let overrideLocation = Location(file: sourceFile, line: line, column: column)
location = overrideLocation
default:
break
}
}
default:
break
}
if let override = declaration.commentCommands.locationOverride {
let (path, line, column) = override
let sourceFile = SourceFile(path: FilePath(path), modules: [])
let overrideLocation = Location(file: sourceFile, line: line, column: column)
location = overrideLocation
}

return location
Expand Down
42 changes: 42 additions & 0 deletions Sources/SourceGraph/Elements/CommentCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,45 @@ public enum CommentCommand: CustomStringConvertible, Hashable {
}
}
}

public extension Sequence<CommentCommand> {
var locationOverride: (String, Int, Int)? {
for command in self {
switch command {
case let .override(overrides):
for override in overrides {
switch override {
case let .location(path, line, column):
return (path, line, column)
default:
break
}
}
default:
break
}
}

return nil
}

var kindOverride: String? {
for command in self {
switch command {
case let .override(overrides):
for override in overrides {
switch override {
case let .kind(kind):
return kind
default:
break
}
}
default:
break
}
}

return nil
}
}
20 changes: 18 additions & 2 deletions Sources/SourceGraph/Elements/Declaration.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import SystemPackage

public final class Declaration {
public enum Kind: String, RawRepresentable, CaseIterable {
Expand Down Expand Up @@ -339,11 +340,26 @@ extension Declaration: CustomStringConvertible {

extension Declaration: Comparable {
public static func < (lhs: Declaration, rhs: Declaration) -> Bool {
if lhs.location == rhs.location {
var lhsLocation = lhs.location
var rhsLocation = rhs.location

if let locationOverride = lhs.commentCommands.locationOverride {
let (path, line, column) = locationOverride
let sourceFile = SourceFile(path: FilePath(path), modules: [])
lhsLocation = Location(file: sourceFile, line: line, column: column)
}

if let locationOverride = rhs.commentCommands.locationOverride {
let (path, line, column) = locationOverride
let sourceFile = SourceFile(path: FilePath(path), modules: [])
rhsLocation = Location(file: sourceFile, line: line, column: column)
}

if lhsLocation == rhsLocation {
return lhs.usrs.sorted().joined() < rhs.usrs.sorted().joined()
}

return lhs.location < rhs.location
return lhsLocation < rhsLocation
}
}

Expand Down