The Swift extension has exposed a public API for some time now that can be used by other VS Code extensions to query information about the active Swift workspace including:
- Swift Toolchains: The active Swift toolchain both globally and on a per-project basis.
- Swift Projects: A list of all known Swift projects in the active workspace.
- SPM Packages: Swift Package Manager targets, products, dependencies, and plugins.
However, this API is not well documented and requires extension authors to write their own TypeScript types. Re-defining these types in every extension is not feasible long term. So, I've put up a PR that aims to reduce the friction for extension authors.
Going forward, the Swift extension will provide TypeScript types for it's public API in the src/SwiftExtensionAPI.ts file which can be downloaded as a build step by other extensions via GitHub. This file will serve as both the definition and documentation for the public API surface. I've added a version number which can be used to determine which features are available at runtime and whether or not any breaking changes have been made.
Check out the PR on GitHub: Add typings and documentation for the Swift extension's API by matthewbastien · Pull Request #2030 · swiftlang/vscode-swift · GitHub
I'm only aware of one extension that uses this API, but I'd like to hear more from any interested community members before moving forward. Any feedback either here or in the PR itself is greatly appreciated!