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

Clash between two extensions using same language alias #2862

Closed
gjsjohnmurray opened this issue Feb 4, 2019 · 15 comments
Closed

Clash between two extensions using same language alias #2862

gjsjohnmurray opened this issue Feb 4, 2019 · 15 comments
Assignees
Labels
extensibility extension author content under /api

Comments

@gjsjohnmurray
Copy link
Contributor

Version: 1.30.2 (user setup)
OS: Windows_NT x64 10.0.16299

(also present in 1.31.0-insider)

I am developing a language extension (not yet published in Marketplace). It contributes three language IDs:
image

I have also installed a Marketplace extension intended for the same language, which contributes three different language IDs but assigns one of them the same name (ObjectScript) as one of mine:
image

When both extensions are enabled and I open the 'Select Language Mode' picker there is only one 'ObjectScript' entry despite every list entry also displaying the language ID in parentheses as a suffix, i.e.
image

Combined, the two extensions offer only five choices rather than six.

The documentation at https://code.visualstudio.com/docs/languages/identifiers didn't help me understand whether what I'm seeing is intentional. Nor does it say how the aliases array is supposed to function.

@jrieken jrieken assigned alexdima and unassigned jrieken Feb 4, 2019
@alexdima
Copy link
Member

Are these really different languages or the same programming language? If they are the same language, may I recommend to use the same language identifier.

Internally, we have maps and the maps will get overwritten/become conflicting. We have a map from file extension to language id (this will be conflicting in this case), another map for language name to language id (this is the one you notice in your screenshot), another map for language id to language name, etc... When picking the same language id, language name, or file extensions, these will be overwritten.

There are two possible solutions:

  • aim at extension compatibility, i.e. both extensions should work at the same time. In this case, aim at reusing existing language ids if there exists an extension already and it is established.
  • extension exclusivity. You can check via extensions.all if the other extension is installed and prompt users, explaining that they need to disable one or the other...

@gjsjohnmurray
Copy link
Contributor Author

@alexandrudima - Thanks for your response. They are the same programming languages.

Is the 'language name' you mention always the first element of the aliases array in a member of the languages array in an extension's package.json?

Or do second and third aliases have equal significance with first aliases?

The doc at https://code.visualstudio.com/docs/languages/identifiers#_new-identifier-guidelines advises:

Search for other extensions in the Marketplace to find out if a language identifier has already been used.

Sounds like we also need to check language names as well as identifiers, right?

@alexdima
Copy link
Member

alexdima commented Feb 11, 2019

Sounds like we also need to check language names as well as identifiers, right?

Yes, clashes in filename extension, language ids and language names will have funny effects, as you have found.

I recommend that you use the same language id and language names as already established. If you don't like to repeat the same definition, you can add an extension dependency from your extension to the other extension.

@gjsjohnmurray
Copy link
Contributor Author

OK, thanks. Please can that doc section be improved? Either under this issue (which is why I haven't yet closed it), or on a fresh one. Ideally add info about aliases too.

@alexdima
Copy link
Member

@alexdima alexdima transferred this issue from microsoft/vscode Jul 5, 2019
@gregvanl gregvanl added the extensibility extension author content under /api label Jul 8, 2019
@gregvanl
Copy link

Closing as no PR submitted.

@pecigonzalo
Copy link

pecigonzalo commented Mar 12, 2020

I have a similar/related question. How are the users able to select between two extensions providing the same language?
I'm developing one that provides only syntax highlighting and grammar, but I would like to be compatible with the existing one, so I'm using the same language id but despite changing the aliases lists and other tricks.

I cant seem to get it to display both and let the user choose while keeping the same languages.id. Ideally, be able to set file associations to my extension so grammar and syntax are pulled from it but completion/etc uses the other extension.

It would be great to better describe what grammars.scopeName and grammars.language do along with lanaguages.id and languages.aliases

pecigonzalo added a commit to pecigonzalo/vscode-terraform-syntax that referenced this issue Mar 12, 2020
@alexdima
Copy link
Member

@pecigonzalo What you desire is currently not possible.

@pecigonzalo
Copy link

pecigonzalo commented Mar 17, 2020 via email

@alexdima
Copy link
Member

@pecigonzalo There is no user-facing picker for grammars (in case multiple extensions register multiple grammars for the same language). But extensions are currently processed in alphabetical order. If extension B comes after extension A alphabetically, then extension B has a chance to override certain contributions done by extension A.

That being said, it is unlikely that we will build a user-facing picker for grammars. IMHO, for the wide community, it is far better to contribute a PR to the established grammar than to start a grammar from scratch, so I would like to ask why do you write a new grammar from scratch for Go and Python. Why don't you contribute to the existing ones, to improve them for all of the users of those extensions?

@pecigonzalo
Copy link

@alexdima There is the files.associations section. Isnt that the picker?

It is better in many cases to contribute to centralized grammar, but I might want to submit a different grammar, which some users might prefer and some don't, so I would just create a new grammar extension. Ideally, users should be given the ability to choose, as we do in all software and linters and etc.

IMO It would be a lot better to stop bundling 30 functions in 1 extension, like grammar/syntax with LSP and linter/formatter as they could be safely decoupled.

Just to clarify, I'm not trying to do a Go or Python syntax, but rather a Terraform one. https://github.com/mauve/vscode-terraform the most widely used one, but there is also https://github.com/4ops/vscode-language-terraform and some others. So it would be great to use and support mauve functionality on formatting and integration to LSP but use a different syntax.

@pecigonzalo
Copy link

@alexdima any thoughts on this? Could we maybe re open the issue?

@dionjwa
Copy link

dionjwa commented Aug 14, 2020

As example: browser Typescript, and Deno. Both use the .ts extension, but the std lib for each is completely different, and requires a different language mode.

@alexdima
Copy link
Member

alexdima commented Sep 2, 2020

@dionjwa We don't currently have any other setting than files.associations. That can be defined at the user level, per-folder or per-workspace.

@pecigonzalo I am sorry I still don't 100% understand what would you want us to do in VS Code? I mean we definitely detect the fact that there are two definitions for two distinct grammars for the same language. Should we offer a user setting that would be respected in case of clashes?

@GitMensch
Copy link

Should we offer a user setting that would be respected in case of clashes?

Yes, for example a variante to the language identifier as it is done in the SARIF spec, you can even use the extension name for that and this way have

"files.associations": {
	"*.S": "asm/some.extension",
	"*.asm": "asm/other.ext",
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extensibility extension author content under /api
Projects
None yet
Development

No branches or pull requests

7 participants