Skip to content

Commit 546a437

Browse files
Use local packages, fix errors
1 parent 04e87ce commit 546a437

File tree

5 files changed

+338
-8
lines changed

5 files changed

+338
-8
lines changed

CodeEdit.xcodeproj/project.pbxproj

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
2BE487EF28245162003F3F64 /* FinderSync.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2BE487EE28245162003F3F64 /* FinderSync.swift */; };
6161
2BE487F428245162003F3F64 /* OpenWithCodeEdit.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = 2BE487EC28245162003F3F64 /* OpenWithCodeEdit.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
6262
3026F50F2AC006C80061227E /* InspectorAreaViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3026F50E2AC006C80061227E /* InspectorAreaViewModel.swift */; };
63+
3039C8DD2B738D5A00C8B4F8 /* LanguageClient in Frameworks */ = {isa = PBXBuildFile; productRef = 3039C8DC2B738D5A00C8B4F8 /* LanguageClient */; };
64+
305811812B73832B0049C9AA /* LanguageServer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 305811802B73832B0049C9AA /* LanguageServer.swift */; };
65+
305811832B73834F0049C9AA /* LSPCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 305811822B73834F0049C9AA /* LSPCache.swift */; };
6366
30E6D0012A6E505200A58B20 /* NavigatorSidebarViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30E6D0002A6E505200A58B20 /* NavigatorSidebarViewModel.swift */; };
6467
3E0196732A3921AC002648D8 /* codeedit_shell_integration.zsh in Resources */ = {isa = PBXBuildFile; fileRef = 3E0196722A3921AC002648D8 /* codeedit_shell_integration.zsh */; };
6568
3E01967A2A392B45002648D8 /* codeedit_shell_integration.bash in Resources */ = {isa = PBXBuildFile; fileRef = 3E0196792A392B45002648D8 /* codeedit_shell_integration.bash */; };
@@ -305,7 +308,6 @@
305308
6C2C155A29B4F4CC00EA60A5 /* Variadic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C2C155929B4F4CC00EA60A5 /* Variadic.swift */; };
306309
6C2C155D29B4F4E500EA60A5 /* SplitViewReader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C2C155C29B4F4E500EA60A5 /* SplitViewReader.swift */; };
307310
6C2C156129B4F52F00EA60A5 /* SplitViewModifiers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C2C156029B4F52F00EA60A5 /* SplitViewModifiers.swift */; };
308-
6C2C20172A4016FF0047EDF2 /* (null) in Frameworks */ = {isa = PBXBuildFile; };
309311
6C4104E3297C87A000F472BA /* BlurButtonStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C4104E2297C87A000F472BA /* BlurButtonStyle.swift */; };
310312
6C4104E6297C884F00F472BA /* AboutDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C4104E5297C884F00F472BA /* AboutDetailView.swift */; };
311313
6C4104E9297C970F00F472BA /* AboutDefaultView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C4104E8297C970F00F472BA /* AboutDefaultView.swift */; };
@@ -620,6 +622,8 @@
620622
2BE487EE28245162003F3F64 /* FinderSync.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FinderSync.swift; sourceTree = "<group>"; };
621623
2BE487F028245162003F3F64 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
622624
3026F50E2AC006C80061227E /* InspectorAreaViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InspectorAreaViewModel.swift; sourceTree = "<group>"; };
625+
305811802B73832B0049C9AA /* LanguageServer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LanguageServer.swift; sourceTree = "<group>"; };
626+
305811822B73834F0049C9AA /* LSPCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LSPCache.swift; sourceTree = "<group>"; };
623627
30E6D0002A6E505200A58B20 /* NavigatorSidebarViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigatorSidebarViewModel.swift; sourceTree = "<group>"; };
624628
3E0196722A3921AC002648D8 /* codeedit_shell_integration.zsh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = codeedit_shell_integration.zsh; sourceTree = "<group>"; };
625629
3E0196792A392B45002648D8 /* codeedit_shell_integration.bash */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.sh; path = codeedit_shell_integration.bash; sourceTree = "<group>"; };
@@ -1075,7 +1079,7 @@
10751079
6CDEFC9629E22C2700B7C684 /* Introspect in Frameworks */,
10761080
2816F594280CF50500DD548B /* CodeEditSymbols in Frameworks */,
10771081
6C6BD6F829CD14D100235D17 /* CodeEditKit in Frameworks */,
1078-
6C2C20172A4016FF0047EDF2 /* (null) in Frameworks */,
1082+
3039C8DD2B738D5A00C8B4F8 /* LanguageClient in Frameworks */,
10791083
6C81916B29B41DD300B75C92 /* DequeModule in Frameworks */,
10801084
);
10811085
runOnlyForDeploymentPostprocessing = 0;
@@ -1314,6 +1318,15 @@
13141318
path = ViewModels;
13151319
sourceTree = "<group>";
13161320
};
1321+
3058117F2B7383090049C9AA /* LSP */ = {
1322+
isa = PBXGroup;
1323+
children = (
1324+
305811802B73832B0049C9AA /* LanguageServer.swift */,
1325+
305811822B73834F0049C9AA /* LSPCache.swift */,
1326+
);
1327+
path = LSP;
1328+
sourceTree = "<group>";
1329+
};
13171330
307AC4CB2ABABD9800163376 /* ViewModels */ = {
13181331
isa = PBXGroup;
13191332
children = (
@@ -1420,6 +1433,7 @@
14201433
587B9E0129301D8F00AC7927 /* Git */,
14211434
B6EE988E27E8877C00CDD8AB /* InspectorArea */,
14221435
58A5DF9D29339F6400D1BD5D /* Keybindings */,
1436+
3058117F2B7383090049C9AA /* LSP */,
14231437
287776EA27E350A100D46668 /* NavigatorArea */,
14241438
5878DAA0291AE76700DD95A3 /* QuickOpen */,
14251439
58798210292D92370085B254 /* Search */,
@@ -3030,6 +3044,7 @@
30303044
6CDEFC9529E22C2700B7C684 /* Introspect */,
30313045
6C5BE5212A3D5666002DA0FC /* WindowManagement */,
30323046
6CE952E22B29433500C29C31 /* CodeEditSourceEditor */,
3047+
3039C8DC2B738D5A00C8B4F8 /* LanguageClient */,
30333048
);
30343049
productName = CodeEdit;
30353050
productReference = B658FB2C27DA9E0F00EA4DBD /* CodeEdit.app */;
@@ -3126,6 +3141,8 @@
31263141
6C5BE5202A3D5666002DA0FC /* XCRemoteSwiftPackageReference "SwiftUI-WindowManagement" */,
31273142
6CE952E12B29433500C29C31 /* XCRemoteSwiftPackageReference "CodeEditSourceEditor" */,
31283143
30AAFCD02B7380EF007177DC /* XCLocalSwiftPackageReference "../CodeEditKit" */,
3144+
30E1AAB12B73856500420274 /* XCLocalSwiftPackageReference "../LanguageClient" */,
3145+
3039C8DF2B738D9B00C8B4F8 /* XCLocalSwiftPackageReference "../LanguageServerProtocol" */,
31293146
);
31303147
productRefGroup = B658FB2D27DA9E0F00EA4DBD /* Products */;
31313148
projectDirPath = "";
@@ -3464,6 +3481,7 @@
34643481
6111920C2B08CD0B00D4459B /* SearchIndexer+InternalMethods.swift in Sources */,
34653482
6CABB1A129C5593800340467 /* OverlayView.swift in Sources */,
34663483
D7211D4327E066CE008F2ED7 /* Localized+Ex.swift in Sources */,
3484+
305811832B73834F0049C9AA /* LSPCache.swift in Sources */,
34673485
581BFB692926431000D251EC /* WelcomeActionView.swift in Sources */,
34683486
20D839AE280E0CA700B27357 /* HistoryPopoverView.swift in Sources */,
34693487
B6E41C7029DD157F0088F9F4 /* AccountsSettingsView.swift in Sources */,
@@ -3481,6 +3499,7 @@
34813499
58D01C96293167DC00C5B6B4 /* Date+Formatted.swift in Sources */,
34823500
B66A4E5629C918A0004573B4 /* SceneID.swift in Sources */,
34833501
6C53AAD829A6C4FD00EE9ED6 /* SplitView.swift in Sources */,
3502+
305811812B73832B0049C9AA /* LanguageServer.swift in Sources */,
34843503
B66A4E5329C91831004573B4 /* CodeEditCommands.swift in Sources */,
34853504
58822529292C280D00E83CDE /* StatusBarLineEndSelector.swift in Sources */,
34863505
5C4BB1E128212B1E00A92FB2 /* World.swift in Sources */,
@@ -4578,10 +4597,18 @@
45784597
/* End XCConfigurationList section */
45794598

