Skip to content

Handle both file paths and URLs from educational notes #2175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions Sources/SourceKitLSP/Swift/Diagnostic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,19 @@ extension Diagnostic {
educationalNotePaths.count > 0,
let primaryPath = educationalNotePaths[0]
{
let url = URL(fileURLWithPath: primaryPath)
let name = url.deletingPathExtension().lastPathComponent
code = .string(name)
codeDescription = .init(href: DocumentURI(url))
// Swift >= 6.2 returns a URL rather than a file path
let url: URL? =
if primaryPath.starts(with: "http") {
URL(string: primaryPath)
} else {
URL(fileURLWithPath: primaryPath)
}

if let url {
let name = url.deletingPathExtension().lastPathComponent
code = .string(name)
codeDescription = .init(href: DocumentURI(url))
}
}

var actions: [CodeAction]? = nil
Expand Down
9 changes: 7 additions & 2 deletions Tests/SourceKitLSPTests/LocalSwiftTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,13 @@ final class LocalSwiftTests: XCTestCase {
XCTAssertEqual(diags.diagnostics.count, 1)
let diag = diags.diagnostics.first!
XCTAssertEqual(diag.code, .string("property-wrapper-requirements"))
let filename = try XCTUnwrap(diag.codeDescription?.href.fileURL?.lastPathComponent)
XCTAssert(filename.starts(with: "property-wrapper-requirements"))

let noteUri = try XCTUnwrap(diag.codeDescription?.href)
if noteUri.fileURL != nil {
// Check we're not creating an absolute path out of a URL
XCTAssertFalse(noteUri.stringValue.contains("https://"))
}
XCTAssert(noteUri.arbitrarySchemeURL.lastPathComponent.starts(with: "property-wrapper-requirements"))
}

func testFixitsAreIncludedInPublishDiagnostics() async throws {
Expand Down