Sourcekitd: no such module error

(John Buckley) #1

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:

-- 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?



(Ben Langmuir) #2

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?

(John Buckley) #3

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.

(John Buckley) #4

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.

(Ben Langmuir) #5

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:

(Boris Buegling) #6

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

(Ben Langmuir) #7

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

(John Buckley) #8

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.

(Argyrios Kyrtzidis) #10

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.

(Ben Langmuir) #11

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