Skip to content
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

Fix Package.swift diagnostics line off by 1 for tools versions <= 5.7 #7795

Merged
merged 4 commits into from
Jul 19, 2024
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
6 changes: 4 additions & 2 deletions Sources/PackageLoading/ManifestLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -768,13 +768,15 @@ public final class ManifestLoader: ManifestLoaderProtocol {
if toolsVersion >= .v5_8 {
manifestPreamble = ByteString()
} else {
manifestPreamble = ByteString("import Foundation\n")
manifestPreamble = ByteString("\nimport Foundation")
}

do {
try withTemporaryDirectory { tempDir, cleanupTempDir in
let manifestTempFilePath = tempDir.appending("manifest.swift")
try localFileSystem.writeFileContents(manifestTempFilePath, bytes: ByteString(manifestPreamble.contents + manifestContents))
// Since this isn't overwriting the original file, append Foundation library
// import to avoid having diagnostics being displayed on the incorrect line.
try localFileSystem.writeFileContents(manifestTempFilePath, bytes: ByteString(manifestContents + manifestPreamble.contents))

let vfsOverlayTempFilePath = tempDir.appending("vfs.yaml")
try VFSOverlay(roots: [
Expand Down
2 changes: 1 addition & 1 deletion Tests/WorkspaceTests/WorkspaceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ final class WorkspaceTests: XCTestCase {
testDiagnostics(observability.diagnostics) { result in
let diagnostic = result.check(
diagnostic: .contains(
"\(pkgDir.appending("Package.swift")):4:8: error: An error in MyPkg"
"\(pkgDir.appending("Package.swift")):3:8: error: An error in MyPkg"
),
severity: .error
)
Expand Down