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

Multiple language / LSP on same file #199520

Closed
Tracked by #199888
goyalyashpal opened this issue Nov 29, 2023 · 9 comments
Closed
Tracked by #199888

Multiple language / LSP on same file #199520

goyalyashpal opened this issue Nov 29, 2023 · 9 comments
Assignees
Labels
languages-basic Basic language support issues *out-of-scope Posted issue is not in scope of VS Code

Comments

@goyalyashpal
Copy link

goyalyashpal commented Nov 29, 2023

I'd like to:

  • set multiple language modes on same file
  • so that i can use extensions belonging to both languages together on the file
  • so that i can use features from both of them together.
  • say for example:
    • hover definitions preview & completion suggestion from extensions of one language; &
    • syntax & validity error diagnostics from other one

use case:

  • using different applications of meta-languages (xml, json, etc)

practical case in hand: .xhtml files

  • live validating xml syntax & getting live error diagnostics from redhat.vscode-xml (currently in xml language mode)
    (earlier, also additional semantic constraints using grammar from doctype declarations or DTD's; but that's thing of past now)
  • documentation hover preview from vscode.html-language-features (currently in html language)

solutions:

  • one ad-hoc solution can be to provide both these features via single extension (so, creating a new one dedicated to xhtml , or putting optional xml validation in html one)
  • but that would have to be done for each of the languages based on xml (or other meta language) syntax 👀

but better would be: to have multiple different dedicated things beautifully working together :) {unix philosophy} as this would:

  • not increase the size of the html extensions - which are builtin & hence crucial to keep small
  • also become useful for other languages based on xml (like svg etc)
  • hence allow users to take benefit of good variety of functionality the xml extensions have to offer 😃 like: minify, prettify, validate, format etc

i.e. similar to the goal of LSP, this second method would keep the complexity to m + n rather than m * n
where m is features related to XML (or other such meta language), and n is number of languages based on it



