swiftlang / vscode-swift

Visual Studio Code Extension for Swift
https://marketplace.visualstudio.com/items?itemName=sswg.swift-lang
Apache License 2.0
705 stars 47 forks source link

Phantom errors, caching issues. #920

Closed ahoppen closed 1 week ago

ahoppen commented 1 week ago

Originally filed by @adamwych on the SourceKit-LSP repository: https://github.com/apple/sourcekit-lsp/issues/1495


Swift version

swiftlang-5.10.0.13, 6.0-dev (490cf64aee23f13)

Platform

macOS 14.3.1

Editor

VSCode with Swift extension 1.10.2

Does the issue reproduce with Swift 6?

Yes

Description

LSP (in my case running in VSCode) very often reports errors, that do not in fact exist in the code.

The context here is an empty project, just a "Hello, world":

image

Here you can see that it complains about identifier v10_14 not being in scope, when .v13 is used (I did put v10_14 there before, the issue here is that it didn't update).

image

After multiple removals of .build, restarts and re-builds, it finally got it - but then I changed swift-tools-version to 5.6 and it started reporting that v13 is not available yet - okay, I bumped the version to 5.8 and it keeps reporting the same error:

image

I also encountered issues in another project where the LSP was reporting that a class member did not exist, while at the same time showing me the definition of that field right below the error...

Note that after I add a product and target, the package will build just fine when running swift build, there are no compilation errors, but the LSP will continue to report those kinds of errors.

For me, it happens very often when working on Swift code and it makes it a chore rather than a pleasure. There is no way to get rid of those phantom errors other than by removing the .build, restarting the editor, reloading LSP and hoping that finally it will work - in case of bigger projects, fully re-building them all the time is obviously terrible and sometimes it doesn't even work! Sometimes I need to fully re-build them multiple times, which makes no sense.

Steps to Reproduce

  1. Create a folder and a Package.swift file.
  2. Put this into Package.swift:
    
    // swift-tools-version:5.9
    import PackageDescription

let package = Package( name: "MyPackage", platforms: [ .macOS(.v13) ] )


3. Change version on the top to 5.6 and save the file.
4. Change version back to 5.9 and save the file.
5. **Change the tab to another file** and the error will pop up.

### Logging

_No response_
plemarquand commented 1 week ago

This looks to be a duplicate of the original issue, #912. Work is being tracked there. Closing.