Skip to content

Commit c6a8f8c

Browse files
FastestMolassesmatthijseikelenboomthecoolwinter
authored
Clean Up Code (#1737)
* Cleaning up code * Removed unnecessary line * Update SettingsView.swift * Update Package.resolved * Remove commented line * Optimize .map * Naming fixes * Move Acknowledgements and Contributors folder under the About folder * Fix comment * Updated fileManager variable to a normal variable instead of a computed one * Rearranged files in the Git folder * Fix All Warnings, Use Non-Optional String * Revert One String Decode * Upgrade Introspect Dependency, Remove Final Warnings * Fix Introspect Error * Reordered some files in the Editor feature folder * Removed extensions folder in CEWorkspace feature folder * Longer Autosave Debounce --------- Co-authored-by: Matthijs Eikelenboom <matthijs697@live.nl> Co-authored-by: Khan Winter <35942988+thecoolwinter@users.noreply.github.com>
1 parent 7513e1b commit c6a8f8c

File tree

53 files changed

+164
-213
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+164
-213
lines changed

.swiftlint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ identifier_name:
1515
# paths to ignore during linting.
1616
excluded:
1717
- CodeEditModules/.build # Where Swift Package Manager checks out dependency sources
18-
- DerivedData
18+
- DerivedData
1919

2020
opt_in_rules:
2121
- attributes

CodeEdit.xcodeproj/project.pbxproj

Lines changed: 91 additions & 96 deletions
Large diffs are not rendered by default.

CodeEdit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"originHash" : "41fcbec1ecbb7853d9ead798bba9d46f35f28767f4d41a009c8eeee022e99a84",
2+
"originHash" : "f3dd40f19b32a2b522dee7a1e94ceb60afbdb1a028938883adffc7328ef9d804",
33
"pins" : [
44
{
55
"identity" : "anycodable",
@@ -15,8 +15,8 @@
1515
"kind" : "remoteSourceControl",
1616
"location" : "https://github.com/CodeEditApp/CodeEditKit",
1717
"state" : {
18-
"revision" : "bf76c0240589a38b504a703363ab85fcedfbc732",
19-
"version" : "0.1.1"
18+
"revision" : "ad28213a968586abb0cb21a8a56a3587227895f1",
19+
"version" : "0.1.2"
2020
}
2121
},
2222
{
@@ -123,8 +123,8 @@
123123
"kind" : "remoteSourceControl",
124124
"location" : "https://github.com/apple/swift-collections.git",
125125
"state" : {
126-
"revision" : "94cf62b3ba8d4bed62680a282d4c25f9c63c2efb",
127-
"version" : "1.1.0"
126+
"revision" : "ee97538f5b81ae89698fd95938896dec5217b148",
127+
"version" : "1.1.1"
128128
}
129129
},
130130
{
@@ -150,8 +150,8 @@
150150
"kind" : "remoteSourceControl",
151151
"location" : "https://github.com/lukepistrol/SwiftLintPlugin",
152152
"state" : {
153-
"revision" : "ea6d3ca895b49910f790e98e4b4ca658e0fe490e",
154-
"version" : "0.54.0"
153+
"revision" : "a0f7b12c7be228592d924f29f654ebbd924ac9c5",
154+
"version" : "0.55.1"
155155
}
156156
},
157157
{
@@ -175,10 +175,10 @@
175175
{
176176
"identity" : "swiftui-introspect",
177177
"kind" : "remoteSourceControl",
178-
"location" : "https://github.com/siteline/SwiftUI-Introspect",
178+
"location" : "https://github.com/siteline/SwiftUI-Introspect.git",
179179
"state" : {
180-
"revision" : "121c146fe591b1320238d054ae35c81ffa45f45a",
181-
"version" : "0.12.0"
180+
"revision" : "668a65735751432b640260c56dfa621cec568368",
181+
"version" : "1.2.0"
182182
}
183183
},
184184
{

CodeEdit.xcodeproj/xcshareddata/xcschemes/CodeEdit.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1430"
3+
LastUpgradeVersion = "1540"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

CodeEdit/AppDelegate.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,7 @@ final class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {
117117

118118
func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
119119
let projects: [String] = CodeEditDocumentController.shared.documents
120-
.map { doc in
121-
(doc as? WorkspaceDocument)?.fileURL?.path
122-
}
123-
.filter { $0 != nil }
124-
.map { $0! }
120+
.compactMap { ($0 as? WorkspaceDocument)?.fileURL?.path }
125121

126122
UserDefaults.standard.set(projects, forKey: AppDelegate.recoverWorkspacesKey)
127123

CodeEdit/CodeEditApp.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ struct CodeEditApp: App {
1212
@NSApplicationDelegateAdaptor var appdelegate: AppDelegate
1313
@ObservedObject var settings = Settings.shared
1414

15-
@Environment(\.openWindow)
16-
var openWindow
17-
1815
let updater: SoftwareUpdater = SoftwareUpdater()
1916

2017
init() {

CodeEdit/Features/CodeEditUI/Views/EffectView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// BlurView.swift
2+
// EffectView.swift
33
// CodeEditModules/CodeEditUI
44
//
55
// Created by Rehatbir Singh on 15/03/2022.

CodeEdit/Features/CodeEditUI/Views/KeyValueTable.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ private struct NewListTableItemView: View {
7575
.disabled(key.isEmpty || value.isEmpty)
7676
}
7777
.padding(.horizontal, 20)
78-
// .padding(.top, 2)
7978
.padding(.bottom, 20)
8079
}
8180
.frame(maxWidth: 480)

CodeEdit/Features/CodeEditUI/Views/PaneTextField.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import SwiftUI
99
import Combine
10-
import Introspect
1110

1211
struct PaneTextField<LeadingAccessories: View, TrailingAccessories: View>: View {
1312
@Environment(\.colorScheme)

CodeEdit/Features/CodeEditUI/Views/SearchPanel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// OverlayPanel.swift
2+
// SearchPanel.swift
33
// CodeEditModules/CodeEditUI
44
//
55
// Created by Pavel Kasila on 20.03.22.

CodeEdit/Features/CodeEditUI/Views/SearchPanelView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// OverlayWindow.swift
2+
// SearchPanelView.swift
33
// CodeEdit
44
//
55
// Created by Khan Winter on 3/17/23.

CodeEdit/Features/CodeEditUI/Views/SegmentedControlImproved.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ struct XcodeButtonStyle: ButtonStyle {
8080
return (3, 8)
8181
case .large:
8282
return (6, 12)
83-
@unknown default:
83+
default:
8484
return (4, 8)
8585
}
8686
}

CodeEdit/Features/Commands/ViewModels/QuickActionsViewModel.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,5 @@ final class QuickActionsViewModel: ObservableObject {
3434
}
3535
self.filteredCommands = CommandManager.shared.commands.filter { $0.title.localizedCaseInsensitiveContains(val) }
3636
self.selected = self.filteredCommands.first
37-
3837
}
3938
}

CodeEdit/Features/Documents/CodeFileDocument.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ final class CodeFileDocument: NSDocument, ObservableObject {
9696

9797
// MARK: - NSDocument
9898

99-
override class var autosavesInPlace: Bool {
99+
override static var autosavesInPlace: Bool {
100100
Settings.shared.preferences.general.isAutoSaveOn
101101
}
102102

CodeEdit/Features/Documents/Controllers/CodeEditDocumentController.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ final class CodeEditDocumentController: NSDocumentController {
1212
@Environment(\.openWindow)
1313
private var openWindow
1414

15-
lazy var fileManager: FileManager = {
16-
FileManager.default
17-
}()
15+
private let fileManager = FileManager.default
1816

1917
override func newDocument(_ sender: Any?) {
2018
guard let newDocumentUrl = self.newDocumentUrl else { return }

CodeEdit/Features/Documents/LazyStringLoader.swift

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,13 @@ class LazyStringLoader {
2222
if fileHandle == nil {
2323
do {
2424
fileHandle = try FileHandle(forReadingFrom: fileURL)
25+
guard let data = try fileHandle?.read(upToCount: chunkSize) else {
26+
return nil
27+
}
28+
return String(decoding: data, as: UTF8.self)
2529
} catch {
26-
27-
}
28-
29-
var data = Data()
30-
let semaphore = DispatchSemaphore(value: 0)
31-
32-
do {
33-
data = try fileHandle?.read(upToCount: chunkSize) ?? Data()
34-
} catch {
35-
30+
return nil
3631
}
37-
38-
return String(data: data, encoding: .utf8)
3932
}
4033
return nil
4134
}

CodeEdit/Features/Documents/WorkspaceDocument+Find.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,10 @@ extension WorkspaceDocument.SearchState {
180180
/// await evaluateFile(query: "example", searchResult: &resultModel)
181181
/// ```
182182
private func evaluateFile(query: String, searchResult: inout SearchResultModel) async {
183-
guard let data = try? Data(contentsOf: searchResult.file.url),
184-
let fileContent = String(data: data, encoding: .utf8) else {
183+
guard let data = try? Data(contentsOf: searchResult.file.url) else {
185184
return
186185
}
186+
let fileContent = String(decoding: data, as: UTF8.self)
187187

188188
// Attempt to create a regular expression from the provided query
189189
guard let regex = try? NSRegularExpression(

CodeEdit/Features/Documents/WorkspaceDocument.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ final class WorkspaceDocument: NSDocument, ObservableObject, NSToolbarDelegate {
6363
".DS_Store"
6464
]
6565

66-
override class var autosavesInPlace: Bool {
66+
override static var autosavesInPlace: Bool {
6767
false
6868
}
6969

CodeEdit/Features/Editor/Models/EditorManager.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import Combine
99
import Foundation
1010
import DequeModule
11-
import OrderedCollections
1211
import os
1312

1413
class EditorManager: ObservableObject {
@@ -30,8 +29,6 @@ class EditorManager: ObservableObject {
3029
/// History of last-used editors.
3130
var activeEditorHistory: Deque<() -> Editor?> = []
3231

33-
var fileDocuments: [CEWorkspaceFile: CodeFileDocument] = [:]
34-
3532
/// notify listeners whenever tab selection changes on the active editor.
3633
var tabBarTabIdSubject = PassthroughSubject<String?, Never>()
3734
var cancellable: AnyCancellable?

CodeEdit/Features/Editor/PathBar/Views/EditorPathBarMenu.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ final class PathBarMenuItem: NSMenuItem {
6969
self.fileItem = fileItem
7070
self.tappedOpenFile = tappedOpenFile
7171
super.init(title: fileItem.name, action: #selector(openFile), keyEquivalent: "")
72-
73-
let icon = fileItem.systemImage
7472
var color = NSColor(fileItem.iconColor)
7573
isEnabled = true
7674
target = self

CodeEdit/Features/Editor/TabBar/Views/EditorTabBarLeadingAccessories.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct EditorTabBarLeadingAccessories: View {
1919

2020
var body: some View {
2121
HStack(spacing: 0) {
22-
if let otherEditor {
22+
if otherEditor != nil {
2323
EditorTabBarAccessoryIcon(
2424
icon: .init(systemName: "multiply"),
2525
action: { [weak editor] in

CodeEdit/Features/Editor/Views/CodeFileView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ struct CodeFileView: View {
6767
codeFile
6868
.contentCoordinator
6969
.textUpdatePublisher
70-
.debounce(for: 0.25, scheduler: DispatchQueue.main)
70+
.debounce(for: 1.0, scheduler: DispatchQueue.main)
7171
.sink { _ in
7272
codeFile.updateChangeCount(.changeDone)
7373
codeFile.autosave(withImplicitCancellability: false) { _ in }

CodeEdit/Features/Extensions/ExtensionSceneView.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,26 +57,25 @@ struct ExtensionSceneView: NSViewControllerRepresentable {
5757
var connection: NSXPCConnection?
5858

5959
func publishEnvironment(data: Data) {
60-
@Decoded<Callbacks> var data = data
61-
guard let $data else { return }
62-
switch $data {
60+
guard let decodedCallbacks = try? JSONDecoder().decode(Callbacks.self, from: data) else { return }
61+
switch decodedCallbacks {
6362
case .openWindow(let id):
6463
openWindow(id)
6564
}
6665
}
6766

68-
func updateEnvironment(@Encoded _ value: _CEEnvironment) {
69-
guard let $value else { return }
67+
func updateEnvironment(_ value: _CEEnvironment) {
68+
guard let newEnvironmentData = try? JSONEncoder().encode(value) else { return }
7069

7170
guard isOnline else {
72-
toPublish = $value
71+
toPublish = newEnvironmentData
7372
return
7473
}
7574

7675
Task {
7776
do {
7877
try await connection!.withService { (service: EnvironmentPublisherObjc) in
79-
service.publishEnvironment(data: $value)
78+
service.publishEnvironment(data: newEnvironmentData)
8079
}
8180
} catch {
8281
print(error)

CodeEdit/Features/Git/Accounts/GitHub/GitHubConfiguration.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ struct GitHubOAuthConfiguration: GitRouterConfiguration {
8989
if response.statusCode != 200 {
9090
return
9191
} else {
92-
if let data, let string = String(data: data, encoding: .utf8) {
92+
if let data {
93+
let string = String(decoding: data, as: UTF8.self)
9394
let accessToken = self.accessTokenFromResponse(string)
9495
if let accessToken {
9596
let config = GitHubTokenConfiguration(accessToken, url: self.apiEndpoint ?? "")

CodeEdit/Features/Git/Accounts/Networking/GitJSONPostRouter.swift

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,9 @@ extension GitJSONPostRouter {
6969
with: data,
7070
options: .mutableContainers
7171
) as? [String: Any] {
72-
7372
userInfo[gitErrorKey] = json as Any?
74-
75-
} else if let data,
76-
let string = String(data: data, encoding: .utf8) {
73+
// swiftlint:disable:next non_optional_string_data_conversion
74+
} else if let data, let string = String(data: data, encoding: .utf8) {
7775
userInfo[gitErrorKey] = string as Any?
7876
}
7977

@@ -125,10 +123,9 @@ extension GitJSONPostRouter {
125123
with: responseTuple.0,
126124
options: .mutableContainers
127125
) as? [String: Any] {
128-
129126
userInfo[gitErrorKey] = json as Any?
130-
131-
} else if let string = String(data: responseTuple.0, encoding: String.Encoding.utf8) {
127+
// swiftlint:disable:next non_optional_string_data_conversion
128+
} else if let string = String(data: responseTuple.0, encoding: .utf8) {
132129
userInfo[gitErrorKey] = string as Any?
133130
}
134131
throw NSError(domain: configuration?.errorDomain ?? "", code: response.statusCode, userInfo: userInfo)
@@ -165,9 +162,8 @@ extension GitJSONPostRouter {
165162
with: data,
166163
options: .mutableContainers
167164
) as? [String: Any] {
168-
169165
userInfo[gitErrorKey] = json as Any?
170-
166+
// swiftlint:disable:next non_optional_string_data_conversion
171167
} else if let data, let string = String(data: data, encoding: String.Encoding.utf8) {
172168
userInfo[gitErrorKey] = string as Any?
173169
}
@@ -219,8 +215,8 @@ extension GitJSONPostRouter {
219215
with: responseTuple.0,
220216
options: .mutableContainers
221217
) as? [String: Any] {
222-
223218
userInfo[gitErrorKey] = json as Any?
219+
// swiftlint:disable:next non_optional_string_data_conversion
224220
} else if let string = String(data: responseTuple.0, encoding: String.Encoding.utf8) {
225221
userInfo[gitErrorKey] = string as Any?
226222
}

CodeEdit/Features/Git/SourceControlManager.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ final class SourceControlManager: ObservableObject {
206206
}
207207

208208
/// Apply stash entry
209-
func applyStashEntry(stashEntry: GitStashEntry?) async throws {
210-
try await gitClient.applyStashEntry(stashEntry?.index)
209+
func applyStashEntry(stashEntry: GitStashEntry) async throws {
210+
try await gitClient.applyStashEntry(stashEntry.index)
211211
try await refreshStashEntries()
212212
await refreshAllChangedFiles()
213213
}

CodeEdit/Features/NavigatorArea/SourceControlNavigator/Repository/Views/SourceControlNavigatorRepositoryView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ struct SourceControlNavigatorRepositoryView: View {
9494
Button("Apply") {
9595
if let stashEntry = stashEntryToApply {
9696
Task {
97-
try await sourceControlManager.applyStashEntry(stashEntry: stashEntryToApply)
97+
try await sourceControlManager.applyStashEntry(stashEntry: stashEntry)
9898
applyStashedChangesIsPresented = false
9999
stashEntryToApply = nil
100100
}

CodeEdit/Features/QuickOpen/Views/NSTableViewWrapper.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ struct NSTableViewWrapper<Content: View, Item: Identifiable & Hashable>: NSViewR
5959
}
6060
}
6161

62-
func makeCoordinator() -> Coordinator<Content> {
62+
func makeCoordinator() -> Coordinator {
6363
Coordinator(parent: self)
6464
}
6565

66-
class Coordinator<Content: View>: NSObject, NSTableViewDelegate, NSTableViewDataSource {
66+
class Coordinator: NSObject, NSTableViewDelegate, NSTableViewDataSource {
6767

6868
var parent: NSTableViewWrapper
6969

CodeEdit/Features/Settings/Models/Settings.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// SettingsModel.swift
2+
// Settings.swift
33
// CodeEditModules/Settings
44
//
55
// Created by Lukas Pistrol on 01.04.22.

CodeEdit/Features/Settings/Models/SettingsSidebarFix.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// Created by Wouter Hennen on 13/04/2023.
66
//
77

8-
import Foundation
98
import AppKit
109

1110
extension NSSplitViewItem {

0 commit comments

Comments
 (0)