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

Configuration for non-default formatter? #4

Open
karlhorky opened this issue Dec 3, 2020 · 4 comments
Open

Configuration for non-default formatter? #4

karlhorky opened this issue Dec 3, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@karlhorky
Copy link
Contributor

karlhorky commented Dec 3, 2020

Hi @rohit-gohri 👋

I would like to run a non-default formatter on a specific file (namely the TypeScript and JavaScript Language Features, in order to format SQL in tagged template literals), and I was wondering whether you would be open to adding support for other, non-default formatters (eg. "Format Document With...")?

Not sure how the configuration would look, maybe something like:

{
  "editor.codeActionsOnSave": [
    "source.fixAll.format['vscode.typescript-language-features']"
  ]
}

Or, as an example, to format using Prettier if it's not the default:

{
  "editor.codeActionsOnSave": [
    "source.fixAll.format['esbenp.prettier-vscode']"
  ]
}

Not sure if that kind of configuration is supported though. I guess the minimal version of this feature would be to provide a single key like:

{
  "editor.codeActionsOnSave": [
    "source.fixAll.formatWithVscodeFormatter"
  ]
}

But then again, that would mean a key for any supported formatter. However, maybe it's an ok tradeoff... 🤔

@rohit-gohri
Copy link
Owner

I don't think this would be possible. In the current implementation I'm calling VSCode's Format Document action that in turn calls the default formatter (in this case prettier). I can't directly call a specific extension AFAIK. This is my first VS Code extension, so my knowledge is very limited.

You may try changing your default formatter for typescript files or in that particular workspace:

  "[typescript]": {
    "editor.defaultFormatter": "vscode.typescript-language-features",
    "editor.formatOnSave": false,
    "editor.codeActionsOnSave": ["source.fixAll.format", "source.fixAll.eslint"]
  },

@karlhorky
Copy link
Contributor Author

karlhorky commented Dec 3, 2020

Hm, yeah.. wonder if there's another API to call Format Document With... . Maybe that's something to look into...

You may try changing your default formatter for typescript files or in that particular workspace

The use case is to actually use multiple formatters in a row 😓 (Prettier first, then the built-in TS/JS thing)

@rohit-gohri
Copy link
Owner

Oh.. Will try to look into if that's possible and expose multiple actions.

You might be interested in prettier/prettier-vscode#1555
If prettier adds their own action, then you can use this with TS/JS Lang Features.

@karlhorky
Copy link
Contributor Author

You might be interested in prettier/prettier-vscode#1555

Oh, nice - thanks for the heads up! I've subscribed over there too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants