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

fix(formatting/#3014): 'Invalid range specified' error #3240

merged 12 commits into from Mar 6, 2021


Copy link

@bryphe bryphe commented Mar 5, 2021

Issue: When formatting a JavaScript file, or other file without a formatter installed by default, and formatting (either via the 'Format Document' command, or key sequences like gg=G) - there'd be a confusing 'Invalid range specified' error.

Defect: There were actually several issues:

  1. When falling back to the default format provider, there was an off-by-one bug that caused that error to be displayed when the whole document was requested to be formatted.
  2. In the case of Document formatting not working #3014 , there actually is a default format provider - the type script language feature provides a formatter, but it is a range formatter (not a document formatter). However, in the case where there is a range formatter but no document formatter, we can fall back to using the range formatter.
  3. The case of multiple format providers wasn't handled in a robust way


  1. Fix the issues with the ranges in the default and language server range formatters
  2. Implement logic to fall back to the range formatter in the case where there is no document formatter available
  3. Implement proper resolution of format providers. When there are multiple, prompt the user to pick a default formatter. Use the "editor.defaultFormatter": "publisher.extension-id" configuration setting to disambiguate, for example:
"[javascript]": {
   "editor.defaultFormatter": "esbenp.prettier-vscode"

When the user selects a default, automatically update the configuration.

@bryphe bryphe merged commit 4431f88 into master Mar 6, 2021
@bryphe bryphe deleted the fix/formatting/3014/invalid-range branch March 6, 2021 02:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

1 participant