45804599
/* Begin XCLocalSwiftPackageReference section */
4600+
3039C8DF2B738D9B00C8B4F8 /* XCLocalSwiftPackageReference "../LanguageServerProtocol" */ = {
4601+
isa = XCLocalSwiftPackageReference;
4602+
relativePath = ../LanguageServerProtocol;
4603+
};
45814604
30AAFCD02B7380EF007177DC /* XCLocalSwiftPackageReference "../CodeEditKit" */ = {
45824605
isa = XCLocalSwiftPackageReference;
45834606
relativePath = ../CodeEditKit;
45844607
};
4608+
30E1AAB12B73856500420274 /* XCLocalSwiftPackageReference "../LanguageClient" */ = {
4609+
isa = XCLocalSwiftPackageReference;
4610+
relativePath = ../LanguageClient;
4611+
};
45854612
/* End XCLocalSwiftPackageReference section */
45864613

45874614
/* Begin XCRemoteSwiftPackageReference section */
@@ -4689,6 +4716,11 @@
46894716
package = 2816F592280CF50500DD548B /* XCRemoteSwiftPackageReference "CodeEditSymbols" */;
46904717
productName = CodeEditSymbols;
46914718
};
4719+
3039C8DC2B738D5A00C8B4F8 /* LanguageClient */ = {
4720+
isa = XCSwiftPackageProductDependency;
4721+
package = 30E1AAB12B73856500420274 /* XCLocalSwiftPackageReference "../LanguageClient" */;
4722+
productName = LanguageClient;
4723+
};
46924724
583E529B29361BAB001AB554 /* SnapshotTesting */ = {
46934725
isa = XCSwiftPackageProductDependency;
46944726
package = 583E529A29361BAB001AB554 /* XCRemoteSwiftPackageReference "swift-snapshot-testing" */;

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

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

CodeEdit/Features/Editor/Models/Editor.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,12 @@ final class Editor: ObservableObject, Identifiable {
169169
default:
170170
break
171171
}
172-
173-
do {
174-
try openFile(item: item)
175-
} catch {
176-
print(error)
177-
}
172+
// TODO: IS THIS NEEDED? openFile ALREADY GETS CALLED INSIDE openTab
173+
// do {
174+
// try openFile(item: item)
175+
// } catch {
176+
// print(error)
177+
// }
178178
}
179179

