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

Package.swift diagnostics on wrong line #7688

Closed
1 task done
award999 opened this issue Jun 19, 2024 · 2 comments
Closed
1 task done

Package.swift diagnostics on wrong line #7688

award999 opened this issue Jun 19, 2024 · 2 comments
Assignees
Labels

Comments

@award999
Copy link

Is it reproducible with SwiftPM command-line tools: swift build, swift test, swift package etc?

  • Confirmed reproduction steps with SwiftPM CLI.

Description

SwiftPM diagnostics for the Package.swift show up at a different line/column than SourceKit-LSP. In this picture the first diagnostics is from SourceKit and shows up at right place, but SwiftPM indicates the diagnostic is on the next line
Screenshot 2024-06-19 at 1 12 31 PM

Expected behavior

No response

Actual behavior

No response

Steps to reproduce

  1. Set macOS platform to v13 in Package.swift
  2. Set swift tool version to 5.6: // swift-tools-version: 5.6
  3. Save file and swift package resolve

Notice output:
Screenshot 2024-06-19 at 2 01 58 PM

As you can see in the picture above the line was line 9, so line is off by one, but the column seems right

Swift Package Manager version/commit hash

No response

Swift & OS version (output of swift --version ; uname -a)

swift-driver version: 1.110 Apple Swift version 6.0 (swiftlang-6.0.0.4.52 clang-1600.0.21.1.3)
Target: arm64-apple-macosx15.0

@MaxDesiatov
Copy link
Contributor

Is this reproducible for errors in other files too, or only Package.swift?

@award999
Copy link
Author

Only seems to be this specific case in Package.swift, for example doing something like this put on the right line (22 like I'd expect):
Screenshot 2024-06-19 at 3 42 34 PM

All diagnostics from swiftc seem correct

@bripeticca bripeticca self-assigned this Jul 5, 2024
MaxDesiatov pushed a commit that referenced this issue Jul 19, 2024
…#7795)

Fixes issue #7688

SwiftPM was implicitly prepending the manifest with 'import Foundation'
for toolchains using Swift toolchain versions 5.7 and under. The
original file itself was never overwritten, thus the diagnostics being
reported would always present on the next line.

This is a quick fix that appends the same line to the end of the
manifest; doing so assures that the intended behaviour doesn't change,
but allows for correct diagnostics to be reported.

### Motivation:

Diagnostics would present on the incorrect line for Package.swift files
using tools version 5.7 and under.

### Modifications:

When evaluating the manifest, a temporary directory copies the contents
of the manifest to a temporary file; rather than prepending the import
to Foundation at the top of the file (causing all lines in the
diagnostic reports to be off by one), append the import to the bottom of
the temporary manifest when dealing with tools versions 5.7 and under.

### Result:

The intended behaviour that requires users to explicitly import
Foundation doesn't change for Swift versions 5.8 and up; diagnostics
reported for Package.swift files for those using swift <= 5.7 will now
show on the correct line.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants