Skip to content

Commit

Permalink
Accept code suggestions and reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
bok- committed Jul 14, 2024
1 parent 76981c7 commit 6d6e556
Show file tree
Hide file tree
Showing 14 changed files with 152 additions and 175 deletions.
49 changes: 0 additions & 49 deletions Sources/Vexil/Decorator.swift

This file was deleted.

23 changes: 10 additions & 13 deletions Sources/Vexil/Snapshots/MutableFlagContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,13 @@ extension MutableFlagContainer: Hashable where Container: Hashable {

// MARK: - Debugging

// extension MutableFlagContainer: CustomDebugStringConvertible {
// public var debugDescription: String {
// "\(String(describing: Group.self))("
// + Mirror(reflecting: group).children
// .map { _, value -> String in
// (value as? CustomDebugStringConvertible)?.debugDescription
// ?? (value as? CustomStringConvertible)?.description
// ?? String(describing: value)
// }
// .joined(separator: ", ")
// + ")"
// }
// }
extension MutableFlagContainer: CustomDebugStringConvertible {
public var debugDescription: String {
let describer = FlagDescriber()
container.walk(visitor: describer)
return "\(String(describing: Container.self))("
+ describer.descriptions.joined(separator: ", ")
+ ")"
}
}

23 changes: 10 additions & 13 deletions Sources/Vexil/Snapshots/Snapshot+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,13 @@ extension Snapshot: Hashable where RootGroup: Hashable {
}
}

// extension Snapshot: CustomDebugStringConvertible {
// public var debugDescription: String {
// "Snapshot<\(String(describing: RootGroup.self)), \(values.count) overrides>("
// + Mirror(reflecting: rootGroup).children
// .map { _, value -> String in
// (value as? CustomDebugStringConvertible)?.debugDescription
// ?? (value as? CustomStringConvertible)?.description
// ?? String(describing: value)
// }
// .joined(separator: "; ")
// + ")"
// }
// }
extension Snapshot: CustomDebugStringConvertible {
public var debugDescription: String {
let describer = FlagDescriber()
rootGroup.walk(visitor: describer)
let count = values.withLock { $0.count }
return "Snapshot<\(String(describing: RootGroup.self)), \(count) overrides>("
+ describer.descriptions.joined(separator: "; ")
+ ")"
}
}
32 changes: 32 additions & 0 deletions Sources/Vexil/Visitors/FlagDescriber.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the Vexil open source project
//
// Copyright (c) 2024 Unsigned Apps and the open source contributors.
// Licensed under the MIT license
//
// See LICENSE for license information
//
// SPDX-License-Identifier: MIT
//
//===----------------------------------------------------------------------===//

final class FlagDescriber: FlagVisitor {

var descriptions = [String]()

func visitFlag<Value>(
keyPath: FlagKeyPath,
value: () -> Value?,
defaultValue: Value,
wigwag: () -> FlagWigwag<Value>
) where Value: FlagValue {
let value = value()
let description = (value as? CustomDebugStringConvertible)?.debugDescription
?? (value as? CustomStringConvertible)?.description
?? String(describing: value)
descriptions.append("\(keyPath.key)=\(description)")
}

}