180180
/// Opens a tab in the editor.
@@ -210,6 +210,7 @@ final class Editor: ObservableObject, Identifiable {
210210
let contentType = try item.file.url.resourceValues(forKeys: [.contentTypeKey]).contentType
211211
let codeFile = try CodeFileDocument(
212212
for: item.file.url,
213+
// TODO: FILE CONTENTS ARE READ MULTIPLE TIMES
213214
withContentsOf: item.file.url,
214215
ofType: contentType?.identifier ?? ""
215216
)

CodeEdit/Features/LSP/LSPCache.swift

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
//
2+
// LSPCache.swift
3+
// CodeEdit
4+
//
5+
// Created by Abe Malla on 2/7/24.
6+
//
7+
8+
import Foundation
9+
10+
struct CacheKey: Hashable {
11+
let uri: String
12+
let requestType: String
13+
}
14+
15+
// TODO: SWITCH TO DOUBLY LINK LIST
16+
17+
/// Thread safe implementation for caching LSP requests with time based expiration and cache size limits.
18+
class LSPCache {
19+
/// Represents a single cache entry with a generic type and an expiration date.
20+
private struct CacheEntry<T> {
21+
let value: T
22+
let expirationDate: Date
23+
}
24+
25+
/// The main cache storage mapping a `CacheKey` to a generic value.
26+
private var cache = [CacheKey: Any]()
27+
/// A collection of locks, one per cache key, for thread-safe access to cache entries.
28+
/// `DispatchQueue` is used for synchronization to ensure that cache operations are thread-safe.
29+
private var locks = [CacheKey: DispatchQueue]()
30+
/// The maximum number of entries that the cache can hold.
31+
private var cacheSizeLimit: Int
32+
/// Tracks the order of cache keys for potential eviction.
33+
private var cacheEntriesOrder: [CacheKey] = []
34+
/// Queue for handling the eviction of old cache entries. Separated from main cache operations to not block them.
35+
private let evictionQueue = DispatchQueue(label: "com.CodeEdit.LSPCache.evictionQueue")
36+
37+
init(cacheSizeLimit: Int = 100) {
38+
self.cacheSizeLimit = cacheSizeLimit
39+
}
40+
41+
private func lock(for key: CacheKey) -> DispatchQueue {
42+
if let lock = locks[key] {
43+
return lock
44+
} else {
45+
let newLock = DispatchQueue(label: "com.CodeEdit.LSPCache.lock.\(key)")
46+
locks[key] = newLock
47+
return newLock
48+
}
49+
}
50+
51+
func get<T>(key: CacheKey) -> T? {
52+
var result: T?
53+
lock(for: key).sync { // Sync to ensure thread safe access
54+
guard let entry = cache[key] as? CacheEntry<T>, Date() < entry.expirationDate else { return }
55+
result = entry.value
56+
}
57+
return result
58+
}
59+
60+
func set<T>(key: CacheKey, value: T, withExpiry expiry: TimeInterval = 300) {
61+
lock(for: key).async {
62+
let expirationDate = Date().addingTimeInterval(expiry)
63+
let entry = CacheEntry(value: value, expirationDate: expirationDate)
64+
self.cache[key] = entry
65+
}
66+
scheduleEviction()
67+
}
68+
69+
func invalidate(key: CacheKey) {
70+
lock(for: key).async {
71+
self.cache.removeValue(forKey: key)
72+
}
73+
}
74+
75+
private func scheduleEviction() {
76+
// TODO: DECIDE ON EVICTION INTERVAL
77+
evictionQueue.asyncAfter(deadline: .now() + 10) {
78+
self.evictIfNeeded()
79+
}
80+
}
81+
82+
private func evictIfNeeded() {
83+
evictionQueue.async(flags: .barrier) {
84+
while self.cacheEntriesOrder.count > self.cacheSizeLimit {
85+
if let oldestKey = self.cacheEntriesOrder.first {
86+
self.cache.removeValue(forKey: oldestKey)
87+
self.cacheEntriesOrder.removeFirst()
88+
}
89+
}
90+
}
91+
}
92+
}

0 commit comments

Comments
 (0)