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

Enabling formatOnSave doesn't cause formatting provider to be invoked during save #13690

Closed
DanTup opened this issue Oct 13, 2016 · 6 comments
Closed
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug formatting Source formatter issues verified Verification succeeded
Milestone

Comments

@DanTup
Copy link
Contributor

DanTup commented Oct 13, 2016

  • VSCode Version: 1.6.0
  • OS Version: Windows 10

Steps to Reproduce:

  1. Install Dart-Code
  2. Add "editor.formatOnSave": true to user options
  3. Type some Dart into a dart file
  4. Press Alt+Shift+F and observe formatting work
  5. Insert some whitespace
  6. Press Ctrl+S

Formatting works fine when I invoke it directly, but provideDocumentFormattingEdits never gets called when I press Save.

It works fine for JSON files, so I presume there's something specific about my extension, but I can't find anything in the docs suggesting I need to do anything specific to enable this?

I'm registering my formatter on activation like this:

context.subscriptions.push(vs.languages.registerDocumentFormattingEditProvider(DART_MODE, new DartFormattingEditProvider(analyzer)));

I've got a breakpoint in the first line of provideDocumentFormattingEdits but it never seems to trigger (full code for this file is here).

@DanTup
Copy link
Contributor Author

DanTup commented Oct 13, 2016

Is it possible this only works with a range formatter (see here)? If so, is there any way this could be changed? I can't currently provide a range formatter and since the whole file is being saved it seems like an unnecessary restriction :(

@jrieken
Copy link
Member

jrieken commented Oct 14, 2016

Good point - it current picks range formatters first, but that an unnecessary limitation.

@jrieken jrieken added bug Issue identified by VS Code Team member as probable bug formatting Source formatter issues labels Oct 14, 2016
@jrieken jrieken added this to the October 2016 milestone Oct 14, 2016
@DanTup
Copy link
Contributor Author

DanTup commented Oct 14, 2016

@jrieken When you say "first", do you mean it should still fall back to the doc formatter? (It doesn't seem to, but if that's the expectation I can do some further debugging)

@jrieken
Copy link
Member

jrieken commented Oct 14, 2016

first as in only

@DanTup
Copy link
Contributor Author

DanTup commented Oct 19, 2016

@jrieken Thanks, works great! 👍

@ramya-rao-a
Copy link
Contributor

Verified using Go extension (from source with some changes tracked in microsoft/vscode-go#540) which also uses provideDocumentFormattingEdits

@ramya-rao-a ramya-rao-a added the verified Verification succeeded label Oct 28, 2016
@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug formatting Source formatter issues verified Verification succeeded
Projects
None yet
Development

No branches or pull requests

3 participants