Skip to content

Commit 4e47fcd

Browse files
committed
Fix Language Servers settings page UI and search
- Replace broken ZStack overlay in LanguageServerRowView with clean VStack layout and single-line description - Replace .searchable() toolbar search with SearchField in a Section to match other settings pages - Replace List with LazyVStack for scroll performance - Replace fuzzy search with word-prefix matching for more intuitive filtering results - Style warning banner inline with small yellow icon matching Apple System Settings pattern - Remove unused getInfoString()
1 parent cec6287 commit 4e47fcd

File tree

2 files changed

+59
-96
lines changed

2 files changed

+59
-96
lines changed

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

Lines changed: 4 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ struct LanguageServerRowView: View, Equatable {
2727
@State private var removalError: Error?
2828
@State private var showingRemovalError = false
2929

30-
@State private var showMore: Bool = false
31-
3230
@EnvironmentObject var registryManager: RegistryManager
3331

3432
init(
@@ -46,49 +44,10 @@ struct LanguageServerRowView: View, Equatable {
4644
Label {
4745
VStack(alignment: .leading) {
4846
Text(package.sanitizedName)
49-
50-
ZStack(alignment: .leadingLastTextBaseline) {
51-
VStack(alignment: .leading) {
52-
Text(package.sanitizedDescription)
53-
.font(.footnote)
54-
.foregroundColor(.secondary)
55-
.lineLimit(showMore ? nil : 1)
56-
.truncationMode(.tail)
57-
if showMore {
58-
Button(package.homepagePretty) {
59-
guard let url = package.homepageURL else { return }
60-
NSWorkspace.shared.open(url)
61-
}
62-
.buttonStyle(.plain)
63-
.foregroundColor(Color(NSColor.linkColor))
64-
.font(.footnote)
65-
.cursor(.pointingHand)
66-
if let installerName = package.installMethod?.packageManagerType?.rawValue {
67-
Text("Install using \(installerName)")
68-
.font(.footnote)
69-
.foregroundColor(.secondary)
70-
}
71-
}
72-
}
73-
if isHovering {
74-
HStack {
75-
Spacer()
76-
Button {
77-
showMore.toggle()
78-
} label: {
79-
Text(showMore ? "Show Less" : "Show More")
80-
.font(.footnote)
81-
}
82-
.buttonStyle(.plain)
83-
.background(
84-
Rectangle()
85-
.inset(by: -2)
86-
.fill(.clear)
87-
.background(Color(NSColor.windowBackgroundColor))
88-
)
89-
}
90-
}
91-
}
47+
Text(package.sanitizedDescription)
48+
.font(.footnote)
49+
.foregroundColor(.secondary)
50+
.lineLimit(1)
9251
}
9352
} icon: {
9453
letterIcon()

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

Lines changed: 55 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,51 +10,72 @@ import SwiftUI
1010
/// Displays a searchable list of packages from the ``RegistryManager``.
1111
struct LanguageServersView: View {
1212
@StateObject var registryManager: RegistryManager = .shared
13-
@StateObject private var searchModel = FuzzySearchUIModel<RegistryItem>()
1413
@State private var searchText: String = ""
14+
@State private var filteredItems: [RegistryItem]?
1515
@State private var selectedInstall: PackageManagerInstallOperation?
1616

17-
@State private var showingInfoPanel = false
18-
1917
var body: some View {
20-
Group {
18+
VStack {
2119
SettingsForm {
22-
if registryManager.isDownloadingRegistry {
23-
HStack {
24-
Spacer()
25-
ProgressView()
26-
.controlSize(.small)
27-
Spacer()
28-
}
20+
Section {
21+
SearchField("Search", text: $searchText)
2922
}
3023

3124
Section {
32-
List(searchModel.items ?? registryManager.registryItems, id: \.name) { item in
33-
LanguageServerRowView(
34-
package: item,
35-
onCancel: {
36-
registryManager.cancelInstallation()
37-
},
38-
onInstall: { [item] in
39-
do {
40-
selectedInstall = try registryManager.installOperation(package: item)
41-
} catch {
42-
// Display the error
43-
NSAlert(error: error).runModal()
44-
}
25+
HStack(alignment: .firstTextBaseline, spacing: 4) {
26+
Image(systemName: "exclamationmark.triangle.fill")
27+
.font(.footnote)
28+
.foregroundColor(.yellow)
29+
Text("Warning: Language server installation is experimental. Use at your own risk.")
30+
.font(.subheadline)
31+
.foregroundColor(.secondary)
32+
}
33+
if registryManager.isDownloadingRegistry {
34+
HStack {
35+
Spacer()
36+
ProgressView()
37+
.controlSize(.small)
38+
Spacer()
39+
}
40+
} else {
41+
LazyVStack(spacing: 0) {
42+
ForEach(
43+
filteredItems ?? registryManager.registryItems,
44+
id: \.name
45+
) { item in
46+
Divider().padding(.horizontal, 10)
47+
LanguageServerRowView(
48+
package: item,
49+
onCancel: {
50+
registryManager.cancelInstallation()
51+
},
52+
onInstall: { [item] in
53+
do {
54+
selectedInstall = try registryManager.installOperation(
55+
package: item
56+
)
57+
} catch {
58+
NSAlert(error: error).runModal()
59+
}
60+
}
61+
)
62+
.padding(10)
4563
}
46-
)
47-
.listRowInsets(EdgeInsets(top: 8, leading: 8, bottom: 8, trailing: 8))
64+
}
65+
.padding(-10)
4866
}
49-
.searchable(text: $searchText)
50-
.onChange(of: searchText) { _, newValue in
51-
searchModel.searchTextUpdated(searchText: newValue, allItems: registryManager.registryItems)
67+
}
68+
}
69+
.onChange(of: searchText) { _, newValue in
70+
if newValue.isEmpty {
71+
filteredItems = nil
72+
} else {
73+
let query = newValue.lowercased()
74+
filteredItems = registryManager.registryItems.filter { item in
75+
item.sanitizedName.lowercased().split(separator: " ").contains {
76+
$0.hasPrefix(query)
77+
}
5278
}
53-
} header: {
54-
Label(
55-
"Warning: Language server installation is experimental. Use at your own risk.",
56-
systemImage: "exclamationmark.triangle.fill"
57-
)
5879
}
5980
}
6081
.sheet(item: $selectedInstall) { operation in
@@ -63,21 +84,4 @@ struct LanguageServersView: View {
6384
}
6485
.environmentObject(registryManager)
6586
}
66-
67-
private func getInfoString() -> AttributedString {
68-
let string = "CodeEdit makes use of the Mason Registry for language server installation. To install a package, "
69-
+ "CodeEdit uses the package manager directed by the Mason Registry, and installs a copy of "
70-
+ "the language server in Application Support.\n\n"
71-
+ "Language server installation is still experimental, there may be bugs and expect this flow "
72-
+ "to change over time."
73-
74-
var attrString = AttributedString(string)
75-
76-
if let linkRange = attrString.range(of: "Mason Registry") {
77-
attrString[linkRange].link = URL(string: "https://mason-registry.dev/")
78-
attrString[linkRange].foregroundColor = NSColor.linkColor
79-
}
80-
81-
return attrString
82-
}
8387
}

0 commit comments

Comments
 (0)