Skip to content

Commit b0ed459

Browse files
committed
FIx Warnings & Compiler Errors
1 parent ee0c00a commit b0ed459

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Views/MockCompletionDelegate.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,12 @@ private let text = [
4545
]
4646

4747
class MockCompletionDelegate: CodeSuggestionDelegate, ObservableObject {
48+
var lastPosition: CursorPosition?
49+
4850
class Suggestion: CodeSuggestionEntry {
4951
var label: String
5052
var detail: String?
53+
var documentation: String? = nil
5154
var pathComponents: [String]?
5255
var targetPosition: CursorPosition? = CursorPosition(line: 10, column: 20)
5356
var sourcePreview: String?
@@ -89,19 +92,32 @@ class MockCompletionDelegate: CodeSuggestionDelegate, ObservableObject {
8992
cursorPosition: CursorPosition
9093
) async -> (windowPosition: CursorPosition, items: [CodeSuggestionEntry])? {
9194
try? await Task.sleep(for: .seconds(0.2))
95+
lastPosition = cursorPosition
9296
return (cursorPosition, randomSuggestions())
9397
}
9498

9599
func completionOnCursorMove(
96100
textView: TextViewController,
97101
cursorPosition: CursorPosition
98102
) -> [CodeSuggestionEntry]? {
103+
// Check if we're typing all in a row.
104+
guard (lastPosition?.range.location ?? 0) + 1 == cursorPosition.range.location else {
105+
lastPosition = nil
106+
moveCount = 0
107+
return nil
108+
}
109+
110+
lastPosition = cursorPosition
99111
moveCount += 1
100112
switch moveCount {
101113
case 1:
102114
return randomSuggestions(2)
103115
case 2:
104116
return randomSuggestions(20)
117+
case 3:
118+
return randomSuggestions(4)
119+
case 4:
120+
return randomSuggestions(1)
105121
default:
106122
moveCount = 0
107123
return nil

Example/CodeEditSourceEditorExample/CodeEditSourceEditorExample/Views/MockJumpToDefinitionDelegate.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@ final class MockJumpToDefinitionDelegate: JumpToDefinitionDelegate, ObservableOb
1515
url: nil,
1616
targetRange: CursorPosition(line: 0, column: 10),
1717
typeName: "Start of Document",
18-
sourcePreview: "// Comment at start"
18+
sourcePreview: "// Comment at start",
19+
documentation: "Jumps to the comment at the start of the document. Useful?"
1920
),
2021
JumpToDefinitionLink(
2122
url: URL(string: "https://codeedit.app/"),
2223
targetRange: CursorPosition(line: 1024, column: 10),
2324
typeName: "CodeEdit Website",
24-
sourcePreview: "https://codeedit.app/"
25+
sourcePreview: "https://codeedit.app/",
26+
documentation: "Opens CodeEdit's homepage! You can customize how links are handled, this one opens a "
27+
+ "URL."
2528
)
2629
]
2730
}

Sources/CodeEditSourceEditor/Controller/TextViewController+Cursor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ extension TextViewController {
9696
let linePosition = textView.layoutManager.textLineForIndex(position.start.line - 1) else {
9797
return nil
9898
}
99-
if let end = position.end, let endPosition = textView.layoutManager.textLineForIndex(end.line - 1) {
99+
if position.end != nil {
100100
range = NSRange(
101101
location: linePosition.range.location + position.start.column,
102102
length: linePosition.range.max

Sources/CodeEditSourceEditor/TreeSitter/TreeSitterClient+Temporary.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ extension TreeSitterClient {
5151
return HighlightRange(range: range, capture: captureName)
5252
}
5353

54-
var string = NSMutableAttributedString(string: string)
54+
let string = NSMutableAttributedString(string: string)
5555

5656
for highlight in highlights {
5757
string.setAttributes(

0 commit comments

Comments
 (0)