Skip to content

Commit ac91d39

Browse files
committed
[DiagnosticBridge] NFC: Refactor addQueuedDiagnostic to use BridgedCharSourceRange for diagnostic highlights
1 parent 49f254f commit ac91d39

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

include/swift/Bridging/ASTGen.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void swift_ASTGen_addQueuedDiagnostic(
3232
BridgedSourceLoc sourceLoc,
3333
BridgedStringRef categoryName,
3434
BridgedStringRef documentationPath,
35-
const void *_Nullable *_Nullable highlightRanges,
35+
const BridgedCharSourceRange *_Nullable highlightRanges,
3636
ptrdiff_t numHighlightRanges);
3737
void swift_ASTGen_renderQueuedDiagnostics(
3838
void *_Nonnull queued, ssize_t contextSize, ssize_t colorize,

lib/AST/DiagnosticBridge.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,10 @@ static void addQueueDiagnostic(void *queuedDiagnostics,
5656
}
5757

5858
// Map the highlight ranges.
59-
SmallVector<const void *, 2> highlightRanges;
59+
SmallVector<BridgedCharSourceRange, 2> highlightRanges;
6060
for (const auto &range : info.Ranges) {
61-
if (range.isInvalid())
62-
continue;
63-
64-
highlightRanges.push_back(range.getStart().getOpaquePointerValue());
65-
highlightRanges.push_back(range.getEnd().getOpaquePointerValue());
61+
if (range.isValid())
62+
highlightRanges.push_back(range);
6663
}
6764

6865
StringRef documentationPath;
@@ -76,7 +73,7 @@ static void addQueueDiagnostic(void *queuedDiagnostics,
7673
info.Category,
7774
documentationPath,
7875
highlightRanges.data(),
79-
highlightRanges.size() / 2);
76+
highlightRanges.size());
8077

8178
// TODO: A better way to do this would be to pass the notes as an
8279
// argument to `swift_ASTGen_addQueuedDiagnostic` but that requires

lib/ASTGen/Sources/ASTGen/DiagnosticsBridge.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public func addQueuedDiagnostic(
246246
cLoc: BridgedSourceLoc,
247247
categoryName: BridgedStringRef,
248248
documentationPath: BridgedStringRef,
249-
highlightRangesPtr: UnsafePointer<BridgedSourceLoc>?,
249+
highlightRangesPtr: UnsafePointer<BridgedCharSourceRange>?,
250250
numHighlightRanges: Int
251251
) {
252252
let queuedDiagnostics = queuedDiagnosticsPtr.assumingMemoryBound(
@@ -299,14 +299,16 @@ public func addQueuedDiagnostic(
299299

300300
// Map the highlights.
301301
var highlights: [Syntax] = []
302-
let highlightRanges = UnsafeBufferPointer<BridgedSourceLoc>(
302+
let highlightRanges = UnsafeBufferPointer<BridgedCharSourceRange>(
303303
start: highlightRangesPtr,
304-
count: numHighlightRanges * 2
304+
count: numHighlightRanges
305305
)
306306
for index in 0..<numHighlightRanges {
307+
let range = highlightRanges[index]
308+
307309
// Make sure both the start and the end land within this source file.
308-
guard let start = highlightRanges[index * 2].getOpaquePointerValue(),
309-
let end = highlightRanges[index * 2 + 1].getOpaquePointerValue()
310+
guard let start = range.start.getOpaquePointerValue(),
311+
let end = range.start.advanced(by: range.byteLength).getOpaquePointerValue()
310312
else {
311313
continue
312314
}

0 commit comments

Comments
 (0)