Skip to content

Commit 26d2b66

Browse files
committed
Finish Rename
1 parent c7d7823 commit 26d2b66

File tree

7 files changed

+46
-38
lines changed

7 files changed

+46
-38
lines changed

Sources/CodeEditSourceEditor/Highlighting/StyledRangeContainer/StyledRangeContainer.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ protocol StyledRangeContainerDelegate: AnyObject {
1818
/// See ``runsIn(range:)`` for more details on how conflicting highlights are handled.
1919
@MainActor
2020
class StyledRangeContainer {
21-
struct StyleElement: StyledRangeStoreElement, CustomDebugStringConvertible {
21+
struct StyleElement: RangeStoreElement, CustomDebugStringConvertible {
2222
var capture: CaptureName?
2323
var modifiers: CaptureModifierSet
2424

@@ -82,10 +82,10 @@ class StyledRangeContainer {
8282
///
8383
/// - Parameter range: The range to query.
8484
/// - Returns: An array of continuous styled runs.
85-
func runsIn(range: NSRange) -> [StyledRangeStoreRun<StyleElement>] {
85+
func runsIn(range: NSRange) -> [RangeStoreRun<StyleElement>] {
8686
// Ordered by priority, lower = higher priority.
8787
var allRuns = _storage.sorted(by: { $0.key < $1.key }).map { $0.value.runs(in: range.intRange) }
88-
var runs: [StyledRangeStoreRun<StyleElement>] = []
88+
var runs: [RangeStoreRun<StyleElement>] = []
8989

9090
var minValue = allRuns.compactMap { $0.last }.enumerated().min(by: { $0.1.length < $1.1.length })
9191

@@ -140,7 +140,7 @@ extension StyledRangeContainer: HighlightProviderStateDelegate {
140140
assertionFailure("No storage found for the given provider: \(provider)")
141141
return
142142
}
143-
var runs: [StyledRangeStoreRun<StyleElement>] = []
143+
var runs: [RangeStoreRun<StyleElement>] = []
144144
var lastIndex = rangeToHighlight.lowerBound
145145

146146
for highlight in highlights {
@@ -150,7 +150,7 @@ extension StyledRangeContainer: HighlightProviderStateDelegate {
150150
continue // Skip! Overlapping
151151
}
152152
runs.append(
153-
StyledRangeStoreRun<StyleElement>(
153+
RangeStoreRun<StyleElement>(
154154
length: highlight.range.length,
155155
value: StyleElement(capture: highlight.capture, modifiers: highlight.modifiers)
156156
)

Sources/CodeEditSourceEditor/RangeStore/RangeStore+OffsetMetric.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ import _RopeModule
99

1010
extension RangeStore {
1111
struct OffsetMetric: RopeMetric {
12-
typealias Element = StyledRun
12+
typealias Element = StoredRun
1313

14-
func size(of summary: RangeStore.StyledRun.Summary) -> Int {
14+
func size(of summary: RangeStore.StoredRun.Summary) -> Int {
1515
summary.length
1616
}
1717

18-
func index(at offset: Int, in element: RangeStore.StyledRun) -> Int {
18+
func index(at offset: Int, in element: RangeStore.StoredRun) -> Int {
1919
return offset
2020
}
2121
}

Sources/CodeEditSourceEditor/RangeStore/RangeStore+StyledRun.swift renamed to Sources/CodeEditSourceEditor/RangeStore/RangeStore+StoredRun.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
//
2-
// RangeStore+StyledRun.swift
2+
// RangeStore+StoredRun.swift
33
// CodeEditSourceEditor
44
//
55
// Created by Khan Winter on 10/25/24
66

77
import _RopeModule
88

99
extension RangeStore {
10-
struct StyledRun {
10+
struct StoredRun {
1111
var length: Int
1212
let value: Element?
1313

1414
static func empty(length: Int) -> Self {
15-
StyledRun(length: length, value: nil)
15+
StoredRun(length: length, value: nil)
1616
}
1717

1818
/// Compare two styled ranges by their stored styles.
@@ -32,7 +32,7 @@ extension RangeStore {
3232
}
3333
}
3434

35-
extension RangeStore.StyledRun: RopeElement {
35+
extension RangeStore.StoredRun: RopeElement {
3636
typealias Index = Int
3737

3838
var summary: Summary { Summary(length: length) }
@@ -63,28 +63,28 @@ extension RangeStore.StyledRun: RopeElement {
6363
}
6464
}
6565

66-
extension RangeStore.StyledRun {
66+
extension RangeStore.StoredRun {
6767
struct Summary {
6868
var length: Int
6969
}
7070
}
7171

72-
extension RangeStore.StyledRun.Summary: RopeSummary {
72+
extension RangeStore.StoredRun.Summary: RopeSummary {
7373
// FIXME: This is entirely arbitrary. Benchmark this.
7474
@inline(__always)
7575
static var maxNodeSize: Int { 10 }
7676

7777
@inline(__always)
78-
static var zero: RangeStore.StyledRun.Summary { Self(length: 0) }
78+
static var zero: RangeStore.StoredRun.Summary { Self(length: 0) }
7979

8080
@inline(__always)
8181
var isZero: Bool { length == 0 }
8282

83-
mutating func add(_ other: RangeStore.StyledRun.Summary) {
83+
mutating func add(_ other: RangeStore.StoredRun.Summary) {
8484
length += other.length
8585
}
8686

87-
mutating func subtract(_ other: RangeStore.StyledRun.Summary) {
87+
mutating func subtract(_ other: RangeStore.StoredRun.Summary) {
8888
length -= other.length
8989
}
9090
}

Sources/CodeEditSourceEditor/RangeStore/RangeStore.swift

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@
77

88
import _RopeModule
99

10-
/// RangeStore is a container type that allows for setting and querying captures and modifiers for syntax
11-
/// highlighting. The container reflects a text document in that its length needs to be kept up-to-date.
10+
/// RangeStore is a container type that allows for setting and querying values for relative ranges in text. The
11+
/// container reflects a text document in that its length needs to be kept up-to-date. It can efficiently remove and
12+
/// replace subranges even for large documents. Provides helper methods for keeping some state in-sync with a text
13+
/// document's content.
1214
///
1315
/// Internally this class uses a `Rope` from the swift-collections package, allowing for efficient updates and
1416
/// retrievals.
15-
struct RangeStore<Element: StyledRangeStoreElement>: Sendable {
16-
typealias Run = StyledRangeStoreRun<Element>
17-
typealias RopeType = Rope<StyledRun>
17+
struct RangeStore<Element: RangeStoreElement>: Sendable {
18+
typealias Run = RangeStoreRun<Element>
19+
typealias RopeType = Rope<StoredRun>
1820
typealias Index = RopeType.Index
1921
var _guts = RopeType()
2022

@@ -27,7 +29,7 @@ struct RangeStore<Element: StyledRangeStoreElement>: Sendable {
2729
private var cache: (range: Range<Int>, runs: [Run])?
2830

2931
init(documentLength: Int) {
30-
self._guts = RopeType([StyledRun(length: documentLength, value: nil)])
32+
self._guts = RopeType([StoredRun(length: documentLength, value: nil)])
3133
}
3234

3335
// MARK: - Core
@@ -83,7 +85,7 @@ struct RangeStore<Element: StyledRangeStoreElement>: Sendable {
8385
_guts.replaceSubrange(
8486
range,
8587
in: OffsetMetric(),
86-
with: runs.map { StyledRun(length: $0.length, value: $0.value) }
88+
with: runs.map { StoredRun(length: $0.length, value: $0.value) }
8789
)
8890

8991
coalesceNearby(range: range)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//
2+
// RangeStoreElement.swift
3+
// CodeEditSourceEditor
4+
//
5+
// Created by Khan Winter on 5/28/25.
6+
//
7+
8+
protocol RangeStoreElement: Equatable, Hashable {
9+
var isEmpty: Bool { get }
10+
func combineLowerPriority(_ other: Self?) -> Self
11+
func combineHigherPriority(_ other: Self?) -> Self
12+
}

Sources/CodeEditSourceEditor/RangeStore/RangeStoreRun.swift

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,37 @@
11
//
2-
// StyledRangeStoreRun.swift
2+
// RangeStoreRun.swift
33
// CodeEditSourceEditor
44
//
55
// Created by Khan Winter on 11/4/24.
66
//
77

8-
protocol StyledRangeStoreElement: Equatable, Hashable {
9-
var isEmpty: Bool { get }
10-
func combineLowerPriority(_ other: Self?) -> Self
11-
func combineHigherPriority(_ other: Self?) -> Self
12-
}
13-
148
/// Consumer-facing value type for the stored values in this container.
15-
struct StyledRangeStoreRun<Element: StyledRangeStoreElement>: Equatable, Hashable {
9+
struct RangeStoreRun<Element: RangeStoreElement>: Equatable, Hashable {
1610
var length: Int
1711
var value: Element?
1812

1913
static func empty(length: Int) -> Self {
20-
StyledRangeStoreRun(length: length, value: nil)
14+
RangeStoreRun(length: length, value: nil)
2115
}
2216

2317
var isEmpty: Bool {
2418
value?.isEmpty ?? true
2519
}
2620

27-
mutating func combineLowerPriority(_ other: StyledRangeStoreRun) {
21+
mutating func combineLowerPriority(_ other: RangeStoreRun) {
2822
value = value?.combineLowerPriority(other.value) ?? other.value
2923
}
3024

31-
mutating func combineHigherPriority(_ other: StyledRangeStoreRun) {
25+
mutating func combineHigherPriority(_ other: RangeStoreRun) {
3226
value = value?.combineHigherPriority(other.value) ?? other.value
3327
}
3428

35-
mutating func subtractLength(_ other: borrowing StyledRangeStoreRun) {
29+
mutating func subtractLength(_ other: borrowing RangeStoreRun) {
3630
self.length -= other.length
3731
}
3832
}
3933

40-
extension StyledRangeStoreRun: CustomDebugStringConvertible {
34+
extension RangeStoreRun: CustomDebugStringConvertible {
4135
var debugDescription: String {
4236
if let value = value as? CustomDebugStringConvertible {
4337
"\(length) (\(value.debugDescription))"

Tests/CodeEditSourceEditorTests/Highlighting/StyledRangeContainerTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import XCTest
22
@testable import CodeEditSourceEditor
33

44
final class StyledRangeContainerTests: XCTestCase {
5-
typealias Run = StyledRangeStoreRun<StyledRangeContainer.StyleElement>
5+
typealias Run = RangeStoreRun<StyledRangeContainer.StyleElement>
66

77
@MainActor
88
func test_init() {

0 commit comments

Comments
 (0)