swiftlang / vscode-swift

Visual Studio Code Extension for Swift
https://marketplace.visualstudio.com/items?itemName=sswg.swift-lang
Apache License 2.0
754 stars 54 forks source link

[macOS] Properly handle cases where `lldb-dap` cannot be found with xcrun #1119

Closed matthewbastien closed 1 month ago

matthewbastien commented 1 month ago

Some users were seeing the extension fail to activate due to lldb-dap not being found in the toolchain. I've tracked this down to three underlying issues with the extension:

  1. The DebugAdapter.verifyDebugAdapterExists() function was awaited on extension startup
  2. The SwiftToolchain.getLLDB() and SwiftToolchain.getLLDBDebugAdapter() functions can throw errors when the executables are not found. This was not being caught properly by DebugAdapter.verifyDebugAdapterExists().
  3. There are inconsistencies between DebugAdapter.adapterName and DebugAdapter.getAdapterType() that can cause them to return different debug adapters under certain circumstances.

The DebugAdapter.verifyDebugAdapterExists() will now catch errors thrown by the SwiftToolchain when finding executables and the extension activation now properly runs this check in the background. I've also updated the docstrings for getLLDB() and getLLDBDebugAdapter() to make it more obvious that they can throw and added some tests in the hopes that this won't happen again.

I've replaced the DebugAdapter.adapterName property and DebugAdapter.getAdapterType() function with a single DebugAdapter.getLaunchConfigType() function. This will hopefully reduce any further issues with adapter mismatches from happening in the future.

I've added mock-fs as a dependency now since these new tests rely on a lot of file system checks and it's easier to mock the fs module this way. The documentation for writing tests has been updated to reflect this.

Related issues: #1069 #1077