I'am testing SourceKit-LSP in vscode & linux and I am failing to make it work properly.
It doesn't seem to recognize some of modules, for example: it recognizes Foundation but not PackageDescriotion.
I have tried with multiple builds of Swift with no positive results.
Would you mind filing a bug on bugs.swift.org, component "SourceKit-LSP" with some details about what version of sourcekit-lsp you're using and what exactly you're trying? For example, does this reproduce the error?
cd /tmp
mkdir pkg
swift package init
code .
# Open Package.swift in VSCode; are there errors?
I have the same problem and it is not because the workspace is in my home folder.
I have a tmp directory in my home directory:
cd ~/tmp
mkdir pkg
cd pkg # <== This was not in your instruction but I assume that was needed.
swift package init
code .
When I then open Package.swift I get 1 error and 3 warnings. The error is:
no such module 'PackageDescription'
The warnings are all valid.
I am running this on macOS 10.15.3 using the latest version of sourcekit-lsp.
Some additional information. In my "normal" code in my Sources directory I have two sub-directories where one contains a module and the other the application. Also the import from the module from the application folder shows this problem. Also all packages that are downloaded through Packages.swift show the error.
I believe the issue is you are using the latest master sourcekit-lsp combined with a toolchain (5.1) that has an older swiftpm. Because of how we use libSwiftpm these need to be in sync. If your goal is to use sourcekit-lsp with the 5.1 toolchain, you could try building the swift-5.1-branch of sourcekit-lsp (or get sourcekit-lsp out of the 5.1 toolchain download on Swift.org/downloads). If your goal is to hack on sourcekit-lsp, you would want to use a newer toolchain instead. More info at sourcekit-lsp/Development.md at main · apple/sourcekit-lsp · GitHub
If I understand correctly, you're using a toolchain from swift.org, but building sourcekit-lsp from source? If so, could you try the sourcekit-lsp that is included in the toolchain (/usr/bin/sourcekit-lsp)? Also, have you verified that the correct toolchain and sourcekit-lsp are being used? If you look in Activity Monitor while it's running, you can choose the sourcekit-lsp and SourceKitService processes and check under "info" > open files, and see that they are using the correct path.
hello I think I solved the problem. but I have another problem.
I just opened sourcekit-lsp swift project file on vscode to check if it works or not.
As you can see, only that XCTest has a problem like
Glad you figured out the first issue! For the failure to import XCTest inside LinuxMain.swift, I think the problem is that file is only part of the SwiftPM target on Linux (CC @Aciid to confirm), so if you open it on macOS we have no compiler arguments for it. If that's the issue, it should only impart LinuxMain.swift and no other files.
No, I'm saying that this error is probably expected in LinuxMain.swift when running on macOS. If you're seeing it elsewhere, it's a separate issue that we can look into.
then I configured sourcekit-lsp path in a vscode plugin named "Maintained Swift Development Environment", but vscode editor still can't find PackageDescription. There seems no problem with other packages.
no such module 'packagedescription' sourcekitd
I guess the problem lies in libSwiftpm and sourcekit-lsp version mismatch? Is there a way I can find out libSwiftpm version and change it?
I also downloaded an older toolchain from swift.org, it is the swift 5.2.5 one. However I can only change toolchain in Xcode, it doesn't affect xcrun and vscode.
To clarify: it's only in the Package.swift file itself you're seeing problem, but things work in other files? Or is it the whole package?
I guess the problem lies in libSwiftpm and sourcekit-lsp version mismatch? Is there a way I can find out libSwiftpm version and change it?
Did you build your package using the same toolchain as you ran sourcekit-lsp from? If so, they should match.
I also downloaded an older toolchain from swift.org, it is the swift 5.2.5 one. However I can only change toolchain in Xcode, it doesn't affect xcrun and vscode.
On the command-line, you can use the TOOLCHAINS environment variable or --toolchain argument to xcrun to specify a specific toolchain. I believe "TOOLCHAINS=swift" should choose the most recent open source toolchain, or you can specify a specific toolchain bundle identifier. E.g.