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

Support batch range formatting #158776

Closed
c-claeys opened this issue Aug 22, 2022 · 8 comments · Fixed by #189841
Closed

Support batch range formatting #158776

c-claeys opened this issue Aug 22, 2022 · 8 comments · Fixed by #189841
Assignees
Labels
api-finalization feature-request Request for new features or functionality formatting Source formatter issues insiders-released Patch has been released in VS Code Insiders on-release-notes Issue/pull request mentioned in release notes verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@c-claeys
Copy link
Contributor

With Editor: Format On Save Mode set to modifications, VSCode will sequentially send requests to its rangeFormatting provider(s). It'd be nice if the whole list of ranges could be sent at once instead of sequentially, allowing the formatter to handle this batch as it sees fit. This could be achieved by modifying registerDocumentRangeFormattingEditProvider to take an additional optional metadata parameter that the provider can use to express support for this multiRange mode.

@jrieken jrieken added this to the Backlog Candidates milestone Aug 22, 2022
@jrieken jrieken added feature-request Request for new features or functionality formatting Source formatter issues labels Aug 22, 2022
@VSCodeTriageBot
Copy link
Collaborator

This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

@c-claeys
Copy link
Contributor Author

Would the team be open to PR for this change? I'm happy to provide one.

@c-claeys c-claeys reopened this Sep 16, 2022
@laurentlb
Copy link
Contributor

To give additional context, we've had user reports like this:

Saving takes 5-15 seconds, and during the wait "Formatting via LSP" (or similar) is spinning in the status bar.
What is most surprising though is that (select whole file, and then "format range") gets it done 10x faster. So the task of formatting alone cannot explain the long delay.

When a file has lots of modified chunks, we see lots of round-trips to the server. Batching the requests can provide a very important performance improvement in some cases.

@VSCodeTriageBot
Copy link
Collaborator

This feature request has not yet received the 20 community upvotes it takes to make to our backlog. 10 days to go. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

@jrieken jrieken removed this from the November 2022 milestone Nov 15, 2022
@jrieken jrieken added this to the April 2023 milestone Mar 30, 2023
@jrieken
Copy link
Member

jrieken commented Apr 4, 2023

feedback from API sync, have explicit optional function

	export interface DocumentRangeFormattingEditProvider {
		provideDocumentRangeFormattingEdits(document: TextDocument, range: Range, options: FormattingOptions, token: CancellationToken): ProviderResult<TextEdit[]>;
		provideDocumentRangesFormattingEdits?(document: TextDocument, ranges: Range[], options: FormattingOptions, token: CancellationToken): ProviderResult<TextEdit[]>;
	}

@jrieken
Copy link
Member

jrieken commented Aug 7, 2023

fyi @dbaeumer this is done and LSP adoption is welcome

jrieken added a commit that referenced this issue Aug 7, 2023
@VSCodeTriageBot VSCodeTriageBot added unreleased Patch has not yet been released in VS Code Insiders insiders-released Patch has been released in VS Code Insiders and removed unreleased Patch has not yet been released in VS Code Insiders labels Aug 7, 2023
@dbaeumer
Copy link
Member

dbaeumer commented Aug 8, 2023

@jrieken jrieken added the verification-needed Verification of issue is requested label Aug 28, 2023
@jrieken
Copy link
Member

jrieken commented Aug 28, 2023

To verify:

  • make sure DocumentRangeFormattingEditProvider API has a new optional function provideDocumentRangesFormattingEdits and make sure it's properly documented
  • (extra) write a dummy extension that implements this and make sure it's called

@roblourens roblourens added the verified Verification succeeded label Aug 29, 2023
@jrieken jrieken added the on-release-notes Issue/pull request mentioned in release notes label Aug 30, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Sep 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api-finalization feature-request Request for new features or functionality formatting Source formatter issues insiders-released Patch has been released in VS Code Insiders on-release-notes Issue/pull request mentioned in release notes verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants