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

Avoid hard-coding extension ID except in package.json #786

Closed
radeksimko opened this issue Sep 22, 2021 · 3 comments · Fixed by #807
Closed

Avoid hard-coding extension ID except in package.json #786

radeksimko opened this issue Sep 22, 2021 · 3 comments · Fixed by #807
Labels
enhancement New feature or request

Comments

@radeksimko
Copy link
Member

Problem Statement

Currently we have the extension ID hard-coded in a number of places:

const extensionId = 'hashicorp.terraform';

const ext = vscode.extensions.getExtension('hashicorp.terraform');

const ext = vscode.extensions.getExtension('hashicorp.terraform');

Additionally in some places we relatedly use the global vscode.extensions API which we shouldn't need to use given that this is mainly designed for accessing APIs of other extensions and our code should be testable without relying on such high-level API.

This prevents us from re-publishing the extension easily under a different name or a publisher and also makes it difficult to run tests in such circumstances. Lastly it forces us to effectively write E2E tests for code that can otherwise be just unit-tested in isolation.

This is a pre-requisite for #774

Expected Maintainer Experience

  • Maintainer is able to run tests regardless of any particular name or publisher values in package.json
  • It is sufficient to replace fields in package.json to enable publishing of a different build or testing in a "sandbox" publisher

Proposal

  • VSCode provides vscode.ExtensionContext as part of the activate() call, which itself already provides access to the extension itself. We can use this to pull out the extension ID + version dynamically from package.json where necessary (e.g. for telemetry reporting)
  • For tests we can decouple the code that needs to be tested into existing/separate files, so that it becomes importable and testable without having to go through the whole extension activation lifecycle
@jpogran
Copy link
Contributor

jpogran commented Sep 22, 2021

We can also move the telemetry key to the package.json file and access it with typescript magic context.extension.packageJSON.apiKey

@radeksimko radeksimko mentioned this issue Sep 22, 2021
6 tasks
@jpogran
Copy link
Contributor

jpogran commented Oct 12, 2021

The context.extension property was added in 1.55: https://code.visualstudio.com/updates/v1_55#_new-extension-property-on-extensioncontext.

Extension authors can now use the new extension property on ExtensionContext, which is passed into the extension's activate function. This returns the same Extension instance that vscode.extensions.getExtension() returns, which contains properties such as the extension's ID, version, and a serialized packageJSON property where you can access data directly from your extension's package.json file.

We'll have to bump our minimum version of VS Code from 1.52.0 to 1.55.0 in order to use this property instead of vscode.extensions.getExtension(<extension-id>)

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants