Skip to content

Conversation

@matthewbastien
Copy link
Member

@matthewbastien matthewbastien commented Jan 7, 2026

Description

The Swift extension exports an API that can be used by other Visual Studio Code extensions. We've had this for a while, but it was not properly documented. This PR creates src/SwiftExtensionApi.ts which defines the API surface of the Swift extension. It can be downloaded by other extensions so that they don't have to re-define types. It also allows us to be explicit in what is considered public API.

I've also added a version number to the API which will start at 0.1.0. It follows the semantic versioning standard and will only be updated when the public API changes. Downstream extensions can use this to check for compatibility with the Swift extension.

Tasks

  • Required tests have been written
  • Documentation has been updated
  • Added an entry to CHANGELOG.md if applicable

src/extension.ts Outdated
return {
workspaceContext,
logger,
version: new Version(0, 1, 0),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should formalize what requires an update to this version value.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After chatting offline, we should also move this version value into the package.json in a custom field and then read it and use it here. This keeps both the extension version and the extension API version in the same place.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added documentation for incrementing the version number and moved it into a new api-version property in the package.json.

*
* This was added to the API in Swift Extension version 2.16.0. Older versions do not provide an API version number.
*/
readonly version?: Version;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea; maybe we can have a featureset enum, akin to grpc's services. If an extension can call into the extension API expecting a list of features, you can accept the subset that is supported for the current version. Alternatively you can make that enum and just expose the featureset. Breaking changes would be a different feature e.g. featureA@1 or featureA@2. Not sure if that's a good idea, but might be worth exploring.

Copy link
Member

@Joannis Joannis Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise it's very open to interpretation by the implementation and prone to mistakes to see what you still support on a version-by-version basis.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use @since tags in the API documentation comments. That way it's clear in the API which version supports what.

readonly version?: Version;

/** The {@link WorkspaceContext} if it is currently available. */
readonly workspaceContext?: WorkspaceContext;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to get an observation on this. Since right now we don't know whether the workspace context becomes available later.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely. This is going to happen soon (have a look at #1932 for phase 1 of the plan). Right now a missing WorkspaceContext basically means that the extension failed to load. This can only be resolved by reloading the extension host so other extensions don't have to worry about it (for now).

Copy link
Member Author

@matthewbastien matthewbastien Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to completely get rid of the extension host reloading on toolchain/configuration changes which means adding events around WorkspaceContext changes. That will definitely be a breaking change to the API which is why I want to formalize what that API is now.

readonly currentDocument: vscode.Uri | null;

/** The global toolchain used as the default for this workspace. */
readonly globalToolchain: SwiftToolchain;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very helpful!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible for an extension to prompt & enact an overwrite of this value? For example, Swift on Android will be 6.3 minimum.

Copy link
Member Author

@matthewbastien matthewbastien Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The toolchain selection logic is based on a combination of VS Code settings and looking at what's configured in PATH. I think in this case it probably makes more sense to give the user a notification that they need to use Swift 6.3 and then invoke the swift.selectToolchain command to get them to change toolchains.

Speaking of commands: it would also be nice to expose their IDs as an enum in the API. I'll have to mull that over.

readonly currentDocument: vscode.Uri | null;

/** The global toolchain used as the default for this workspace. */
readonly globalToolchain: SwiftToolchain;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A similar API for the selected SDK would be helpful too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. It's available inside the SwiftToolchain interface.

readonly folder: vscode.Uri;

/** Array of available package plugins. */
readonly plugins: PackagePlugin[];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would we still manually trigger plugins, or does the VSCode extension intent to trigger these for us?

Copy link
Member Author

@matthewbastien matthewbastien Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Swift extension provides VS Code tasks for each plugin that can be used to trigger them. We could expose that in the public API depending on what you need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants