Skip to content

Commit f5af711

Browse files
committed
Update CESE Protocol Conformances
1 parent 5b8e3b2 commit f5af711

File tree

6 files changed

+142
-170
lines changed

6 files changed

+142
-170
lines changed

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

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

CodeEdit/Features/LSP/Features/AutoComplete/AutoCompleteCoordinator.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ class AutoCompleteCoordinator {
2020
/// The current filter text based on partial token input
2121
private var currentFilterText: String = ""
2222
/// Stores the unfiltered completion items
23-
private var completionItems: [CompletionItem] = []
23+
private var completionItems: [AutoCompleteItem] = []
2424

2525
init(_ file: CEWorkspaceFile) {
2626
self.file = file
2727
}
2828

29-
private func fetchCompletions(position: Position) async -> [CompletionItem] {
29+
private func fetchCompletions(position: Position) async -> [AutoCompleteItem] {
3030
let workspace = await file?.fileDocument?.findWorkspace()
3131
guard let file,
3232
let workspacePath = workspace?.fileURL?.absoluteURL.path(),
@@ -51,9 +51,9 @@ class AutoCompleteCoordinator {
5151
// Extract the completion items list
5252
switch completions {
5353
case .optionA(let completionItems):
54-
return completionItems
54+
return completionItems.map { AutoCompleteItem($0) }
5555
case .optionB(let completionList):
56-
return completionList.items
56+
return completionList.items.map { AutoCompleteItem($0) }
5757
case .none:
5858
return []
5959
}
@@ -63,7 +63,7 @@ class AutoCompleteCoordinator {
6363
}
6464

6565
/// Filters completion items based on the current partial token input
66-
private func filterCompletionItems(_ items: [CompletionItem]) -> [CompletionItem] {
66+
private func filterCompletionItems(_ items: [AutoCompleteItem]) -> [AutoCompleteItem] {
6767
guard !currentFilterText.isEmpty else {
6868
return items
6969
}
@@ -183,9 +183,9 @@ extension AutoCompleteCoordinator: CodeSuggestionDelegate {
183183
func completionWindowApplyCompletion(
184184
item: CodeSuggestionEntry,
185185
textView: TextViewController,
186-
cursorPosition: CursorPosition
186+
cursorPosition: CursorPosition?
187187
) {
188-
guard let item = item as? CompletionItem else { return }
188+
guard let cursorPosition, let item = item as? AutoCompleteItem else { return }
189189

190190
// Make the updates
191191
let replacementRange = currentNode?.range ?? cursorPosition.range
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
//
2+
// AutoCompleteItem.swift
3+
// CodeEdit
4+
//
5+
// Created by Khan Winter on 7/25/25.
6+
//
7+
8+
import SwiftUI
9+
import CodeEditSourceEditor
10+
import LanguageServerProtocol
11+
12+
/// A Near 1:1 of `LanguageServerProtocol`'s `CompletionItem`. Wrapped for compatibility with the CESE's
13+
/// `CodeSuggestionEntry` protocol to deal with some optional bools.
14+
struct AutoCompleteItem: Hashable, Sendable, CodeSuggestionEntry {
15+
let label: String
16+
let kind: CompletionItemKind?
17+
let detail: String?
18+
let documentation: TwoTypeOption<String, MarkupContent>?
19+
let deprecated: Bool
20+
let preselect: Bool
21+
let sortText: String?
22+
let filterText: String?
23+
let insertText: String?
24+
let insertTextFormat: InsertTextFormat?
25+
let textEdit: TwoTypeOption<TextEdit, InsertReplaceEdit>?
26+
let additionalTextEdits: [TextEdit]?
27+
let commitCharacters: [String]?
28+
let command: LanguageServerProtocol.Command?
29+
let data: LSPAny?
30+
31+
// Not used by regular autocomplete items
32+
public var pathComponents: [String]? { nil }
33+
public var targetPosition: CursorPosition? { nil }
34+
35+
// LSP Spec says the `detail` field holds useful syntax information about the item for completion.
36+
public var sourcePreview: String? { detail }
37+
38+
public var image: Image { Image(systemName: kind?.symbolName ?? "dot.square.fill") }
39+
public var imageColor: SwiftUI.Color { kind?.swiftUIColor ?? SwiftUI.Color.gray }
40+
41+
init(_ item: CompletionItem) {
42+
self.label = item.label
43+
self.kind = item.kind
44+
self.detail = item.detail
45+
self.documentation = item.documentation
46+
self.deprecated = item.deprecated ?? false
47+
self.preselect = item.preselect ?? false
48+
self.sortText = item.sortText
49+
self.filterText = item.filterText
50+
self.insertText = item.insertText
51+
self.insertTextFormat = item.insertTextFormat
52+
self.textEdit = item.textEdit
53+
self.additionalTextEdits = item.additionalTextEdits
54+
self.commitCharacters = item.commitCharacters
55+
self.command = item.command
56+
self.data = item.data
57+
}
58+
}

CodeEdit/Features/LSP/LSPUtil.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ enum LSPCompletionItemsUtil {
3838
return edits
3939
}
4040

41-
static func getInsertText(from completionItem: CompletionItem) -> String {
41+
static func getInsertText(from completionItem: AutoCompleteItem) -> String {
4242
// According to LSP spec, textEdit takes precedence if present, then insertText, then label
4343
if let textEdit = completionItem.textEdit {
4444
switch textEdit {

CodeEdit/Features/LSP/Views/CompletionItem.swift

Lines changed: 0 additions & 91 deletions
This file was deleted.

CodeEdit/Features/LSP/Views/CompletionItemKind.swift

Lines changed: 73 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -9,77 +9,82 @@ import SwiftUI
99
import LanguageServerProtocol
1010

1111
extension CompletionItemKind {
12-
static func toSymbolName(kind: CompletionItemKind?) -> String {
13-
let defaultSymbol = "dot.square.fill"
14-
15-
guard let kind = kind else {
16-
return defaultSymbol
12+
var symbolName: String {
13+
switch self {
14+
case .text:
15+
"t.square.fill"
16+
case .method, .module:
17+
"m.square.fill"
18+
case .function:
19+
"curlybraces.square.fill"
20+
case .constructor, .interface:
21+
"i.square.fill"
22+
case .field, .class, .color:
23+
"c.square.fill"
24+
case .variable:
25+
"v.square.fill"
26+
case .property:
27+
"p.square.fill"
28+
case .unit:
29+
"u.square.fill"
30+
case .value:
31+
"n.square.fill"
32+
case .enum, .enumMember, .event:
33+
"e.square.fill"
34+
case .keyword, .constant:
35+
"k.square.fill"
36+
case .snippet, .struct:
37+
"s.square.fill"
38+
case .file:
39+
"d.square.fill"
40+
case .reference:
41+
"r.square.fill"
42+
case .folder:
43+
"f.square.fill"
44+
case .operator:
45+
"plus.slash.minus"
46+
case .typeParameter:
47+
"t.square.fill"
1748
}
18-
19-
let symbolMap: [CompletionItemKind: String] = [
20-
.text: "t.square.fill",
21-
.method: "m.square.fill",
22-
.function: "curlybraces.square.fill",
23-
.constructor: "i.square.fill",
24-
.field: "c.square.fill",
25-
.variable: "v.square.fill",
26-
.class: "c.square.fill",
27-
.interface: "i.square.fill",
28-
.module: "m.square.fill",
29-
.property: "p.square.fill",
30-
.unit: "u.square.fill",
31-
.value: "n.square.fill",
32-
.enum: "e.square.fill",
33-
.keyword: "k.square.fill",
34-
.snippet: "s.square.fill",
35-
.color: "c.square.fill",
36-
.file: "d.square.fill",
37-
.reference: "r.square.fill",
38-
.folder: "f.square.fill",
39-
.enumMember: "e.square.fill",
40-
.constant: "k.square.fill",
41-
.struct: "s.square.fill",
42-
.event: "e.square.fill",
43-
.operator: "plus.slash.minus",
44-
.typeParameter: "t.square.fill"
45-
]
46-
return symbolMap[kind] ?? defaultSymbol
4749
}
4850

49-
static func toSymbolColor(kind: CompletionItemKind?) -> SwiftUICore.Color {
50-
let defaultColor = Color.gray
51-
52-
guard let kind = kind else {
53-
return defaultColor
51+
var swiftUIColor: SwiftUI.Color {
52+
switch self {
53+
case .text,
54+
.function,
55+
.interface,
56+
.module,
57+
.unit,
58+
.value,
59+
.color,
60+
.file,
61+
.reference,
62+
.folder,
63+
.enumMember,
64+
.constant,
65+
.struct,
66+
.event,
67+
.operator,
68+
.typeParameter:
69+
Color.blue
70+
case .variable:
71+
Color.green
72+
case .method:
73+
Color.cyan
74+
case .constructor:
75+
Color.teal
76+
case .field:
77+
Color.indigo
78+
case .class:
79+
Color.pink
80+
case .property:
81+
Color.purple
82+
case .enum:
83+
Color.mint
84+
case .keyword:
85+
Color.pink
86+
case .snippet:
87+
Color.purple
5488
}
55-
56-
let symbolMap: [CompletionItemKind: SwiftUICore.Color] = [
57-
.text: Color.blue,
58-
.method: Color.cyan,
59-
.function: Color.blue,
60-
.constructor: Color.teal,
61-
.field: Color.indigo,
62-
.variable: Color.blue,
63-
.class: Color.pink,
64-
.interface: Color.blue,
65-
.module: Color.blue,
66-
.property: Color.purple,
67-
.unit: Color.blue,
68-
.value: Color.blue,
69-
.enum: Color.mint,
70-
.keyword: Color.pink,
71-
.snippet: Color.purple,
72-
.color: Color.blue,
73-
.file: Color.blue,
74-
.reference: Color.blue,
75-
.folder: Color.blue,
76-
.enumMember: Color.blue,
77-
.constant: Color.blue,
78-
.struct: Color.blue,
79-
.event: Color.blue,
80-
.operator: Color.blue,
81-
.typeParameter: Color.blue,
82-
]
83-
return symbolMap[kind] ?? defaultColor
8489
}
8590
}

0 commit comments

Comments
 (0)