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

Extension Optional Dependency #6384

Closed
AvinZarlez opened this issue May 15, 2016 · 15 comments
Closed

Extension Optional Dependency #6384

AvinZarlez opened this issue May 15, 2016 · 15 comments
Assignees
Labels
extensions Issues concerning extensions feature-request Request for new features or functionality *out-of-scope Posted issue is not in scope of VS Code
Milestone

Comments

@AvinZarlez
Copy link

AvinZarlez commented May 15, 2016

I am writing an extension that includes snippets designed for developers using C, C++, and/or C#.

However, if I add a snippets for the language "csharp" and the C# extension/support is not installed (which by default, it is not), the extension makes an error:

[c:/Users/TobiahZ/Documents/Projects/tool-jam/vscode-comment-snippets]: Unknown language in contributes.snippets.language. Provided value: csharp

This leaves me with two options, as I understand it:

  • Include vscode.csharp in extensionDependencies
  • Do not provide csharp snippets

Ideally, I'd love to have a feature for optional dependency. If "csharp" is installed, use these snippets.

I don't like the idea of having to force people to install C# if they aren't planning on using it, just because I'd like to include optional C# snippets.

(Related follow up question: If I did include csharp as a dependency, would it automatically install csharp or does it give the user an error and/or prompt first?)

  • VSCode Version: 1.1.0
  • OS Version: Win10

Steps to Reproduce:

  1. Include csharp language snippets, without installing the C# extension:
