Is VS Code integration broken on Mac now? How to debug? Wrong 'No such module' errors

Hi. Something has happened to my VS Code and I do not remember which update made it break.

VS Code: 1.95.3
Swift Extension: 1.11.3
macOS: 15.1 (M1)

swift --version

swift-driver version: 1.115 Apple Swift version 6.0.2 (swiftlang-6.0.2.1.2 clang-1600.0.26.4)
Target: arm64-apple-macosx15.0

It now struggles to find anything imported. For example, in Package.swift on the very first two lines:

// swift-tools-version:5.10
import PackageDescription

I get the following error displayed:

No such module 'PackageDescription'

This and many other errors prevent me from doing basic stuff such as viewing the variable types or jumping to definitions.

And yet it compiles and the debugger runs fine! In addition, many import statements are failing in random parts. Such as No such module 'Vapor' and so on.

Am I the only one this unlucky? Can anyone suggest how to debug this problem? Restarting the editor did not help so far.

Thank you!

Sounds like it could be an issue with how sourcekit-lsp is set up.

Could you run the > Swift Capture VS Code Diagnostic Bundle command and attach the output in a .zip? Capturing minimal diagnostics should be OK.

Here is the minimal diagnostic (I have only adjusted the project name). It was surprisingly short and only two files.

extension-logs.txt:

15:49:05: SourceKit-LSP setup
15:49:05: Failed to find /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/lldb-vscode
15:49:07: MyServer: add: /Users/ruslan/Projects/MyServer
15:49:07: MyServer: focus: /Users/ruslan/Projects/MyServer

settings.txt:

Apple Swift version 6.0.2 (swiftlang-6.0.2.1.2 clang-1600.0.26.4)
Swift Path: /usr/bin
Toolchain Path: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr
Runtime Library Path: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx:/usr/lib/swift
Default Target: arm64-apple-macosx15.0
Default SDK: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.1.sdk
XCTest Path: /Applications/Xcode.app/Contents/Developer/usr/bin
Settings:
{
  "path": "",
  "buildArguments": [],
  "additionalTestArguments": [],
  "testEnvironmentVariables": {},
  "sanitizer": "off",
  "searchSubfoldersForPackages": false,
  "autoGenerateLaunchConfigurations": true,
  "disableAutoResolve": true,
  "diagnosticsCollection": "keepSourceKit",
  "diagnosticsStyle": "llvm",
  "backgroundCompilation": false,
  "actionAfterBuildError": "Focus Terminal",
  "buildPath": "",
  "disableSwiftPackageManagerIntegration": false,
  "warnAboutSymlinkCreation": true,
  "enableTerminalEnvironment": true,
  "excludeFromCodeCoverage": [],
  "excludePathsFromPackageDependencies": [
    ".git",
    ".github"
  ],
  "showBuildStatus": "swiftStatus",
  "showCreateSwiftProjectInWelcomePage": true,
  "openAfterCreateNewProject": "prompt",
  "sourcekit-lsp": {
    "serverPath": "",
    "serverArguments": [],
    "supported-languages": [
      "swift",
      "objective-c",
      "objective-cpp",
      "c",
      "cpp"
    ],
    "backgroundIndexing": true,
    "trace": {
      "server": "off"
    },
    "disable": false
  },
  "debugger": {
    "useDebugAdapterFromToolchain": false,
    "path": ""
  },
  "swiftEnvironmentVariables": {},
  "runtimePath": "",
  "SDK": "",
  "diagnostics": false
}

Before the update if your swift version was 6.0.1 then the update that moved you to 6.0.2 might have cause the lldb-vs-code to be removed… just my two cents…

Nothing is jumping out at me right away. Is the problem still there if you simply create a new package with swift package init and open the Package.swift?

If it is open that generated package in VS Code, try and trigger an auto completion in the Package.swift and then do > Swift Capture VS Code Diagnostic Bundle capturing a full diagnostic instead of a minimal bundle.

You can also check the contents of Output > SourceKit Language Server (from the dropdown in the Output tab) and look for suspicious errors.

I have created a new empty project, and it worked perfectly well. All features working well.

Next I decided to try removing .index-build folder (it did not help), but then I removed it together with the .buid folder before recompiling. This time the LSP worked perfectly fine again.

I have captured the full diagnostics before removing the old .build folder. The crashes and logs folders are empty. However, the log.txt was not empty.

Does anyone know how I can attach a text file to messages in this forum? The log file does not tell me much, but maybe it will help the extension and LSP developers in the future at some point.

To be honest, I have previously encountered cases where running swift package update broke something, preventing the project from compiling at all until I manually removed the .build folder. Unfortunately, I never figured out what went wrong nor how to reproduce the issue.