this request is not to be confused with "embedded languages" or "language injections" (#1751 or https://code.visualstudio.com/api/language-extensions/embedded-languages)

there was a similar request of having multiple formatter to act on same file a while ago in context of python. i can't find that - so, sorry if a duplicate exists for multiple lsps too.

some of the tried searches 🔍 :

@goyalyashpal
Copy link
Author

goyalyashpal commented Nov 29, 2023

MWE (minimal working example/illustration):

<?xml version="1.0" encoding="UTF-8"?>
<!-- <!DOCTYPE html> -->
<!-- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> -->

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=80%, initial-scale=1.0"/>
    <title>HTML with XML</title>
</head>

<body>
    <p hidden>Attribute value validation</p>
    Entity validation: &
</body>

</html>

Modified image showing imagination of what-if-both extensions/LSs could work together

image

@gjsjohnmurray
Copy link
Contributor

Have you investigated all the links given by @aeschli in #1751 (comment)? If so, what showstoppers did you encounter?

@goyalyashpal
Copy link
Author

goyalyashpal commented Nov 29, 2023

hi @gjsjohnmurray - the use case i shared is not dealing with injections in first place.

the whole of document is to be acted upon by extensions of both the languages together.

that issue deals with injections or embeddings: "ohkay, here it's js, but inside this string, it's html"

@aeschli
Copy link
Contributor

aeschli commented Nov 29, 2023

You say you want to set multiple languages for the same file, such as XML and HTML.
But how often are two languages compatible so a file can have two languages?
In your example, you would get all XML features that are not applicable for HTML. XML snippets that are not valid in the context of HTML. And the HTML extension might produce proposals that are not XHTML.
You'd end up with a bag of features duplicating each other and not working well together.

@RedCMD
Copy link
Contributor

RedCMD commented Nov 29, 2023

#146731
#198583

@goyalyashpal
Copy link
Author

goyalyashpal commented Nov 29, 2023

hi! thanks for response. good questions.

But how often are two languages compatible so a file can have two languages?

  • this is common anytime there's need of standardised data exchange.
  • i had already shared some examples in issue description itself, will add links to those extensions
  • so, formats based on xml like android layout/*.xml, AndroidManifest.xml, java maven pom.xml, docbook, svg
  • js based formats like qml (qt)
  • miscellaneous tangential example: json based things: config files, .code-workspace files; schema formats like parse tree sitter

XML features that are not applicable for HTML. XML snippets that are not valid in the context of HTML.

umh, xml is a meta language - as far as i know, then except for some headers at the start, there ain't much else to it in terms of snippets. but if i am wrong in this context, then too i didn't face much problem with the extension i am using redhat-xml; can't say for others. do you have any tangible example?

And the HTML extension might produce proposals that are not XHTML

yep, another valid concern. but the reasons for this are multi-fold:

  • html was not originally based on xml, so, their syntax were not inherently same
  • xhtml had rough history of stark differences with html, so, it didn't catch with people early on
  • now the keyword things are in sync (xhtml5 is same as html5), but the public interest doesn't seem to be much in xhtml
  • so as of now, xhtml ain't getting attention in the dev tooling side

but this may change if some initial conducers like this are there.

other than that:

  • default html extensions (vscode.html, vscode.html-language-features, vscode.emmet) don't give any contradictory suggestions
  • the only other html extension i used was html-validate.vscode-html-validate, and yes, it produces contradictory suggestions * but xhtml confirming style options already exist & can be picked in a config file. i am working on making a bundle of those, & packing it - once it's in, it will be very easy to resolve that via some one click option.

for other html extensions too, it will come gradually as reaping initial benefits of xhtml becomes easy

[html/xhtml] You'd end up with a bag of features duplicating each other and not working well together.

for xml extensions, considering my above points w.r.t. xml, they don't do anything html specific - and they won't change even after this.

for html extensions, i think that if an extension provides inclusive valid options like the html-validate above, then it already can be made xhtml compatible with some small bundling etc. and if an extension is opinionated to be strictly lean html, then it simply won't be usable with xhtml. so, i don't see how there will be any large scale duplication.

#146731

that's only for html, but there're other things too like docbook, android layout, android manifest, office files etc...
like i said, this feature is not limited to html, nor just to xml. it can apply to any decent meta language and application files made over it which require syntax and schema validation

UPDATE 2023-12-03: this is at extension level. i was saying at the local editor level.

@goyalyashpal
Copy link
Author

goyalyashpal commented Nov 29, 2023

i have added links in description to all the extensions mentioned. this would make it easy to go to them to see all mentioned non-html & few even non-xml examples of languages based on meta-like-languages like xml, js, etc.

html ain't alone in this suffering. these quotations shows same quest:

I have also extracted the XML language definition and grammar from VSCode itself and use them to create the ZCML language in VSCode.
- erral.erral-zcmlLanguageConfiguration

You can validate a document specified by its DC file. Right-click the DC file in the Explorer view and select DAPS > Validate.
- openSUSE.daps

this would also makes it optional for these language extensions to implement their formatters. the default xml formatter (from redhat) is functional and can quench any urgent requirement for a dedicated formatter.

@aeschli
Copy link
Contributor

aeschli commented Dec 5, 2023

Currently, a document has one language id assigned to it. We don't want to change that. One language is the main language, defining the overall structure.
Language extensions contribute features against that language id. For a html document, the html language features extension provides features. However also the XML extension could decide to contribute a validator for html. Most of the language features are additive: More than one extension can provide proposals, they are all shown.
However, as I tried to explain, I think this will lead to a bad user experience. There will be duplicate functionality, e.g. duplicate proposals for the same thing, proposals that don't match, e.g. XML proposals that are or not really fitting in HTML.
It's better to have a HTML specific extension providing a tailored experience. Internally, the HTML extension implementation could reuse XML functionality through libraries. That's what we do in HTML for the embedded CSS and JavaScript.

Still, that's just our approach. The APIs allow composition, so I encourage you to try things out. Write a extension that forwards XML features to the HTML language... Or help us improve the HTML extension...

Closing as 'out of scope'. We stick with one language per document.

@aeschli aeschli closed this as completed Dec 5, 2023
@aeschli aeschli added the languages-basic Basic language support issues label Dec 5, 2023
@goyalyashpal
Copy link
Author

goyalyashpal commented Dec 5, 2023

@aeschli can u make it closed as not planned ?


2023-12-13
there's also the jinja (python) , the jsp or jspx (java) , and all other server side web page scripting languages 😃
i ain't writing any puffed up extension when exisiting ones can theoretically be composed. unix philosophy for the win.

anyhow... i will live with it for the time being.

@aeschli aeschli added the *out-of-scope Posted issue is not in scope of VS Code label Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
languages-basic Basic language support issues *out-of-scope Posted issue is not in scope of VS Code
Projects
None yet
Development

No branches or pull requests

4 participants