"contributes": {
    "snippets": [
      {
        "language": "csharp",
        "path": "./snippets/csharp-snippets.json"
      },
@jrieken jrieken assigned aeschli and unassigned jrieken May 17, 2016
@aeschli
Copy link
Contributor

aeschli commented May 23, 2016

At some place the language id, it's human readable name as well as the file suffices need to be defined. Without it, you would not be able to get an editor in C# mode and the user would not be able to see your snippets.
Right now this is the vscode.csharp extension. You point out that you don't want to force everyone into installing that extension. But then having that extension is also a good thing.

At some point we discussed here if we should keep the language definition with VS code. @egamma didn't like that idea, but I think it has some merits.

Our installer doesn't yet install extension dependencies. I think that's a reasonable request, please file a request.

@alexandrudima @joaomoreno FYI

@aeschli aeschli removed their assignment May 23, 2016
@aeschli aeschli added this to the Backlog milestone May 23, 2016
@aeschli aeschli added the feature-request Request for new features or functionality label May 24, 2016
@idleberg
Copy link

idleberg commented Feb 28, 2017

I'm in the same position as @TobiahZ, I would love to mark a dependency as optional or at least have means to handle the error printed in the console (IMHO it should be a warning anyway!)

You point out that you don't want to force everyone into installing that extension. But then having that extension is also a good thing.

In the case of C#, which has an official extension handled by Microsoft, I would agree with the above (even when there might be third-party alternatives.) In my case the language is Haskell, which currently has three packages that add syntax highlighting. I want to leave the choice to the user, each has their own preference.

@rebornix
Copy link
Member

rebornix commented Apr 4, 2019

Ideally, I'd love to have a feature for optional dependency. If "csharp" is installed, use these snippets

IMO what we need here is more like optional dependency activation events, activate some features only when a specific extension is installed and activated. In the example described above, marking csharp extension as optional dependency is the first step, the next step is notifying the extension when csharp extension is activated. The second step can be implemented by adding an listener to vscode.extensions.

@sandy081 may I have your comments on this? We run into this issue where GH PR has a soft dependency on other extensions microsoft/vscode-pull-request-github#1050 but right now there is no sound solution.

@sandy081
Copy link
Member

sandy081 commented Apr 4, 2019

CC @alexandrudima

@alexdima
Copy link
Member

@rebornix Let's sync in our next 1:1 on the exact problem you're running into.

@jdneo
Copy link
Member

jdneo commented Sep 14, 2020

We have exactly the same request. Considering the following scenario:

The extension A has several features which some of the features depends on extension B. As an extension author, I can do:

  1. Make extension A explicitly depends on extension B, this makes sure that all the feature is usable. The disadvantage is that, for those features which do not depend on extension B, they are not useable until the extension B is activated.

  2. Make extension A does not depend on extension B. By doing this, we need a API to tell the extension that 'The extension B is activated', then we can register the commands that depends on extension B. (which is exactly @rebornix has said)

@alexdima
Copy link
Member

@jdneo The vscode.extensions namespace offers API to get an extension by id and activate it (if not already activated). You can register commands with a context key hasExtensionB and then define that context key once you determine at runtime that the extension B is installed and activated.

@jdneo
Copy link
Member

jdneo commented Sep 14, 2020

Thank you @alexdima.

In that model, it's A's responsibility to determine whether to register some commands.

It would be great if A could be notified that B is activated. Considering this:

We have an extension Project Manager for Java, which can create new Java projects and provide project views to the users.

One problem we are facing is that, if the user is in a non-Java project and triggers the command create new java project, he will wait for a long time until the Java language server started. This is because it's now hard depend on Java Language Server.

To make this command get executed as soon as it gets triggered, and not start the Java language server unnecessarily, we need to remove the hard dependency here. let the extension only register the create project command at activation. And after it's notified that Java language server is started, do other stuffs (initialization and consume the APIs exposed from Java language server)

@fiveisprime
Copy link
Member

There's a similar need from the Python folks, but their scenario sounds more like a plugin system than optional dependencies (it's the reverse of the original issue). In their case, the Python extension provides general Python functionality (e.g. REPL and run file in terminal) while various Python language servers can be used.

The ask is to allow for a default language server to be installed along with the Python extension but, because it's an optional/plugin to the Python extension, it can be uninstalled and replaced by a different language server extension.

This is similar in functionality to an extension pack dependency, but that's not the right solution given the UX in VS Code and the categorization in the Marketplace.

@fiveisprime
Copy link
Member

Extensions that have functionality and extensionPack property will be treated (visually) as an extension with dependencies that can be uninstalled.

Extensions that have no functionality and only extensionPack property will be treated as an extension pack.

Scenarios:
On install, the extensionPack deps are also installed.
On update, extensionPack deps should not be re-installed if it was uninstalled by the customer.

When the extension is side loaded, extensionPack deps are installed; in cases where the extension is updated via a sideload (e.g. Python insiders), extensionPack deps should not be installed.

@TylerLeonhardt
Copy link
Member

I need something similar mentioned in the comments but not in the original issue...

I need either extension A or B installed. Both satisfy. Here's what I'm doing for that:

export async function activate(context: vscode.ExtensionContext) {

	const powershellExtension = vscode.extensions.getExtension("ms-vscode.PowerShell-Preview") || vscode.extensions.getExtension("ms-vscode.PowerShell");
	if(!powershellExtension) {
		await vscode.window.showErrorMessage('Please install either the PowerShell or PowerShell Preview extension and then reload the window to use the Pester Test Explorer.');
		const activatedEvent = vscode.extensions.onDidChange(() => {
			if (vscode.extensions.getExtension('ms-vscode.PowerShell') || vscode.extensions.getExtension('ms-vscode.PowerShell-Preview')) {
				activate(context);
                                activatedEvent.dispose();
			}
		});
		return;
	}

	if (!powershellExtension.isActive) {
		await powershellExtension.activate();
	}

        // ...
}

Though there is currently an issue about vscode.extensions.onDidChange( not firing in remote microsoft/vscode-remote-release#4610

@sandy081
Copy link
Member

@fiveisprime Created a separate issue to track python extension use case - #118442

@tjcouch-sil
Copy link

It seems the built-in extension vscode.github implements the concept of an optional extension dependency to some extent by listening for the extensions.onDidChange event and such things in initializeGitExtension. I don't imagine you can make optional contributions this way, but this is another example of an optional extension dependency in extension code.

@BinToss
Copy link

BinToss commented Feb 4, 2024

I'd prefer the user be prompted to install or is recommended the extensions (like workspace extension recommendations) rather than it being auto-installed and optionally uninstalled afterward.

EDIT: redhat provides a Node package to similar effect
https://www.npmjs.com/package/@redhat-developer/vscode-extension-proposals

BinToss added a commit to BinToss/AvaloniaUI.AvaloniaVSCode that referenced this issue Feb 4, 2024
I'd prefer the user was prompted or recommended the extension rather than it being auto-installed and optionally uninstalled.
See microsoft/vscode#6384 (comment)

Perhaps this should instead be done via a dedicated extension pack instead of...this way.
BinToss added a commit to BinToss/AvaloniaUI.AvaloniaVSCode that referenced this issue Feb 4, 2024
I'd prefer the user was prompted or recommended the extension rather than it being auto-installed and optionally uninstalled.
See microsoft/vscode#6384 (comment)

Perhaps this should instead be done via a dedicated extension pack instead of...this way.
BinToss added a commit to BinToss/AvaloniaUI.AvaloniaVSCode that referenced this issue Feb 5, 2024
I'd prefer the user was prompted or recommended the extension rather than it being auto-installed and optionally uninstalled.
See microsoft/vscode#6384 (comment)

Perhaps this should instead be done via a dedicated extension pack instead of...this way.
BinToss added a commit to BinToss/AvaloniaUI.AvaloniaVSCode that referenced this issue Feb 9, 2024
I'd prefer the user was prompted or recommended the extension rather than it being auto-installed and optionally uninstalled.
See microsoft/vscode#6384 (comment)

Perhaps this should instead be done via a dedicated extension pack instead of...this way.
BinToss added a commit to BinToss/AvaloniaUI.AvaloniaVSCode that referenced this issue Feb 9, 2024
I'd prefer the user was prompted or recommended the extension rather than it being auto-installed and optionally uninstalled.
See microsoft/vscode#6384 (comment)

Perhaps this should instead be done via a dedicated extension pack instead of...this way.
BinToss added a commit to BinToss/AvaloniaUI.AvaloniaVSCode that referenced this issue Mar 19, 2024
I'd prefer the user was prompted or recommended the extension rather than it being auto-installed and optionally uninstalled.
See microsoft/vscode#6384 (comment)

Perhaps this should instead be done via a dedicated extension pack instead of...this way.
@EronWright
Copy link

To recap, any type of extension may declare an optional dependency via the extensionPack field. When the extension is installed, the optional dependenc(ies) are automatically installed and uninstalled. A user is able to disable and/or uninstall the dependenc(ies). An "extension pack" tab also appears on the extension's management page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extensions Issues concerning extensions feature-request Request for new features or functionality *out-of-scope Posted issue is not in scope of VS Code
Projects
None yet
Development

No branches or pull requests

14 participants