Skip to content

Commit ed9dfe6

Browse files
Update notifications
1 parent 2f2c022 commit ed9dfe6

File tree

4 files changed

+78
-11
lines changed

4 files changed

+78
-11
lines changed

CodeEdit/Features/LSP/Registry/RegistryManager.swift

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ private let installPath = homeDirectory
1414
.appending(path: "Library")
1515
.appending(path: "Application Support")
1616
.appending(path: "CodeEdit")
17-
.appending(path: "extensions")
17+
.appending(path: "language-servers")
1818

1919
final class RegistryManager {
2020
static let shared: RegistryManager = .init()
@@ -122,13 +122,34 @@ final class RegistryManager {
122122
guard let manager = Self.createPackageManager(for: method) else {
123123
throw PackageManagerError.invalidConfiguration
124124
}
125-
try await manager.install(method: method)
126125

126+
// Add to activity viewer
127+
let activityTitle = "\(entry.name)\("@" + (method.version ?? "latest"))"
128+
NotificationCenter.default.post(
129+
name: .taskNotification,
130+
object: nil,
131+
userInfo: [
132+
"id": entry.name,
133+
"action": "create",
134+
"title": "Installing \(activityTitle)"
135+
]
136+
)
137+
138+
do {
139+
try await manager.install(method: method)
140+
} catch {
141+
Self.updateActivityViewer(entry.name, activityTitle, fail: true)
142+
// Throw error again so the UI can catch it
143+
throw error
144+
}
145+
146+
// Save to settings
127147
installedLanguageServers[entry.name] = .init(
128148
packageName: entry.name,
129149
isEnabled: true,
130150
version: method.version ?? ""
131151
)
152+
Self.updateActivityViewer(entry.name, activityTitle, fail: false)
132153
}
133154

134155
/// Attempts downloading from `url`, with error handling and a retry policy
@@ -227,6 +248,55 @@ final class RegistryManager {
227248
return nil
228249
}
229250
}
251+
252+
/// Updates the activity viewer with the status of the language server installation
253+
private static func updateActivityViewer(
254+
_ id: String,
255+
_ activityName: String,
256+
fail failed: Bool
257+
) {
258+
if failed {
259+
NotificationCenter.default.post(
260+
name: .taskNotification,
261+
object: nil,
262+
userInfo: [
263+
"id": id,
264+
"action": "update",
265+
"title": "Could not install \(activityName)",
266+
"isLoading": false
267+
]
268+
)
269+
NotificationCenter.default.post(
270+
name: .taskNotification,
271+
object: nil,
272+
userInfo: [
273+
"id": id,
274+
"action": "deleteWithDelay",
275+
"delay": 5.0,
276+
]
277+
)
278+
} else {
279+
NotificationCenter.default.post(
280+
name: .taskNotification,
281+
object: nil,
282+
userInfo: [
283+
"id": id,
284+
"action": "update",
285+
"title": "Successfully installed \(activityName)",
286+
"isLoading": false
287+
]
288+
)
289+
NotificationCenter.default.post(
290+
name: .taskNotification,
291+
object: nil,
292+
userInfo: [
293+
"id": id,
294+
"action": "deleteWithDelay",
295+
"delay": 5.0,
296+
]
297+
)
298+
}
299+
}
230300
}
231301

232302
/// `CachedRegistry` is a timer based cache that will remove the registry items from memory

CodeEdit/Features/Settings/Models/SettingsData.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ struct SettingsData: Codable, Hashable {
109109
case .location:
110110
LocationsSettings().searchKeys.forEach { settings.append(.init(name, isSetting: true, settingName: $0)) }
111111
case .languageServers:
112-
LanguageServerSettings().searchKeys.forEach { settings.append(.init(name, isSetting: true, settingName: $0)) }
112+
LanguageServerSettings().searchKeys.forEach {
113+
settings.append(.init(name, isSetting: true, settingName: $0))
114+
}
113115
case .developer:
114116
developerSettings.searchKeys.forEach { settings.append(.init(name, isSetting: true, settingName: $0)) }
115117
case .behavior: return [.init(name, settingName: "Error")]

CodeEdit/Features/Settings/Pages/Extensions/LanguageServerRowView.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ struct LanguageServerRowView: View, Equatable {
2222
@State private var isInstalling: Bool = false
2323
@State private var isInstalled: Bool = false
2424
@State private var isEnabled = false
25-
@State private var installProgress: Double = 0.0
2625

2726
init(
2827
packageName: String,
@@ -115,7 +114,7 @@ struct LanguageServerRowView: View, Equatable {
115114
@ViewBuilder
116115
private func isInstallingRow() -> some View {
117116
ZStack {
118-
CECircularProgressView(progress: installProgress)
117+
CECircularProgressView()
119118
.frame(width: 20, height: 20)
120119
Button {
121120
isInstalling = false
@@ -134,14 +133,9 @@ struct LanguageServerRowView: View, Equatable {
134133
private func isHoveringRow() -> some View {
135134
Button {
136135
isInstalling = true
137-
withAnimation(.linear(duration: 3)) {
138-
installProgress = 0.75
139-
}
136+
140137
Task {
141138
await onInstall()
142-
withAnimation(.linear(duration: 1)) {
143-
installProgress = 1.0
144-
}
145139
isInstalling = false
146140
isInstalled = true
147141
isEnabled = true

CodeEdit/Features/Settings/Pages/Extensions/LanguageServersView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ struct LanguageServersView: View {
3535
do {
3636
try await RegistryManager.shared.installPackage(package: item)
3737
} catch {
38+
didError = true
3839
installationFailure = InstallationFailure(error: error.localizedDescription)
3940
}
4041
}

0 commit comments

Comments
 (0)