Skip to content

Commit 1ddda8a

Browse files
authored
Merge pull request #2183 from hamishknight/2175-6.2
2 parents fc5bffd + 7221a87 commit 1ddda8a

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

Sources/SourceKitLSP/Swift/Diagnostic.swift

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,19 @@ extension Diagnostic {
248248
educationalNotePaths.count > 0,
249249
let primaryPath = educationalNotePaths[0]
250250
{
251-
let url = URL(fileURLWithPath: primaryPath)
252-
let name = url.deletingPathExtension().lastPathComponent
253-
code = .string(name)
254-
codeDescription = .init(href: DocumentURI(url))
251+
// Swift >= 6.2 returns a URL rather than a file path
252+
let url: URL? =
253+
if primaryPath.starts(with: "http") {
254+
URL(string: primaryPath)
255+
} else {
256+
URL(fileURLWithPath: primaryPath)
257+
}
258+
259+
if let url {
260+
let name = url.deletingPathExtension().lastPathComponent
261+
code = .string(name)
262+
codeDescription = .init(href: DocumentURI(url))
263+
}
255264
}
256265

257266
var actions: [CodeAction]? = nil

Tests/SourceKitLSPTests/LocalSwiftTests.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,8 +379,13 @@ final class LocalSwiftTests: XCTestCase {
379379
XCTAssertEqual(diags.diagnostics.count, 1)
380380
let diag = diags.diagnostics.first!
381381
XCTAssertEqual(diag.code, .string("property-wrapper-requirements"))
382-
let filename = try XCTUnwrap(diag.codeDescription?.href.fileURL?.lastPathComponent)
383-
XCTAssert(filename.starts(with: "property-wrapper-requirements"))
382+
383+
let noteUri = try XCTUnwrap(diag.codeDescription?.href)
384+
if noteUri.fileURL != nil {
385+
// Check we're not creating an absolute path out of a URL
386+
XCTAssertFalse(noteUri.stringValue.contains("https://"))
387+
}
388+
XCTAssert(noteUri.arbitrarySchemeURL.lastPathComponent.starts(with: "property-wrapper-requirements"))
384389
}
385390

386391
func testFixitsAreIncludedInPublishDiagnostics() async throws {

0 commit comments

Comments
 (0)