Skip to content

Commit 93f949e

Browse files
committed
Resolved most SwiftLint warnings
1 parent f877153 commit 93f949e

File tree

19 files changed

+119
-96
lines changed

19 files changed

+119
-96
lines changed

CodeEdit.xcodeproj/project.pbxproj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@
368368
attributes = {
369369
BuildIndependentTargetsInParallel = 1;
370370
LastSwiftUpdateCheck = 1330;
371-
LastUpgradeCheck = 1540;
371+
LastUpgradeCheck = 1620;
372372
TargetAttributes = {
373373
2BE487EB28245162003F3F64 = {
374374
CreatedOnToolsVersion = 13.3.1;
@@ -565,6 +565,7 @@
565565
baseConfigurationReferenceRelativePath = Alpha.xcconfig;
566566
buildSettings = {
567567
ALWAYS_SEARCH_USER_PATHS = NO;
568+
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
568569
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
569570
CLANG_ANALYZER_NONNULL = YES;
570571
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
@@ -759,6 +760,7 @@
759760
baseConfigurationReferenceRelativePath = Beta.xcconfig;
760761
buildSettings = {
761762
ALWAYS_SEARCH_USER_PATHS = NO;
763+
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
762764
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
763765
CLANG_ANALYZER_NONNULL = YES;
764766
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
@@ -1021,6 +1023,7 @@
10211023
baseConfigurationReferenceRelativePath = Alpha.xcconfig;
10221024
buildSettings = {
10231025
ALWAYS_SEARCH_USER_PATHS = NO;
1026+
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
10241027
CE_APPICON_NAME = AppIconPre;
10251028
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
10261029
CLANG_ANALYZER_NONNULL = YES;
@@ -1217,6 +1220,7 @@
12171220
baseConfigurationReferenceRelativePath = Debug.xcconfig;
12181221
buildSettings = {
12191222
ALWAYS_SEARCH_USER_PATHS = NO;
1223+
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
12201224
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
12211225
CLANG_ANALYZER_NONNULL = YES;
12221226
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
@@ -1288,6 +1292,7 @@
12881292
baseConfigurationReferenceRelativePath = Release.xcconfig;
12891293
buildSettings = {
12901294
ALWAYS_SEARCH_USER_PATHS = NO;
1295+
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
12911296
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
12921297
CLANG_ANALYZER_NONNULL = YES;
12931298
CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
@@ -1616,7 +1621,7 @@
16161621
repositoryURL = "https://github.com/lukepistrol/SwiftLintPlugin";
16171622
requirement = {
16181623
kind = upToNextMajorVersion;
1619-
minimumVersion = 0.56.2;
1624+
minimumVersion = 0.58.2;
16201625
};
16211626
};
16221627
303E88452C276FD100EEA8D9 /* XCRemoteSwiftPackageReference "LanguageClient" */ = {

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

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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 = "1540"
3+
LastUpgradeVersion = "1620"
44
version = "1.7">
55
<BuildAction
66
parallelizeBuildables = "YES"

CodeEdit/Features/Documents/WorkspaceDocument/WorkspaceDocument+Find.swift

Lines changed: 52 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
import Foundation
99

10+
extension WorkspaceDocument.SearchState: @unchecked Sendable {}
11+
1012
extension WorkspaceDocument.SearchState {
1113
/// Creates a search term based on the given query and search mode.
1214
///
@@ -94,9 +96,6 @@ extension WorkspaceDocument.SearchState {
9496
}
9597

9698
let searchQuery = getSearchTerm(query)
97-
98-
// The regexPattern is only used for the evaluateFile function
99-
// to ensure that the search terms are highlighted correctly
10099
let regexPattern = getRegexPattern(query)
101100

102101
guard let indexer = indexer else {
@@ -105,24 +104,34 @@ extension WorkspaceDocument.SearchState {
105104
}
106105

107106
let asyncController = SearchIndexer.AsyncManager(index: indexer)
108-
109107
let evaluateResultGroup = DispatchGroup()
110108
let evaluateSearchQueue = DispatchQueue(label: "app.codeedit.CodeEdit.EvaluateSearch")
111109

112110
let searchStream = await asyncController.search(query: searchQuery, 20)
113111
for try await result in searchStream {
114112
for file in result.results {
113+
let fileURL = file.url
114+
let fileScore = file.score
115+
let capturedRegexPattern = regexPattern
116+
115117
evaluateSearchQueue.async(group: evaluateResultGroup) {
116118
evaluateResultGroup.enter()
117-
Task {
118-
var newResult = SearchResultModel(file: CEWorkspaceFile(url: file.url), score: file.score)
119-
await self.evaluateFile(query: regexPattern, searchResult: &newResult)
120-
121-
// Check if the new result has any line matches.
122-
if !newResult.lineMatches.isEmpty {
123-
// The function needs to be called because,
124-
// we are trying to modify the array from within a concurrent context.
125-
self.appendNewResultsToTempResults(newResult: newResult)
119+
Task { [weak self] in
120+
guard let self else {
121+
evaluateResultGroup.leave()
122+
return
123+
}
124+
125+
let result = await self.evaluateSearchResult(
126+
fileURL: fileURL,
127+
fileScore: fileScore,
128+
regexPattern: capturedRegexPattern
129+
)
130+
131+
if let result = result {
132+
await MainActor.run {
133+
self.tempSearchResults.append(result)
134+
}
126135
}
127136
evaluateResultGroup.leave()
128137
}
@@ -131,33 +140,33 @@ extension WorkspaceDocument.SearchState {
131140
}
132141

133142
evaluateResultGroup.notify(queue: evaluateSearchQueue) {
134-
self.setSearchResults()
143+
Task { @MainActor [weak self] in
144+
self?.setSearchResults()
145+
}
135146
}
136147
}
137148

138149
/// Appends a new search result to the temporary search results array on the main thread.
139150
///
140151
/// - Parameters:
141152
/// - newResult: The `SearchResultModel` to be appended to the temporary search results.
153+
@MainActor
142154
func appendNewResultsToTempResults(newResult: SearchResultModel) {
143-
DispatchQueue.main.async {
144-
self.tempSearchResults.append(newResult)
145-
}
155+
self.tempSearchResults.append(newResult)
146156
}
147157

148158
/// Sets the search results by updating various properties on the main thread.
149159
/// This function updates `findNavigatorStatus`, `searchResult`, `searchResultCount`, and `searchResultsFileCount`
150160
/// and sets the `tempSearchResults` to an empty array.
151161
/// - Important: Call this function when you are ready to
152162
/// display or use the final search results.
163+
@MainActor
153164
func setSearchResults() {
154-
DispatchQueue.main.async {
155-
self.searchResult = self.tempSearchResults.sorted { $0.score > $1.score }
156-
self.searchResultsCount = self.tempSearchResults.map { $0.lineMatches.count }.reduce(0, +)
157-
self.searchResultsFileCount = self.tempSearchResults.count
158-
self.findNavigatorStatus = .found
159-
self.tempSearchResults = []
160-
}
165+
self.searchResult = self.tempSearchResults.sorted { $0.score > $1.score }
166+
self.searchResultsCount = self.tempSearchResults.map { $0.lineMatches.count }.reduce(0, +)
167+
self.searchResultsFileCount = self.tempSearchResults.count
168+
self.findNavigatorStatus = .found
169+
self.tempSearchResults = []
161170
}
162171

163172
/// Evaluates a search query within the content of a file and updates
@@ -183,7 +192,10 @@ extension WorkspaceDocument.SearchState {
183192
guard let data = try? Data(contentsOf: searchResult.file.url) else {
184193
return
185194
}
186-
let fileContent = String(decoding: data, as: UTF8.self)
195+
guard let fileContent = String(bytes: data, encoding: .utf8) else {
196+
await setStatus(.failed(errorMessage: "Failed to decode file content."))
197+
return
198+
}
187199

188200
// Attempt to create a regular expression from the provided query
189201
guard let regex = try? NSRegularExpression(
@@ -343,4 +355,19 @@ extension WorkspaceDocument.SearchState {
343355
self.findNavigatorStatus = .none
344356
}
345357
}
358+
359+
private func evaluateSearchResult(
360+
fileURL: URL,
361+
fileScore: Float,
362+
regexPattern: String
363+
) async -> SearchResultModel? {
364+
var newResult = SearchResultModel(
365+
file: CEWorkspaceFile(url: fileURL),
366+
score: fileScore
367+
)
368+
369+
await evaluateFile(query: regexPattern, searchResult: &newResult)
370+
371+
return newResult.lineMatches.isEmpty ? nil : newResult
372+
}
346373
}

CodeEdit/Features/Editor/TabBar/Tabs/Tab/EditorTabCloseButton.swift

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,3 @@ struct EditorTabCloseButton: View {
104104
}
105105
}
106106
}
107-
108-
#Preview {
109-
@State var closeButtonGestureActive: Bool = false
110-
@State var isHoveringClose: Bool = false
111-
112-
return EditorTabCloseButton(
113-
isActive: false,
114-
isHoveringTab: false,
115-
isDragging: false,
116-
closeAction: { print("Close tab") },
117-
closeButtonGestureActive: $closeButtonGestureActive,
118-
isHoveringClose: $isHoveringClose
119-
)
120-
}

CodeEdit/Features/LSP/Service/LSPService.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ final class LSPService: ObservableObject {
218218
do {
219219
try await languageServer.openDocument(document)
220220
} catch {
221-
let uri = await document.languageServerURI
221+
let uri = document.languageServerURI
222222
// swiftlint:disable:next line_length
223223
self.logger.error("Failed to close document: \(uri ?? "<NO URI>", privacy: .private), language: \(lspLanguage.rawValue). Error \(error)")
224224
}

CodeEdit/Features/NavigatorArea/FindNavigator/FindNavigatorResultList/FindNavigatorListViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ extension FindNavigatorListViewController: NSOutlineViewDelegate {
155155
shouldShowCellExpansionFor tableColumn: NSTableColumn?,
156156
item: Any
157157
) -> Bool {
158-
return item as? SearchResultModel != nil
158+
item is SearchResultModel
159159
}
160160

161161
func outlineView(_ outlineView: NSOutlineView, shouldShowOutlineCellForItem item: Any) -> Bool {

CodeEdit/Features/OpenQuickly/ViewModels/OpenQuicklyViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ final class OpenQuicklyViewModel: ObservableObject {
2424
///
2525
/// ``OpenQuicklyPreviewView`` also uses this to load the `fileUrl` for preview.
2626
struct SearchResult: Identifiable, Hashable {
27-
var id: String { fileURL.id }
27+
var id: String { fileURL.absoluteString }
2828
let fileURL: URL
2929
let matchedCharacters: [NSRange]
3030

CodeEdit/Features/OpenQuickly/Views/OpenQuicklyView.swift

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

88
import SwiftUI
99

10-
extension URL: Identifiable {
11-
public var id: String {
12-
absoluteString
13-
}
14-
}
15-
1610
struct OpenQuicklyView: View {
1711
@EnvironmentObject private var workspace: WorkspaceDocument
1812

CodeEdit/Features/Settings/Views/ExternalLink.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ struct ExternalLink<Content: View, Icon: View>: View {
5555
@ViewBuilder content: @escaping () -> Content,
5656
title: String? = nil,
5757
subtitle: String? = nil,
58-
@ViewBuilder icon: @escaping() -> Icon = { EmptyView() }
58+
@ViewBuilder icon: @escaping () -> Icon = { EmptyView() }
5959
) {
6060
self.showInFinder = showInFinder
6161
self.title = title

0 commit comments

Comments
 (0)