Sourcekitd: no such module error

I'm testing sourcekit-lsp in vscode & emacs using the latest source from github along with the latest swift toolchain.

In both editors things are generally working ok, however one of my projects builds and imports a framework which is not found by sourcekitd.

The project is setup using Xcode (not a Swift package) as follows:

Root.xcworkspace
-- App.xcodeproj
-- GradeKit.xcodeproj

If I'm editing a swift file in the app imports "GradeKit" I get the following error message (via sourcekit-lsp):

"sourcekitd: no such module GradeKit".

The GradeKit framework is located in the app's built products directory and can be found correctly by Xcode etc.

Any idea why this is and if there is a fix or work-around for sourcekit-lsp?

Thanks,

John

SourceKit-LSP does not yet support getting build settings from Xcode projects, so it won't find the build products directory, etc. We currently support getting settings from SwiftPM packages and Clang's json compilation databases. Our intention is to support using sourcekit-lsp from inside Xcode in the future, but it sounds like what you are looking for here is to be able to use e.g. emacs with sourcekit-lsp for an xcode project, right?

but it sounds like what you are looking for here is to be able to use e.g. emacs with sourcekit-lsp for an xcode project, right?

Yes, exactly. And that's the value proposition of sourcekit-lsp for my use case: I prefer Emacs to Xcode for editing, but need to use Xcode for project management (macOS and iOS app development). The same would be the case if I were a vscode user.

So, it would be ideal if sourcekit-lsp could pick up build settings from Xcode projects. Actually I wrote an extension to flycheck to do exactly that so that I can error check my code on-the-fly using swiftc in Emacs.

I'll look into the Clang json compilation db, sounds like that might be a useful workaround for now.

1 Like

FWIW I fixed the issue by creating a Package.swift compatible with my project. It's enough to compile the library and executable and seems to satisfy sourcekit-lsp. This is despite swift build requiring various build settings (-target, -framework etc) to be passed via the cmd line to successfully compile.

Glad to hear you found a workaround! We've seen some issues when the deployment version (-target) used by sourcekit is different than what's used by the build, so I suggest configuring that within your Package.swift as soon as the new settings are available:

SwiftPM master already supports this since yesterday, so it should be in toolchain snapshots as well pretty soon.

1 Like

We need to update sourcekit-lsp to use a new swiftpm revision to pick that up. I'm working on it.

That's good to know. I noticed the proposal and commits in swift-package-manager, but wasn't sure if it was complete or not.

I've just upgraded my Package.swift to swift-tools-version:5.0 with the correct platform and swift build settings. swift build now works as expected without additional arguments.

However, sourcekit-lsp is now reporting the "no such module" error again. I suspect that sourcekit-lsp is still using the 4.2 swiftpm revision? Either that or the platform target is causing problems (I'm using .macOS("10.13")). Realise this is all a WIP.

Works now. I have all this working on linux swift 4.2.0 & VSCode. THANK YOU FOR YOUR WORK

Ubuntu 18.10 / AMD64 Using Vapor APT for swift 4.2 binaries.

1 Like

Just a reminder that indexing functionality not working (e.g. 'find references') when using linux 4.2 toolchain is a known problem, you'd have to move to 5.0 to get the full functionality on linux.

If you update to the latest sourcekit-lsp and the new recommended toolchain (see New Recommended Toolchain: swift-DEVELOPMENT-SNAPSHOT-2018-12-02-a - #2) it should work. Let me know if you still see issues there!

I've got this issue on Sublime Text with this toolchain swift-DEVELOPMENT-SNAPSHOT-2019-01-05-a-osx. The project is the PerfectSwift server.

Both not working for me find references neither find definition if it's stored in another project file. But at the same time if i click find definition on some basic swift class, like Codable it opens binary files from within the toolchain folder and the autocompletion works fine.

This is just to letting you know about the issue, and one more thing i'd should mention that the problem could be in me and my misunderstanding something in the configuration process, not in the lsp server.

And the last one: could you please tell me, is there any way to download last recomended toolchain for the swift 4.2.1 on macOS? I'd be happy to develop some vapor server in the sublime, but the available from the recomended toolchains in the list on the swift site is only about swift 5.0. And unfortunately vapor crash while building on such.

Do you mean GitHub - PerfectlySoft/Perfect: Server-side Swift. The Perfect core toolset and framework for Swift Developers. (For mobile back-end development, website and API development, and more…)? Can you give more details about which code you were looking at when you saw the error? I tried the template project on macOS with the 01-05-a toolchain and things seemed to be working okay. And did you build the project first with the same toolchain?

This is a known issue. We should avoid jumping to binary files. Unfortunately the LSP doesn't give us a good way to jump to something like Codable today since there is no source file on disk for it. In Xcode we generate an interface for it, and we could potentially do something similar in other editors if we wrote the generated file to disk maybe. Needs to be designed.

Unfortunately we don't support Swift 4 toolchains for sourcekit-lsp. There have been changes to swiftpm since 4 that would cause us to not find modules from the build directory.

Do you mean GitHub - PerfectlySoft/Perfect: Server-side Swift. The Perfect core toolset and framework for Swift Developers. (For mobile back-end development, website and API development, and more…)? Can you give more details about which code you were looking at when you saw the error? I tried the template project on macOS with the 01-05-a toolchain and things seemed to be working okay. And did you build the project first with the same toolchain?

Yep. That's that one. I'd upload my project as solo repo https://github.com/yaroslavyaroslav/PerfectIssue. There's such a mess in it, but it's the only project that have been build successfully with the swift 5.0 toolchain yet.

Before report issue i did follow:

  1. export TOOLCHAINS=swift
  2. swift package reset
  3. swift package update
  4. swift build

The most projects yet works fine. Just several things are going wrong.

  • PoloneixNetworkExtention.swift line 24 && 25 addingPercentEncoding causes to unable to find addingPercentEncoding. But it rather shows popup with correct documentation.
  • PoloneixNetworkExtention.swift line 28 joined do the same.
  • All imports are failed as well. But i guess it's by design.

Are you relying on this to set the toolchain used at runtime in LSP as well? env TOOLCHAINS=swift will work at build time, but currently won't work in LSP itself (I'll fix that). You can either use env SOURCEKIT_TOOLCHAIN_PATH=/path/to/toolchain.xctoolchain or use env TOOLCHAINS=org.swift.4220190105a with the full toolchain identifier (you can find the toolchain identifier in the Info.plist file in the toolchain).

This is the part of my Sublime lsp client configuration, is this enough or should I add this into my .zshrc?

"env":
			{
				"SOURCEKIT_TOOLCHAIN_PATH": "/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2019-01-05-a.xctoolchain"
			},

That should be enough; I'll see if I can reproduce from the project you mentioned.

I have the same problem but I write a post with a work around for this "issue".

Basically I write a build pre-action and I change the BundleID and the AppName from the shell script.

Take a look to the post: