Skip to content

How to force other formatter to be used by MultiFormatter on foreign language? #28

@aleksusklim

Description

@aleksusklim

I am trying to use Multi Formatter Extension to process HTML file to be formatted as JS file and then as HTML file. I believe this is the only way to properly reformat EJS embeds <% %> as normal JS.

When I have a EJS file to be formatted, I can change the language to Javascript and format with native Typescript and Javascript Language Features, all JS embeds are formatted properly but HTML tags get broken; then, if I'll change the language to HTML and format with native HTML Language Features (while also having EJS language support installed) – all HTML is fixed while already pre-formatted JS is preserved.

I thought Multi Formatter Extension could solve this, so I set up

  "html.format.templating": true,
  "emmet.includeLanguages": {
    "ejs": "html",
  },
  "files.associations": {
    "*.ejs": "html"
  },
  "[javascript]": {
    "editor.defaultFormatter": "vscode.typescript-language-features"
  },
  "[html]": {
    "editor.defaultFormatter": "vscode.html-language-features",
    "multiFormatter.formatterList": ["vscode.typescript-language-features", "vscode.html-language-features"]
  },

But unfortunately, I see the error:
Extension 'TypeScript and JavaScript Language Features' is configured as formatter but it cannot format 'HTML'-files

I even tried to edit …\Microsoft VS Code\resources\app\extensions\typescript-language-features\package.json, adding "onLanguage:html", to "activationEvents":[ (just as MultiFormatter does it), and restarted VSCode.

But this changed nothing, and I cannot even choose Typescript and Javascript Language Features as a formatter whenever I have HTML as current language.
(Permanently changing the current language breaks EJS highlighting; I tried other EJS formatters/beautifiers with no avail).

What can I try?
Maybe it is technically possible to swap the language during multiformat itself somehow?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions