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

"Format Selection With..." Missing From Markdown Files #183466

Closed
cjbarth opened this issue May 25, 2023 · 3 comments
Closed

"Format Selection With..." Missing From Markdown Files #183466

cjbarth opened this issue May 25, 2023 · 3 comments
Assignees
Labels
*extension-candidate Issue identified as good extension implementation

Comments

@cjbarth
Copy link

cjbarth commented May 25, 2023

Does this issue occur when all extensions are disabled?: Yes

  • VS Code Version: 1.78.2
  • OS Version: Windows_NT x64 10.0.22621

Steps to Reproduce:

  1. Create a Markdown file and put a JavaScript fence in it
  2. Select the JavaScript code in the fence
  3. Try invoking "Format Selection With..." from either the context menu or the Command Pallet; it isn't there

What I really want to do is just select that code, choose "Format Selection With..." and choose Prettier and let it format the JavaScript.

@cjbarth
Copy link
Author

cjbarth commented May 25, 2023

This feature is available when I'm working in a JavaScript file, and is commented on here: https://stackoverflow.com/a/55431401/271351

@mjbvz mjbvz assigned jrieken and unassigned mjbvz May 25, 2023
@jrieken jrieken added the *extension-candidate Issue identified as good extension implementation label May 26, 2023
@vscodenpa
Copy link

We try to keep VS Code lean and we think the functionality you're asking for is great for a VS Code extension. Maybe you can already find one that suits you in the VS Code Marketplace. Just in case, in a few simple steps you can get started writing your own extension. See also our issue reporting guidelines.

Happy Coding!

@vscodenpa vscodenpa closed this as not planned Won't fix, can't repro, duplicate, stale May 26, 2023
@cjbarth
Copy link
Author

cjbarth commented May 26, 2023

That would be a great idea, but without access to all the installed format providers, there is no way to actually do this. The only method that works is to create a new document, set its format, format document, and copy that text back to the originating document (or apply TextEdits to selection). That creates a very poor user experience.

I wrote an extension to do this for myself, and it really is ugly. I'll gladly share the code if you want to see for yourself @jrieken .

Ideally, vscode.executeFormatRangeProvider would include as an option which format provider to use. Of course, without being able to get a list of the format providers, that isn't very helpful. So, without some basic programmatic API help here, there is no way to elegantly make an extensions to do this.

Also, making use of Language Server Protocol isn't really an option either as it would require anticipating all the languages one would want to format.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*extension-candidate Issue identified as good extension implementation
Projects
None yet
Development

No branches or pull requests

4 participants