jota0222 / MultiFormatterVSCode

It's a Visual Studio Code that allows you to use multiple formatters in just one run
GNU General Public License v3.0
10 stars 15 forks source link

Automatic or Configurable language support #9

Open Stadly opened 11 months ago

Stadly commented 11 months ago

Would it be possible to automatically check the supported languages of the listed formatters and use those as the languages supported by this extension?

jota0222 commented 9 months ago

Hi @Stadly sorry for the delayed reply.

According to what I know, there is no a programatic way to know which formatters are for which languages, to do so it will be necessary to create a map manually, but, to be honest, I don't think it deserves the time since you just need to configure the languages once for a project.

If you have a better way to do it I will ask you to try implementing it, the repo is open to receive any PR.

Indy-rbo commented 7 months ago

Hi @jota0222 Looking at https://github.com/Vehmloewff/custom-format it seems to allow you to set a language to register your formatter for:

"custom-format.formatters": [
    {
      "language": "languageIdentifier",
      "command": "commandContent"
    }
  ]

Do you think it's possible to add a setting like multiFormatter.languages which takes in an array of language identifiers? It's not automatic like the initial issue asks, but it allows users to supply their own array of languages, replacing the need for a PR to supported-languages.ts.

Reading the VSCode activation event docs we could use onLanguage as the activationEvents

jota0222 commented 6 months ago

This could be a good improvement, I will try to add it but it can take a while since I do this in my free time, and I don't have much at this moment 😅

a-laughlin commented 6 months ago

Correct me if I'm wrong, but wouldn't:

"activationEvents": [
    "onLanguage"
]

...combined with...

languages.registerDocumentRangeFormattingEditProvider('*', {
      async provideDocumentRangeFormattingEdits(document) {...}
});

... make this work automatically for all languages? And it would remove the need to define supported languages or submit PRs for them.

a-laughlin commented 6 months ago

Just tested the above solution. It works.

a-laughlin commented 6 months ago

@jota0222 I can submit a PR for this if you'd like. I've been testing it out. VScode already has an error message for when the language isn't supported by the formatter.

jota0222 commented 2 months ago

@a-laughlin I tried to do that when I created the first version of the extensión, however, for an unknown reason it only worked for me if I add a limited list of languages. If it works for you now, you can indeed create the PR so I can test it again