5 changes: 1 addition & 4 deletions Sources/VexilMacros/FlagContainerMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,8 @@ private extension DeclModifierListSyntax {
private extension TypeSyntax {
var identifier: String? {
for token in tokens(viewMode: .all) {
switch token.tokenKind {
case let .identifier(identifier):
if case let .identifier(identifier) = token.tokenKind {
return identifier
default:
break
}
}
return nil
Expand Down
7 changes: 4 additions & 3 deletions Sources/VexilMacros/FlagGroupMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,10 @@ private extension FlagGroupMacro {
let stringLiteral = functionCall.arguments.first?.expression.as(StringLiteralExprSyntax.self),
let string = stringLiteral.segments.first?.as(StringSegmentSyntax.self)
{
switch memberAccess.declName.baseName.text {
case "customKey": self = .customKey(string.content.text)
default: return nil
if case "customKey" = memberAccess.declName.baseName.text {
self = .customKey(string.content.text)
} else {
return nil
}

} else {
Expand Down
2 changes: 1 addition & 1 deletion Sources/VexilMacros/FlagMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private extension AttributeSyntax.Arguments {
}

// Support for the single description property overload, ie @Flag("description")
if case .argumentList(let list) = self, list.count == 1, let argument = list.first, argument.label == nil {
if case let .argumentList(list) = self, list.count == 1, let argument = list.first, argument.label == nil {
return argument
}

Expand Down
16 changes: 9 additions & 7 deletions Sources/VexilMacros/Utilities/PatternBindingSyntax.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,17 @@ extension PatternBindingSyntax {
} else if let function = initializer.value.as(FunctionCallExprSyntax.self) {
if let identifier = function.calledExpression.as(DeclReferenceExprSyntax.self) {
return TypeSyntax(IdentifierTypeSyntax(name: identifier.baseName))
} else if let memberAccess = function.calledExpression.as(MemberAccessExprSyntax.self) {
if let identifier = memberAccess.base?.as(DeclReferenceExprSyntax.self) {
return TypeSyntax(IdentifierTypeSyntax(name: identifier.baseName))
}
}
} else if let memberAccess = initializer.value.as(MemberAccessExprSyntax.self) {
if let identifier = memberAccess.base?.as(DeclReferenceExprSyntax.self) {
} else if
let memberAccess = function.calledExpression.as(MemberAccessExprSyntax.self),
let identifier = memberAccess.base?.as(DeclReferenceExprSyntax.self)
{
return TypeSyntax(IdentifierTypeSyntax(name: identifier.baseName))
}
} else if
let memberAccess = initializer.value.as(MemberAccessExprSyntax.self),
let identifier = memberAccess.base?.as(DeclReferenceExprSyntax.self)
{
return TypeSyntax(IdentifierTypeSyntax(name: identifier.baseName))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// This source file is part of the Vexil open source project
//
// Copyright (c) 2023 Unsigned Apps and the open source contributors.
// Copyright (c) 2024 Unsigned Apps and the open source contributors.
// Licensed under the MIT license
//
// See LICENSE for license information
Expand Down Expand Up @@ -38,48 +38,48 @@ struct CaseIterableFlagControl<Value>: View where Value: FlagValue, Value: CaseI

var content: some View {
HStack {
Text(self.label).font(.headline)
Text(label).font(.headline)
Spacer()
FlagDisplayValueView(value: self.value)
FlagDisplayValueView(value: value)
}
}

#if os(iOS)

var body: some View {
HStack {
if self.isEditable {
NavigationLink(destination: self.selector) {
self.content
if isEditable {
NavigationLink(destination: selector) {
content
}
} else {
self.content
content
}
DetailButton(hasChanges: self.hasChanges, showDetail: self.$showDetail)
DetailButton(hasChanges: hasChanges, showDetail: $showDetail)
}
}

var selector: some View {
SelectorList(value: self.$value)
.navigationBarTitle(Text(self.label), displayMode: .inline)
SelectorList(value: $value)
.navigationBarTitle(Text(label), displayMode: .inline)
}

#elseif os(macOS)

var body: some View {
Group {
if self.isEditable {
self.picker
if isEditable {
picker
} else {
self.content
content
}
}
}

var picker: some View {
let picker = Picker(
selection: self.$value,
label: Text(self.label),
selection: $value,
label: Text(label),
content: {
ForEach(Value.allCases, id: \.self) { value in
FlagDisplayValueView(value: value)
Expand Down Expand Up @@ -114,7 +114,7 @@ struct CaseIterableFlagControl<Value>: View where Value: FlagValue, Value: CaseI
Button(
action: {
self.value = value
self.presentationMode.wrappedValue.dismiss()
presentationMode.wrappedValue.dismiss()
},
label: {
HStack {
Expand All @@ -123,7 +123,7 @@ struct CaseIterableFlagControl<Value>: View where Value: FlagValue, Value: CaseI
Spacer()

if value == self.value {
self.checkmark
checkmark
}
}
}
Expand All @@ -135,13 +135,13 @@ struct CaseIterableFlagControl<Value>: View where Value: FlagValue, Value: CaseI
#if os(macOS)

var checkmark: some View {
return Text("")
Text("")
}

#else

var checkmark: some View {
return Image(systemName: "checkmark")
Image(systemName: "checkmark")
}

#endif
Expand All @@ -160,8 +160,8 @@ extension UnfurledFlag: CaseIterableEditableFlag
where Value: FlagValue, Value: CaseIterable, Value.AllCases: RandomAccessCollection,
Value: RawRepresentable, Value.RawValue: FlagValue, Value: Hashable
{
func control<RootGroup>(label: String, manager: FlagValueManager<RootGroup>, showDetail: Binding<Bool>) -> AnyView where RootGroup: FlagContainer {
return CaseIterableFlagControl<Value>(
func control(label: String, manager: FlagValueManager<some FlagContainer>, showDetail: Binding<Bool>) -> AnyView {
CaseIterableFlagControl<Value>(
label: label,
value: Binding(
key: flag.key,
Expand Down
Loading

0 comments on commit 6d6e556

Please sign in to comment.