Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose the API via exports instead of editor commands #2855

Merged
merged 2 commits into from
Aug 3, 2020

Conversation

TylerLeonhardt
Copy link
Member

PR Summary

So my first attempt at doing an external API was totally wrong.

Turns out, extensions can export things that other extensions can use... this is how the Test Explorer extension works:
https://github.com/hbenl/vscode-test-explorer/blob/82e7d339c5ef25c2e02ca5be8f63f46eadd07e8f/src/main.ts#L116-L123

Anyway, not much changes here besides how you access the API... simply:

const powershellExtension = vscode.extensions.getExtension<IPowerShellExtensionClient>("ms-vscode.PowerShell-Preview");
const powerShellExtensionClient = powershellExtension!.exports as IPowerShellExtensionClient;

Then you're good to go:

const sessionId = powerShellExtensionClient.registerExternalExtension("ms-vscode.powershell-test-explorer");
const versionDetails = powerShellExtensionClient.getPowerShellVersionDetails(sessionId);

I mentioned as a TODO in code that this should be wrapped in a simple npm package that hides the management of sessionId and checks for both PowerShell and PowerShell Preview extensions.

PR Checklist

Note: Tick the boxes below that apply to this pull request by putting an x between the square brackets.
Please mark anything not applicable to this PR NA.

  • PR has a meaningful title
  • Summarized changes
  • PR has tests
  • This PR is ready to merge and is not work in progress
    • If the PR is work in progress, please add the prefix WIP: to the beginning of the title and remove the prefix when the PR is ready

@TylerLeonhardt TylerLeonhardt merged commit bb5dbb8 into PowerShell:master Aug 3, 2020
@TylerLeonhardt TylerLeonhardt deleted the redo-api-correctly branch August 3, 2020 17:22
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.

2 participants