From 883721d1c3ca8fd4ec16bfe404804ed41ba58925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kry=C5=A1tof=20Mat=C4=9Bj?= Date: Fri, 15 Sep 2023 11:08:43 +0200 Subject: [PATCH] Update Rubicon app --- Rubicon.xcodeproj/project.pbxproj | 25 +-- .../xcshareddata/WorkspaceSettings.xcsettings | 5 + .../Sources/Rubicon/Integration/Rubicon.swift | 9 + .../Integration/SpyIntegrationTests.swift | 1 + RubiconApp/Base.lproj/Main.storyboard | 4 +- RubiconApp/ViewController.swift | 20 +-- RubiconExtension/Generate.swift | 160 +++++++++--------- RubiconExtension/IndentationFormatter.swift | 16 -- .../InvocationGeneratorOutput.swift | 8 +- .../PasteboardGeneratorOutput.swift | 71 ++++---- RubiconExtension/SourceEditorExtension.swift | 2 +- 11 files changed, 154 insertions(+), 167 deletions(-) create mode 100644 Rubicon.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings delete mode 100644 RubiconExtension/IndentationFormatter.swift diff --git a/Rubicon.xcodeproj/project.pbxproj b/Rubicon.xcodeproj/project.pbxproj index 31897e6..68c2751 100644 --- a/Rubicon.xcodeproj/project.pbxproj +++ b/Rubicon.xcodeproj/project.pbxproj @@ -7,12 +7,12 @@ objects = { /* Begin PBXBuildFile section */ - 6656B5EB2AA9F805003E6391 /* Rubicon in Frameworks */ = {isa = PBXBuildFile; productRef = 6656B5EA2AA9F805003E6391 /* Rubicon */; }; + 6647D88B2AB1CCDB0064CCEB /* Rubicon in Frameworks */ = {isa = PBXBuildFile; productRef = 6647D88A2AB1CCDB0064CCEB /* Rubicon */; }; + 6647D88D2AB1CCE00064CCEB /* Rubicon in Frameworks */ = {isa = PBXBuildFile; productRef = 6647D88C2AB1CCE00064CCEB /* Rubicon */; }; 66990B3125D4835D00F5875B /* XcodeKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BBF3D3871EC78F2B00FAB739 /* XcodeKit.framework */; }; 66990B3225D4835D00F5875B /* XcodeKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = BBF3D3871EC78F2B00FAB739 /* XcodeKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 669D6860202660CB00600E59 /* InvocationGeneratorOutput.swift in Sources */ = {isa = PBXBuildFile; fileRef = 669D685F202660CB00600E59 /* InvocationGeneratorOutput.swift */; }; 669D68622026624800600E59 /* PasteboardGeneratorOutput.swift in Sources */ = {isa = PBXBuildFile; fileRef = 669D68612026624800600E59 /* PasteboardGeneratorOutput.swift */; }; - BB0168D31EC78945001024A9 /* IndentationFormatter.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB0168D21EC78945001024A9 /* IndentationFormatter.swift */; }; BB0474341EC0609100FC2B34 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB0474331EC0609100FC2B34 /* AppDelegate.swift */; }; BB0474361EC0609100FC2B34 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB0474351EC0609100FC2B34 /* ViewController.swift */; }; BB0474381EC0609100FC2B34 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BB0474371EC0609100FC2B34 /* Assets.xcassets */; }; @@ -70,10 +70,9 @@ /* Begin PBXFileReference section */ 2C57FE2A28E5DB9700CCFB1D /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = ""; }; - 6656B5E92AA9F7E6003E6391 /* Rubicon */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = Rubicon; sourceTree = ""; }; + 6647D8892AB1CC1E0064CCEB /* Rubicon */ = {isa = PBXFileReference; lastKnownFileType = wrapper; path = Rubicon; sourceTree = ""; }; 669D685F202660CB00600E59 /* InvocationGeneratorOutput.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InvocationGeneratorOutput.swift; sourceTree = ""; }; 669D68612026624800600E59 /* PasteboardGeneratorOutput.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasteboardGeneratorOutput.swift; sourceTree = ""; }; - BB0168D21EC78945001024A9 /* IndentationFormatter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IndentationFormatter.swift; sourceTree = ""; }; BB0168D41EC789FF001024A9 /* RubiconApp.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = RubiconApp.entitlements; sourceTree = ""; }; BB0474311EC0609100FC2B34 /* Rubicon.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Rubicon.app; sourceTree = BUILT_PRODUCTS_DIR; }; BB0474331EC0609100FC2B34 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; @@ -95,7 +94,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 6656B5EB2AA9F805003E6391 /* Rubicon in Frameworks */, + 6647D88B2AB1CCDB0064CCEB /* Rubicon in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -103,6 +102,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 6647D88D2AB1CCE00064CCEB /* Rubicon in Frameworks */, 66990B3125D4835D00F5875B /* XcodeKit.framework in Frameworks */, BB0474A51EC068FA00FC2B34 /* Cocoa.framework in Frameworks */, ); @@ -114,7 +114,7 @@ 6656B5E82AA9F7E6003E6391 /* Packages */ = { isa = PBXGroup; children = ( - 6656B5E92AA9F7E6003E6391 /* Rubicon */, + 6647D8892AB1CC1E0064CCEB /* Rubicon */, ); name = Packages; sourceTree = ""; @@ -150,7 +150,6 @@ 669D68612026624800600E59 /* PasteboardGeneratorOutput.swift */, 669D685F202660CB00600E59 /* InvocationGeneratorOutput.swift */, BB0474A91EC068FA00FC2B34 /* SourceEditorExtension.swift */, - BB0168D21EC78945001024A9 /* IndentationFormatter.swift */, ); path = RubiconExtension; sourceTree = ""; @@ -204,7 +203,7 @@ ); name = RubiconApp; packageProductDependencies = ( - 6656B5EA2AA9F805003E6391 /* Rubicon */, + 6647D88A2AB1CCDB0064CCEB /* Rubicon */, ); productName = RubiconApp; productReference = BB0474311EC0609100FC2B34 /* Rubicon.app */; @@ -224,6 +223,9 @@ dependencies = ( ); name = RubiconExtension; + packageProductDependencies = ( + 6647D88C2AB1CCE00064CCEB /* Rubicon */, + ); productName = RubiconExtension; productReference = BB0474A21EC068FA00FC2B34 /* Rubicon.appex */; productType = "com.apple.product-type.xcode-extension"; @@ -314,7 +316,6 @@ files = ( 669D6860202660CB00600E59 /* InvocationGeneratorOutput.swift in Sources */, BB0474AA1EC068FA00FC2B34 /* SourceEditorExtension.swift in Sources */, - BB0168D31EC78945001024A9 /* IndentationFormatter.swift in Sources */, 669D68622026624800600E59 /* PasteboardGeneratorOutput.swift in Sources */, BB0474AC1EC068FA00FC2B34 /* Generate.swift in Sources */, ); @@ -618,7 +619,11 @@ /* End XCConfigurationList section */ /* Begin XCSwiftPackageProductDependency section */ - 6656B5EA2AA9F805003E6391 /* Rubicon */ = { + 6647D88A2AB1CCDB0064CCEB /* Rubicon */ = { + isa = XCSwiftPackageProductDependency; + productName = Rubicon; + }; + 6647D88C2AB1CCE00064CCEB /* Rubicon */ = { isa = XCSwiftPackageProductDependency; productName = Rubicon; }; diff --git a/Rubicon.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings b/Rubicon.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings new file mode 100644 index 0000000..0c67376 --- /dev/null +++ b/Rubicon.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings @@ -0,0 +1,5 @@ + + + + + diff --git a/Rubicon/Sources/Rubicon/Integration/Rubicon.swift b/Rubicon/Sources/Rubicon/Integration/Rubicon.swift index c9da894..e92dc48 100644 --- a/Rubicon/Sources/Rubicon/Integration/Rubicon.swift +++ b/Rubicon/Sources/Rubicon/Integration/Rubicon.swift @@ -148,4 +148,13 @@ public final class Rubicon { ) } + public func updateTearDown(text: String, spacing: Int) throws -> String { + let parser = NilableVariablesParserImpl() + let tearDownInteractor = TearDownInteractor(nilableVariablesParser: parser) + return try tearDownInteractor.execute(text: text, spacing: spacing) + } + + func x() { + Rubicon().makeSpy(code: <#T##String#>, accessLevel: <#T##AccessLevel#>, indentStep: <#T##String#>) + } } diff --git a/Rubicon/Tests/RubiconTests/Integration/SpyIntegrationTests.swift b/Rubicon/Tests/RubiconTests/Integration/SpyIntegrationTests.swift index 7a4717d..d621860 100644 --- a/Rubicon/Tests/RubiconTests/Integration/SpyIntegrationTests.swift +++ b/Rubicon/Tests/RubiconTests/Integration/SpyIntegrationTests.swift @@ -8,6 +8,7 @@ final class SpyIntegrationTests: XCTestCase { var name: String? { get } var color: Int { get set } + @MainActor func go() func load(with stuff: Int, label: String) throws -> Int func isFull(validate: @escaping () -> Void) -> Bool diff --git a/RubiconApp/Base.lproj/Main.storyboard b/RubiconApp/Base.lproj/Main.storyboard index 0e330ca..cba94ac 100644 --- a/RubiconApp/Base.lproj/Main.storyboard +++ b/RubiconApp/Base.lproj/Main.storyboard @@ -1,8 +1,8 @@ - + - + diff --git a/RubiconApp/ViewController.swift b/RubiconApp/ViewController.swift index 981bc90..9d3ca1a 100644 --- a/RubiconApp/ViewController.swift +++ b/RubiconApp/ViewController.swift @@ -9,31 +9,19 @@ import Cocoa import Rubicon -class ViewController: NSViewController, GeneratorOutput { +class ViewController: NSViewController { @IBOutlet weak var sourceTextField: NSTextView! @IBOutlet var resultLabel: NSTextView! @IBAction func generateSpy(_ sender: Any) { - let spyMocksController = MocksGeneratorControllerImpl(output: self, interactor: CreateSpyInteractor(accessLevel: .internal)) - let texts = [sourceTextField.string] - spyMocksController.run(texts: texts) + resultLabel.string = Rubicon().makeSpy(code: sourceTextField.string, accessLevel: .internal, indentStep: " ").joined(separator: "\n\n") } @IBAction func generateStub(_ sender: Any) { - let spyMocksController = MocksGeneratorControllerImpl(output: self, interactor: CreateStubInteractor(accessLevel: .internal)) - let texts = [sourceTextField.string] - spyMocksController.run(texts: texts) + resultLabel.string = Rubicon().makeStub(code: sourceTextField.string, accessLevel: .internal, indentStep: " ").joined(separator: "\n\n") } @IBAction func generateDummy(_ sender: Any) { - let spyMocksController = MocksGeneratorControllerImpl(output: self, interactor: CreateDummyInteractor(accessLevel: .internal)) - let texts = [sourceTextField.string] - spyMocksController.run(texts: texts) - } - - // MARK: - GeneratorOutput - - func save(text: String) { - resultLabel.string = text + resultLabel.string = Rubicon().makeDummy(code: sourceTextField.string, accessLevel: .internal, indentStep: " ").joined(separator: "\n\n") } } diff --git a/RubiconExtension/Generate.swift b/RubiconExtension/Generate.swift index 7cca30a..40e8434 100644 --- a/RubiconExtension/Generate.swift +++ b/RubiconExtension/Generate.swift @@ -12,58 +12,56 @@ import XcodeKit class Generate: NSObject, XCSourceEditorCommand { fileprivate var invocation: XCSourceEditorCommandInvocation? - private var output: GeneratorOutput? - func perform(with invocation: XCSourceEditorCommandInvocation, completionHandler: @escaping (Error?) -> Void) { switch invocation.commandIdentifier { - case "GeneratePrivateSpy": - let output = InvocationGeneratorOutput(invocation: invocation) - let createMockInteractor = CreateSpyInteractor(accessLevel: .private) - perform(with: invocation, generatorOutput: output, createMockInteractor: createMockInteractor, completionHandler: completionHandler) - case "GenerateSpy": - let output = InvocationGeneratorOutput(invocation: invocation) - let createMockInteractor = CreateSpyInteractor(accessLevel: .internal) - perform(with: invocation, generatorOutput: output, createMockInteractor: createMockInteractor, completionHandler: completionHandler) - case "GeneratePublicSpy": - let output = InvocationGeneratorOutput(invocation: invocation) - let createMockInteractor = CreateSpyInteractor(accessLevel: .public) - perform(with: invocation, generatorOutput: output, createMockInteractor: createMockInteractor, completionHandler: completionHandler) - case "GenerateSpyToPasteboard": - let output = PasteboardGeneratorOutput(invocation: invocation) - let createMockInteractor = CreateSpyInteractor(accessLevel: .internal) - perform(with: invocation, generatorOutput: output, createMockInteractor: createMockInteractor, completionHandler: completionHandler) - case "GeneratePrivateStub": - let output = InvocationGeneratorOutput(invocation: invocation) - let createMockInteractor = CreateStubInteractor(accessLevel: .private) - perform(with: invocation, generatorOutput: output, createMockInteractor: createMockInteractor, completionHandler: completionHandler) - case "GenerateStub": - let output = InvocationGeneratorOutput(invocation: invocation) - let createMockInteractor = CreateStubInteractor(accessLevel: .internal) - perform(with: invocation, generatorOutput: output, createMockInteractor: createMockInteractor, completionHandler: completionHandler) - case "GeneratePublicStub": - let output = InvocationGeneratorOutput(invocation: invocation) - let createMockInteractor = CreateStubInteractor(accessLevel: .public) - perform(with: invocation, generatorOutput: output, createMockInteractor: createMockInteractor, completionHandler: completionHandler) - case "GenerateStubToPasteboard": - let output = PasteboardGeneratorOutput(invocation: invocation) - let createMockInteractor = CreateStubInteractor(accessLevel: .internal) - perform(with: invocation, generatorOutput: output, createMockInteractor: createMockInteractor, completionHandler: completionHandler) - case "GeneratePrivateDummy": - let output = InvocationGeneratorOutput(invocation: invocation) - let createMockInteractor = CreateDummyInteractor(accessLevel: .private) - perform(with: invocation, generatorOutput: output, createMockInteractor: createMockInteractor, completionHandler: completionHandler) - case "GenerateDummy": - let output = InvocationGeneratorOutput(invocation: invocation) - let createMockInteractor = CreateDummyInteractor(accessLevel: .internal) - perform(with: invocation, generatorOutput: output, createMockInteractor: createMockInteractor, completionHandler: completionHandler) - case "GeneratePublicDummy": - let output = InvocationGeneratorOutput(invocation: invocation) - let createMockInteractor = CreateDummyInteractor(accessLevel: .public) - perform(with: invocation, generatorOutput: output, createMockInteractor: createMockInteractor, completionHandler: completionHandler) - case "GenerateDummyToPasteboard": - let output = PasteboardGeneratorOutput(invocation: invocation) - let createMockInteractor = CreateDummyInteractor(accessLevel: .internal) - perform(with: invocation, generatorOutput: output, createMockInteractor: createMockInteractor, completionHandler: completionHandler) +// case "GeneratePrivateSpy": +// let output = InvocationGeneratorOutput(invocation: invocation) +// let createMockInteractor = CreateSpyInteractor(accessLevel: .private) +// perform(with: invocation, generatorOutput: output, createMockInteractor: createMockInteractor, completionHandler: completionHandler) +// case "GenerateSpy": +// let output = InvocationGeneratorOutput(invocation: invocation) +// let createMockInteractor = CreateSpyInteractor(accessLevel: .internal) +// perform(with: invocation, generatorOutput: output, createMockInteractor: createMockInteractor, completionHandler: completionHandler) +// case "GeneratePublicSpy": +// let output = InvocationGeneratorOutput(invocation: invocation) +// let createMockInteractor = CreateSpyInteractor(accessLevel: .public) +// perform(with: invocation, generatorOutput: output, createMockInteractor: createMockInteractor, completionHandler: completionHandler) +// case "GenerateSpyToPasteboard": +// let output = PasteboardGeneratorOutput(invocation: invocation) +// let createMockInteractor = CreateSpyInteractor(accessLevel: .internal) +// perform(with: invocation, generatorOutput: output, createMockInteractor: createMockInteractor, completionHandler: completionHandler) +// case "GeneratePrivateStub": +// let output = InvocationGeneratorOutput(invocation: invocation) +// let createMockInteractor = CreateStubInteractor(accessLevel: .private) +// perform(with: invocation, generatorOutput: output, createMockInteractor: createMockInteractor, completionHandler: completionHandler) +// case "GenerateStub": +// let output = InvocationGeneratorOutput(invocation: invocation) +// let createMockInteractor = CreateStubInteractor(accessLevel: .internal) +// perform(with: invocation, generatorOutput: output, createMockInteractor: createMockInteractor, completionHandler: completionHandler) +// case "GeneratePublicStub": +// let output = InvocationGeneratorOutput(invocation: invocation) +// let createMockInteractor = CreateStubInteractor(accessLevel: .public) +// perform(with: invocation, generatorOutput: output, createMockInteractor: createMockInteractor, completionHandler: completionHandler) +// case "GenerateStubToPasteboard": +// let output = PasteboardGeneratorOutput(invocation: invocation) +// let createMockInteractor = CreateStubInteractor(accessLevel: .internal) +// perform(with: invocation, generatorOutput: output, createMockInteractor: createMockInteractor, completionHandler: completionHandler) +// case "GeneratePrivateDummy": +// let output = InvocationGeneratorOutput(invocation: invocation) +// let createMockInteractor = CreateDummyInteractor(accessLevel: .private) +// perform(with: invocation, generatorOutput: output, createMockInteractor: createMockInteractor, completionHandler: completionHandler) +// case "GenerateDummy": +// let output = InvocationGeneratorOutput(invocation: invocation) +// let createMockInteractor = CreateDummyInteractor(accessLevel: .internal) +// perform(with: invocation, generatorOutput: output, createMockInteractor: createMockInteractor, completionHandler: completionHandler) +// case "GeneratePublicDummy": +// let output = InvocationGeneratorOutput(invocation: invocation) +// let createMockInteractor = CreateDummyInteractor(accessLevel: .public) +// perform(with: invocation, generatorOutput: output, createMockInteractor: createMockInteractor, completionHandler: completionHandler) +// case "GenerateDummyToPasteboard": +// let output = PasteboardGeneratorOutput(invocation: invocation) +// let createMockInteractor = CreateDummyInteractor(accessLevel: .internal) +// perform(with: invocation, generatorOutput: output, createMockInteractor: createMockInteractor, completionHandler: completionHandler) case "AddTearDownMethod": processTearDown(with: invocation, completionHandler: completionHandler) default: @@ -71,28 +69,28 @@ class Generate: NSObject, XCSourceEditorCommand { } } - private func perform(with invocation: XCSourceEditorCommandInvocation, generatorOutput: GeneratorOutput, createMockInteractor: CreateMockInteractor, completionHandler: @escaping (Error?) -> Void) { - self.invocation = invocation - - guard var lines = invocation.buffer.lines as? [String] else { - fatalError("not lines: \(invocation.buffer.lines)") - } - - if invocation.buffer.selections.count == 1, let range = invocation.buffer.selections.firstObject as? XCSourceTextRange { - if isEmptyRange(range) { - let start = range.start.line - let end = range.end.column == 0 ? max(range.end.line - 1, 0) : range.end.line - lines = Array(lines[start ... end]) - } - } - - let text = lines.joined() - - output = generatorOutput - let mocksController = MocksGeneratorControllerImpl(output: generatorOutput, interactor: createMockInteractor) - mocksController.run(texts: [text]) - completionHandler(nil) - } +// private func perform(with invocation: XCSourceEditorCommandInvocation, generatorOutput: GeneratorOutput, createMockInteractor: CreateMockInteractor, completionHandler: @escaping (Error?) -> Void) { +// self.invocation = invocation +// +// guard var lines = invocation.buffer.lines as? [String] else { +// fatalError("not lines: \(invocation.buffer.lines)") +// } +// +// if invocation.buffer.selections.count == 1, let range = invocation.buffer.selections.firstObject as? XCSourceTextRange { +// if isEmptyRange(range) { +// let start = range.start.line +// let end = range.end.column == 0 ? max(range.end.line - 1, 0) : range.end.line +// lines = Array(lines[start ... end]) +// } +// } +// +// let text = lines.joined() +// +// output = generatorOutput +// let mocksController = MocksGeneratorControllerImpl(output: generatorOutput, interactor: createMockInteractor) +// mocksController.run(texts: [text]) +// completionHandler(nil) +// } private func processTearDown(with invocation: XCSourceEditorCommandInvocation, completionHandler: @escaping (Error?) -> Void) { guard let lines = invocation.buffer.lines as? [String] else { @@ -100,17 +98,17 @@ class Generate: NSObject, XCSourceEditorCommand { return } - let interactor = TearDownInteractor(nilableVariablesParser: NilableVariablesParserImpl()) + let text = lines.joined() - do { - let newFile = try interactor.execute(text: text, spacing: invocation.buffer.indentationWidth) - invocation.buffer.lines.removeAllObjects() - invocation.buffer.lines.addObjects(from: newFile.components(separatedBy: "\n").dropLast()) - completionHandler(nil) - } catch { - completionHandler(error) - } +// do { +// let newFile = try Rubicon().updateTearDown(text: text, spacing: invocation.buffer.indentationWidth) +// invocation.buffer.lines.removeAllObjects() +// invocation.buffer.lines.addObjects(from: newFile.components(separatedBy: "\n").dropLast()) +// completionHandler(nil) +// } catch { +// completionHandler(error) +// } } private func isEmptyRange(_ range: XCSourceTextRange) -> Bool { diff --git a/RubiconExtension/IndentationFormatter.swift b/RubiconExtension/IndentationFormatter.swift deleted file mode 100644 index ee2f9d7..0000000 --- a/RubiconExtension/IndentationFormatter.swift +++ /dev/null @@ -1,16 +0,0 @@ -// -// IndentationFormatter.swift -// Rubicon -// -// Created by Kryštof Matěj on 13/05/2017. -// Copyright © 2017 Kryštof Matěj. All rights reserved. -// - -public class IndentationFormatter { - - public init() {} - - public func format(indent: String, string: String) -> String { - return string.replacingOccurrences(of: "\t", with: indent) - } -} diff --git a/RubiconExtension/InvocationGeneratorOutput.swift b/RubiconExtension/InvocationGeneratorOutput.swift index a1cdc7a..7658f16 100644 --- a/RubiconExtension/InvocationGeneratorOutput.swift +++ b/RubiconExtension/InvocationGeneratorOutput.swift @@ -10,9 +10,7 @@ import Foundation import Rubicon import XcodeKit -class InvocationGeneratorOutput: GeneratorOutput { - - private let indentFormatter = IndentationFormatter() +class InvocationGeneratorOutput { private let invocation: XCSourceEditorCommandInvocation private lazy var indent: String = { let buffer = self.invocation.buffer @@ -36,7 +34,7 @@ class InvocationGeneratorOutput: GeneratorOutput { } func save(text: String) { - let lines = indentFormatter.format(indent: indent, string: text).components(separatedBy: "\n") - invocation.buffer.lines.addObjects(from: lines) + +// invocation.buffer.lines.addObjects(from: lines) } } diff --git a/RubiconExtension/PasteboardGeneratorOutput.swift b/RubiconExtension/PasteboardGeneratorOutput.swift index f7f93a8..37f6589 100644 --- a/RubiconExtension/PasteboardGeneratorOutput.swift +++ b/RubiconExtension/PasteboardGeneratorOutput.swift @@ -6,39 +6,38 @@ // Copyright © 2018 Kryštof Matěj. All rights reserved. // -import Foundation -import Rubicon -import XcodeKit - -class PasteboardGeneratorOutput: GeneratorOutput { - - private let indentFormatter = IndentationFormatter() - private let invocation: XCSourceEditorCommandInvocation - private lazy var indent: String = { - let buffer = self.invocation.buffer - var indent: String = "" - - if buffer.usesTabsForIndentation { - for _ in 0 ..< buffer.tabWidth { - indent += "\t" - } - } else { - for _ in 0 ..< buffer.indentationWidth { - indent += " " - } - } - - return indent - }() - - init(invocation: XCSourceEditorCommandInvocation) { - self.invocation = invocation - } - - func save(text: String) { - let lines = indentFormatter.format(indent: indent, string: text) - NSPasteboard.general.clearContents() - NSPasteboard.general.declareTypes([.string], owner: nil) - NSPasteboard.general.setString(lines, forType: .string) - } -} +//import Foundation +//import Rubicon +//import XcodeKit +// +//class PasteboardGeneratorOutput { +// private let indentFormatter = IndentationFormatter() +// private let invocation: XCSourceEditorCommandInvocation +// private lazy var indent: String = { +// let buffer = self.invocation.buffer +// var indent: String = "" +// +// if buffer.usesTabsForIndentation { +// for _ in 0 ..< buffer.tabWidth { +// indent += "\t" +// } +// } else { +// for _ in 0 ..< buffer.indentationWidth { +// indent += " " +// } +// } +// +// return indent +// }() +// +// init(invocation: XCSourceEditorCommandInvocation) { +// self.invocation = invocation +// } +// +// func save(text: String) { +// let lines = indentFormatter.format(indent: indent, string: text) +// NSPasteboard.general.clearContents() +// NSPasteboard.general.declareTypes([.string], owner: nil) +// NSPasteboard.general.setString(lines, forType: .string) +// } +//} diff --git a/RubiconExtension/SourceEditorExtension.swift b/RubiconExtension/SourceEditorExtension.swift index 789bb16..358cc39 100644 --- a/RubiconExtension/SourceEditorExtension.swift +++ b/RubiconExtension/SourceEditorExtension.swift @@ -9,4 +9,4 @@ import Foundation import XcodeKit -class SourceEditorExtension: NSObject, XCSourceEditorExtension {} +final class SourceEditorExtension: NSObject, XCSourceEditorExtension {}