Skip to content

Commit 6f80528

Browse files
Merge branch 'main' into itembox
2 parents 02fb3b5 + f580ef5 commit 6f80528

55 files changed

Lines changed: 1674 additions & 460 deletions

File tree

Some content is hidden

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

CodeEdit.xcodeproj/project.pbxproj

Lines changed: 105 additions & 41 deletions
Large diffs are not rendered by default.

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

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

CodeEdit/AppDelegate.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {
2020
@LazyService var lspService: LSPService
2121

2222
func applicationDidFinishLaunching(_ notification: Notification) {
23-
setupServiceContainer()
2423
enableWindowSizeSaveOnQuit()
2524
Settings.shared.preferences.general.appAppearance.applyAppearance()
2625
checkForFilesToOpen()
@@ -271,14 +270,6 @@ final class AppDelegate: NSObject, NSApplicationDelegate, ObservableObject {
271270
workspace.taskManager?.stopAllTasks()
272271
}
273272
}
274-
275-
/// Setup all the services into a ServiceContainer for the application to use.
276-
@MainActor
277-
private func setupServiceContainer() {
278-
ServiceContainer.register(
279-
LSPService()
280-
)
281-
}
282273
}
283274

284275
extension AppDelegate {

CodeEdit/CodeEditApp.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ struct CodeEditApp: App {
1515
let updater: SoftwareUpdater = SoftwareUpdater()
1616

1717
init() {
18+
// Register singleton services before anything else
19+
ServiceContainer.register(
20+
LSPService()
21+
)
22+
1823
_ = CodeEditDocumentController.shared
1924
NSMenuItem.swizzle()
2025
NSSplitViewItem.swizzle()

CodeEdit/Features/CEWorkspace/Models/CEWorkspaceFileManager+DirectoryEvents.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ extension CEWorkspaceFileManager {
3030
// Can be ignored for now, these I think not related to tree changes
3131
continue
3232
case .rootChanged:
33-
// TODO: Handle workspace root changing.
33+
// TODO: #1880 - Handle workspace root changing.
3434
continue
3535
case .itemCreated, .itemCloned, .itemRemoved, .itemRenamed:
3636
for fileItem in fileItems {
@@ -48,7 +48,10 @@ extension CEWorkspaceFileManager {
4848
self.notifyObservers(updatedItems: files)
4949
}
5050

51-
self.handleGitEvents(events: events)
51+
if Settings.shared.preferences.sourceControl.general.sourceControlIsEnabled &&
52+
Settings.shared.preferences.sourceControl.general.refreshStatusLocally {
53+
self.handleGitEvents(events: events)
54+
}
5255
}
5356
}
5457

CodeEdit/Features/CodeEditUI/Views/ToolbarBranchPicker.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ struct ToolbarBranchPicker: View {
7171
isHovering = active
7272
}
7373
.onReceive(NotificationCenter.default.publisher(for: NSApplication.didBecomeActiveNotification)) { (_) in
74-
Task {
75-
await sourceControlManager?.refreshCurrentBranch()
74+
if self.currentBranch != nil {
75+
Task {
76+
await sourceControlManager?.refreshCurrentBranch()
77+
}
7678
}
7779
}
7880
.onReceive(
@@ -82,8 +84,10 @@ struct ToolbarBranchPicker: View {
8284
self.currentBranch = branch
8385
}
8486
.task {
85-
await self.sourceControlManager?.refreshCurrentBranch()
86-
await self.sourceControlManager?.refreshBranches()
87+
if Settings.shared.preferences.sourceControl.general.sourceControlIsEnabled {
88+
await self.sourceControlManager?.refreshCurrentBranch()
89+
await self.sourceControlManager?.refreshBranches()
90+
}
8791
}
8892
}
8993

CodeEdit/Features/Documents/CodeFileDocument/CodeFileDocument.swift

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ final class CodeFileDocument: NSDocument, ObservableObject {
2828

2929
static let logger = Logger(subsystem: Bundle.main.bundleIdentifier ?? "", category: "CodeFileDocument")
3030

31-
@Service var lspService: LSPService
31+
/// Sent when the document is opened. The document will be sent in the notification's object.
32+
static let didOpenNotification = Notification.Name(rawValue: "CodeFileDocument.didOpen")
33+
/// Sent when the document is closed. The document's `fileURL` will be sent in the notification's object.
34+
static let didCloseNotification = Notification.Name(rawValue: "CodeFileDocument.didClose")
3235

3336
/// The text content of the document, stored as a text storage
3437
///
@@ -46,11 +49,8 @@ final class CodeFileDocument: NSDocument, ObservableObject {
4649
/// See ``CodeEditSourceEditor/CombineCoordinator``.
4750
@Published var contentCoordinator: CombineCoordinator = CombineCoordinator()
4851

49-
lazy var languageServerCoordinator: LSPContentCoordinator = {
50-
let coordinator = LSPContentCoordinator()
51-
coordinator.uri = self.languageServerURI
52-
return coordinator
53-
}()
52+
/// Set by ``LanguageServer`` when initialized.
53+
@Published var lspCoordinator: LSPContentCoordinator?
5454

5555
/// Used to override detected languages.
5656
@Published var language: CodeLanguage?
@@ -83,7 +83,7 @@ final class CodeFileDocument: NSDocument, ObservableObject {
8383
}
8484

8585
/// A stable string to use when identifying documents with language servers.
86-
var languageServerURI: String? { fileURL?.languageServerURI }
86+
var languageServerURI: String? { fileURL?.absolutePath }
8787

8888
/// Specify options for opening the file such as the initial cursor positions.
8989
/// Nulled by ``CodeFileView`` on first load.
@@ -160,6 +160,7 @@ final class CodeFileDocument: NSDocument, ObservableObject {
160160
} else {
161161
Self.logger.error("Failed to read file from data using encoding: \(rawEncoding)")
162162
}
163+
NotificationCenter.default.post(name: Self.didOpenNotification, object: self)
163164
}
164165

165166
/// Triggered when change occurred
@@ -186,7 +187,7 @@ final class CodeFileDocument: NSDocument, ObservableObject {
186187

187188
override func close() {
188189
super.close()
189-
lspService.closeDocument(self)
190+
NotificationCenter.default.post(name: Self.didCloseNotification, object: fileURL)
190191
}
191192

192193
func getLanguage() -> CodeLanguage {
@@ -201,15 +202,6 @@ final class CodeFileDocument: NSDocument, ObservableObject {
201202
}
202203

203204
func findWorkspace() -> WorkspaceDocument? {
204-
CodeEditDocumentController.shared.documents.first(where: { doc in
205-
guard let workspace = doc as? WorkspaceDocument, let path = self.languageServerURI else { return false }
206-
// createIfNotFound is safe here because it will still exit if the file and the workspace
207-
// do not share a path prefix
208-
return workspace
209-
.workspaceFileManager?
210-
.getFile(path, createIfNotFound: true)?
211-
.fileDocument?
212-
.isEqual(self) ?? false
213-
}) as? WorkspaceDocument
205+
fileURL?.findWorkspace()
214206
}
215207
}

CodeEdit/Features/Documents/Controllers/CodeEditDocumentController.swift

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

15-
@LazyService var lspService: LSPService
15+
@Service var lspService: LSPService
1616

1717
private let fileManager = FileManager.default
1818

@@ -92,13 +92,6 @@ final class CodeEditDocumentController: NSDocumentController {
9292
}
9393
}
9494
}
95-
96-
override func addDocument(_ document: NSDocument) {
97-
super.addDocument(document)
98-
if let document = document as? CodeFileDocument {
99-
lspService.openDocument(document)
100-
}
101-
}
10295
}
10396

10497
extension NSDocumentController {

CodeEdit/Features/Editor/Views/CodeFileView.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,9 @@ struct CodeFileView: View {
5656

5757
init(codeFile: CodeFileDocument, textViewCoordinators: [TextViewCoordinator] = [], isEditable: Bool = true) {
5858
self._codeFile = .init(wrappedValue: codeFile)
59-
self.textViewCoordinators = textViewCoordinators + [
60-
codeFile.contentCoordinator,
61-
codeFile.languageServerCoordinator,
62-
]
59+
self.textViewCoordinators = textViewCoordinators
60+
+ [codeFile.contentCoordinator]
61+
+ [codeFile.lspCoordinator].compactMap({ $0 })
6362
self.isEditable = isEditable
6463

6564
if let openOptions = codeFile.openOptions {

CodeEdit/Features/InspectorArea/HistoryInspector/HistoryInspectorModel.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ final class HistoryInspectorModel: ObservableObject {
4040
do {
4141
let commitHistory = try await sourceControlManager
4242
.gitClient
43-
.getCommitHistory(maxCount: 40, fileLocalPath: fileURL)
43+
.getCommitHistory(
44+
maxCount: 40,
45+
fileLocalPath: fileURL,
46+
showMergeCommits: Settings.shared.preferences.sourceControl.git.showMergeCommitsPerFileLog
47+
)
4448
await setCommitHistory(commitHistory)
4549
} catch {
4650
await setCommitHistory([])

0 commit comments

Comments
 (0)