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":
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).
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:
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.
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_
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":
Here you can see that it complains about identifier
v10_14
not being in scope, when.v13
is used (I did putv10_14
there before, the issue here is that it didn't update).After multiple removals of
.build
, restarts and re-builds, it finally got it - but then I changedswift-tools-version
to 5.6 and it started reporting thatv13
is not available yet - okay, I bumped the version to 5.8 and it keeps reporting the same error: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
andtarget
, the package will build just fine when runningswift 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
Package.swift
file.Package.swift
:let package = Package( name: "MyPackage", platforms: [ .macOS(.v13) ] )