Skip to content

Commit 44063ca

Browse files
Use File System Events To Monitor Workspace (#1365)
* Add `DirectoryEventStream` * Remove unnecessary lock * Fix bugs, docs, tests
1 parent 3220ffc commit 44063ca

File tree

8 files changed

+294
-233
lines changed

8 files changed

+294
-233
lines changed

CodeEdit.xcodeproj/project.pbxproj

+21-17
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,9 @@
243243
58FD7608291EA1CB0051D6E4 /* CommandPaletteViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58FD7605291EA1CB0051D6E4 /* CommandPaletteViewModel.swift */; };
244244
58FD7609291EA1CB0051D6E4 /* CommandPaletteView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 58FD7607291EA1CB0051D6E4 /* CommandPaletteView.swift */; };
245245
5C4BB1E128212B1E00A92FB2 /* World.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5C4BB1E028212B1E00A92FB2 /* World.swift */; };
246+
6C049A372A49E2DB00D42923 /* DirectoryEventStream.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C049A362A49E2DB00D42923 /* DirectoryEventStream.swift */; };
246247
6C05A8AF284D0CA3007F4EAA /* WorkspaceDocument+Listeners.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C05A8AE284D0CA3007F4EAA /* WorkspaceDocument+Listeners.swift */; };
248+
6C092EC62A4E803300489202 /* CodeEditTextView in Frameworks */ = {isa = PBXBuildFile; productRef = 6C092EC52A4E803300489202 /* CodeEditTextView */; };
247249
6C0D0C6829E861B000AE4D3F /* SettingsSidebarFix.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C0D0C6729E861B000AE4D3F /* SettingsSidebarFix.swift */; };
248250
6C0F3A3C2A1D0D5000223D19 /* CodeEditKit in Frameworks */ = {isa = PBXBuildFile; productRef = 6C0F3A3B2A1D0D5000223D19 /* CodeEditKit */; };
249251
6C147C4029A328BC0089B630 /* SplitViewData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C147C3F29A328560089B630 /* SplitViewData.swift */; };
@@ -314,7 +316,6 @@
314316
6CC9E4B229B5669900C97388 /* Environment+ActiveTabGroup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CC9E4B129B5669900C97388 /* Environment+ActiveTabGroup.swift */; };
315317
6CD0375F2A3504540071C4DA /* FuzzySearch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CD0375E2A3504540071C4DA /* FuzzySearch.swift */; };
316318
6CD03B6A29FC773F001BD1D0 /* SettingsInjector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CD03B6929FC773F001BD1D0 /* SettingsInjector.swift */; };
317-
6CD601B52A420E0900E8C324 /* CodeEditTextView in Frameworks */ = {isa = PBXBuildFile; productRef = 6CD601B42A420E0900E8C324 /* CodeEditTextView */; };
318319
6CDA84AD284C1BA000C1CC3A /* TabBarContextMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CDA84AC284C1BA000C1CC3A /* TabBarContextMenu.swift */; };
319320
6CDEFC9629E22C2700B7C684 /* Introspect in Frameworks */ = {isa = PBXBuildFile; productRef = 6CDEFC9529E22C2700B7C684 /* Introspect */; };
320321
6CE622692A2A174A0013085C /* InspectorTab.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CE622682A2A174A0013085C /* InspectorTab.swift */; };
@@ -700,6 +701,7 @@
700701
58FD7605291EA1CB0051D6E4 /* CommandPaletteViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CommandPaletteViewModel.swift; sourceTree = "<group>"; };
701702
58FD7607291EA1CB0051D6E4 /* CommandPaletteView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CommandPaletteView.swift; sourceTree = "<group>"; };
702703
5C4BB1E028212B1E00A92FB2 /* World.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = World.swift; sourceTree = "<group>"; };
704+
6C049A362A49E2DB00D42923 /* DirectoryEventStream.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DirectoryEventStream.swift; sourceTree = "<group>"; };
703705
6C05A8AE284D0CA3007F4EAA /* WorkspaceDocument+Listeners.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "WorkspaceDocument+Listeners.swift"; sourceTree = "<group>"; };
704706
6C0D0C6729E861B000AE4D3F /* SettingsSidebarFix.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsSidebarFix.swift; sourceTree = "<group>"; };
705707
6C147C3D29A3281D0089B630 /* TabGroupData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabGroupData.swift; sourceTree = "<group>"; };
@@ -861,7 +863,7 @@
861863
6C0F3A3C2A1D0D5000223D19 /* CodeEditKit in Frameworks */,
862864
6C5BE5222A3D5666002DA0FC /* WindowManagement in Frameworks */,
863865
6C66C31329D05CDC00DE9ED2 /* GRDB in Frameworks */,
864-
6CD601B52A420E0900E8C324 /* CodeEditTextView in Frameworks */,
866+
6C092EC62A4E803300489202 /* CodeEditTextView in Frameworks */,
865867
58F2EB1E292FB954004A9BDE /* Sparkle in Frameworks */,
866868
6C2149412A1BB9AB00748382 /* LogStream in Frameworks */,
867869
6C147C4529A329350089B630 /* OrderedCollections in Frameworks */,
@@ -1856,6 +1858,7 @@
18561858
5894E59629FEF7740077E59C /* CEWorkspaceFile+Recursion.swift */,
18571859
58A2E40629C3975D005CB615 /* CEWorkspaceFileIcon.swift */,
18581860
58710158298EB80000951BA4 /* CEWorkspaceFileManager.swift */,
1861+
6C049A362A49E2DB00D42923 /* DirectoryEventStream.swift */,
18591862
);
18601863
path = Models;
18611864
sourceTree = "<group>";
@@ -2482,7 +2485,7 @@
24822485
6CDEFC9529E22C2700B7C684 /* Introspect */,
24832486
6C0F3A3B2A1D0D5000223D19 /* CodeEditKit */,
24842487
6C5BE5212A3D5666002DA0FC /* WindowManagement */,
2485-
6CD601B42A420E0900E8C324 /* CodeEditTextView */,
2488+
6C092EC52A4E803300489202 /* CodeEditTextView */,
24862489
);
24872490
productName = CodeEdit;
24882491
productReference = B658FB2C27DA9E0F00EA4DBD /* CodeEdit.app */;
@@ -2578,7 +2581,7 @@
25782581
6CDEFC9429E22C2700B7C684 /* XCRemoteSwiftPackageReference "SwiftUI-Introspect" */,
25792582
6C0F3A3A2A1D0D5000223D19 /* XCRemoteSwiftPackageReference "CodeEditKit" */,
25802583
6C5BE5202A3D5666002DA0FC /* XCRemoteSwiftPackageReference "SwiftUI-WindowManagement" */,
2581-
6CD601B32A420E0900E8C324 /* XCRemoteSwiftPackageReference "CodeEditTextView" */,
2584+
6C092EC42A4E803300489202 /* XCRemoteSwiftPackageReference "CodeEditTextView" */,
25822585
);
25832586
productRefGroup = B658FB2D27DA9E0F00EA4DBD /* Products */;
25842587
projectDirPath = "";
@@ -2935,6 +2938,7 @@
29352938
286471AB27ED51FD0039369D /* ProjectNavigatorView.swift in Sources */,
29362939
B6E41C7C29DE2B110088F9F4 /* AccountsSettingsProviderRow.swift in Sources */,
29372940
B62AEDB52A1FE295009A9F52 /* DebugAreaDebugView.swift in Sources */,
2941+
6C049A372A49E2DB00D42923 /* DirectoryEventStream.swift in Sources */,
29382942
6CAAF68A29BC9C2300A1F48A /* (null) in Sources */,
29392943
6C6BD6EF29CD12E900235D17 /* ExtensionManagerWindow.swift in Sources */,
29402944
6CFF967629BEBCD900182D6F /* FileCommands.swift in Sources */,
@@ -3963,6 +3967,14 @@
39633967
version = 2.3.0;
39643968
};
39653969
};
3970+
6C092EC42A4E803300489202 /* XCRemoteSwiftPackageReference "CodeEditTextView" */ = {
3971+
isa = XCRemoteSwiftPackageReference;
3972+
repositoryURL = "https://github.com/CodeEditApp/CodeEditTextView";
3973+
requirement = {
3974+
kind = upToNextMajorVersion;
3975+
minimumVersion = 0.6.6;
3976+
};
3977+
};
39663978
6C0F3A3A2A1D0D5000223D19 /* XCRemoteSwiftPackageReference "CodeEditKit" */ = {
39673979
isa = XCRemoteSwiftPackageReference;
39683980
repositoryURL = "https://github.com/CodeEditApp/CodeEditKit";
@@ -4011,14 +4023,6 @@
40114023
minimumVersion = 0.2.0;
40124024
};
40134025
};
4014-
6CD601B32A420E0900E8C324 /* XCRemoteSwiftPackageReference "CodeEditTextView" */ = {
4015-
isa = XCRemoteSwiftPackageReference;
4016-
repositoryURL = "https://github.com/CodeEditApp/CodeEditTextView";
4017-
requirement = {
4018-
kind = upToNextMajorVersion;
4019-
minimumVersion = 0.6.6;
4020-
};
4021-
};
40224026
6CDEFC9429E22C2700B7C684 /* XCRemoteSwiftPackageReference "SwiftUI-Introspect" */ = {
40234027
isa = XCRemoteSwiftPackageReference;
40244028
repositoryURL = "https://github.com/siteline/SwiftUI-Introspect";
@@ -4050,6 +4054,11 @@
40504054
package = 58F2EB1C292FB954004A9BDE /* XCRemoteSwiftPackageReference "Sparkle" */;
40514055
productName = Sparkle;
40524056
};
4057+
6C092EC52A4E803300489202 /* CodeEditTextView */ = {
4058+
isa = XCSwiftPackageProductDependency;
4059+
package = 6C092EC42A4E803300489202 /* XCRemoteSwiftPackageReference "CodeEditTextView" */;
4060+
productName = CodeEditTextView;
4061+
};
40534062
6C0F3A3B2A1D0D5000223D19 /* CodeEditKit */ = {
40544063
isa = XCSwiftPackageProductDependency;
40554064
package = 6C0F3A3A2A1D0D5000223D19 /* XCRemoteSwiftPackageReference "CodeEditKit" */;
@@ -4094,11 +4103,6 @@
40944103
package = 6C147C4329A329350089B630 /* XCRemoteSwiftPackageReference "swift-collections" */;
40954104
productName = DequeModule;
40964105
};
4097-
6CD601B42A420E0900E8C324 /* CodeEditTextView */ = {
4098-
isa = XCSwiftPackageProductDependency;
4099-
package = 6CD601B32A420E0900E8C324 /* XCRemoteSwiftPackageReference "CodeEditTextView" */;
4100-
productName = CodeEditTextView;
4101-
};
41024106
6CDEFC9529E22C2700B7C684 /* Introspect */ = {
41034107
isa = XCSwiftPackageProductDependency;
41044108
package = 6CDEFC9429E22C2700B7C684 /* XCRemoteSwiftPackageReference "SwiftUI-Introspect" */;

CodeEdit/Features/CEWorkspace/Models/CEWorkspaceFile.swift

-30
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ final class CEWorkspaceFile: Codable, Comparable, Hashable, Identifiable, TabBar
5151

5252
var fileIdentifier = UUID().uuidString
5353

54-
var watcher: DispatchSourceFileSystemObject?
55-
var watcherCode: ((CEWorkspaceFile) -> Void)?
56-
5754
/// Returns the Git status of a file as ``GitType``
5855
var gitStatus: GitType?
5956

@@ -124,33 +121,6 @@ final class CEWorkspaceFile: Codable, Comparable, Hashable, Identifiable, TabBar
124121
try container.encode(gitStatus, forKey: .changeType)
125122
}
126123

127-
func activateWatcher() -> Bool {
128-
guard let watcherCode else { return false }
129-
130-
let descriptor = open(self.url.path, O_EVTONLY)
131-
guard descriptor > 0 else { return false }
132-
133-
// create the source
134-
let source = DispatchSource.makeFileSystemObjectSource(
135-
fileDescriptor: descriptor,
136-
eventMask: .write,
137-
queue: DispatchQueue.global()
138-
)
139-
140-
if descriptor > 2000 {
141-
print("Watcher \(descriptor) used up on \(url.path)")
142-
}
143-
144-
source.setEventHandler { watcherCode(self) }
145-
source.setCancelHandler { close(descriptor) }
146-
source.resume()
147-
self.watcher = source
148-
149-
// TODO: reindex the current item, because the files in the item may have changed
150-
// since the initial load on startup.
151-
return true
152-
}
153-
154124
/// Returns a string describing a SFSymbol for folders
155125
///
156126
/// If it is the top-level folder this will return `"square.dashed.inset.filled"`.

0 commit comments

Comments
 (0)