SourceKit-LSP System Library Targets

I'm trying to develop a small application on Linux that makes use of libgpiod.

I've declared a Package.swift file that contains a systemLibrary target (as described in SE-0208).

My language server is sending a diagnostic of "no such module" with the textDocument/publishDiagnostics notification. Does that means that system library targets are not supported yet in the language server or do I need to provide extra configuration to enable this feature?

I would have expected it to work since to sourcekit it’s just compiler arguments from swiftpm, but haven’t tested it. Is there an easy way to reproduce on either maxOS or Ubuntu?

tl;dr My current work around is to stop the language server after adding an import statement to a systemLibrary. Then restart it.

So I kept playing with it last night. I finally got it working. Sort of. I think there is some bug but I'm not quite sure how to describe it or where it comes from yet. I'm still trying to come up with a minimal reproduction of it. I'm also not sure if it is just systemLibrary targets or all.

I noticed that whenever adding a new file that contains an import to a systemLibrary I have to stop the language server and restart it. Then the diagnostics disappear.

Preliminary Reproduction Steps

I've gone ahead and pushed the scaffold of the library here. It is presumed that VSCode and sourcekit-lsp are already properly configured.

  1. git clone
  2. cd swift-libgpiod
  3. git checkout 460046249da35b34570a357bace1af44745f1d97
  4. code .
  5. Open main.swift and you should see no diagnostic errors.
  6. git checkout 24ed5f06876182e4bd17e162e3017fe4f99cc796
    • Note: Before doing this 2nd git checkout do not close VSCode or sourcekit-lsp.
    • I typically run the git checkout on a terminal external to VSCode but I don't think this is necessary.
  7. With main.swift still open there should now be an error use of unresolved identifier 'Chip' originating from sourcekitd.
  8. Open Chip.swift there is now an error no such module 'Clibgpiod' originating from sourcekitd.
    • Also note that at this time and at every step previously swift build and swift run worked fine.
  9. Now close VSCode and re-launch. All the diagnostic errors are gone and the language server works as expected (until a new file importing Clibgpiod is made).

This was all done on Ubuntu 19.10 with a daily build of the master branch of the Swift toolchain from 17 March 2020.

Ah, this sounds like the first known issue on this list:

We don't automatically update compiler arguments from SwiftPM, we only compute them on start. It's not specific to system libraries.

Ben I'm sorry about that. I didn't realize that was the same issue. Sorry about wasting your time.

No problem at all!