zed/docs/src
G36maid b9f3396b68
Add support for format_on_save only changed lines (#49964)
## Summary

Introduces `format_on_save` variants that format only modified lines,
limiting formatting to lines changed since the last commit. This
prevents massive diffs when editing legacy codebases. Aligns with VS
Code's `editor.formatOnSaveMode` naming:

- `"modifications"` — formats only git-diffed lines. Requires source
control; skips formatting if no diff is available.
- `"modifications_if_available"` — formats only git-diffed lines,
falling back to full-file formatting for untracked files, when source
control is unavailable, or when the LSP does not support range
formatting.

Also supports importing equivalent VS Code settings
(`formatOnSaveMode`).

This PR uses the range-based whitespace/newline infrastructure from the
dependency PR above.

## Changes


<details>
<summary><b>New settings, modified ranges computation, VS Code
import</b></summary>

### New settings (`language.rs`, `default.json`, `all-settings.md`)

Two new `FormatOnSave` variants: `Modifications` and
`ModificationsIfAvailable`.

### Modified ranges computation (`items.rs`)

- `compute_format_decision()` — reads `format_on_save` setting across
all buffers, determines whether to use ranged formatting (`Ranges`),
full formatting (`Full`), or skip (`Skip`).
- `compute_modified_ranges()` — extracts modified line ranges from git
diff hunks via `BufferDiffSnapshot`.
- `is_empty_range()` — helper to detect deletion-only hunks that produce
no formatable content.

The `save()` method calls `compute_format_decision()` and dispatches
accordingly.

### Modifications mode in `lsp_store.rs`

- Adds `FormatOnSave::Modifications |
FormatOnSave::ModificationsIfAvailable` to the formatter selection match
arm.
- `ModificationsIfAvailable` falls back to full-file formatting when
ranged formatting produces no results.

### VS Code settings import (`vscode_import.rs`, `settings_store.rs`)

Imports `editor.formatOnSaveMode` mapping:
- `"modifications"` → `FormatOnSave::Modifications`
- `"modificationsIfAvailable"` →
`FormatOnSave::ModificationsIfAvailable`
- `"file"` → `FormatOnSave::On`

</details>

## Tests

- `test_modifications_format_on_save` — basic modifications mode
formatting with dirty buffer
- `test_modifications_format_no_changes` — clean buffer triggers no
formatting
- `test_modifications_format_lsp_no_range_support` — LSP without range
formatting skips entirely for `Modifications`
- `test_modifications_format_lsp_returns_empty_edits` — empty edits
handled gracefully
- `test_modifications_format_multiple_hunks` — two non-adjacent edits
produce two separate range formatting requests

---

Self-Review Checklist:

- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable


Closes #16509
Depends on #53942

Release Notes:

- Added `modifications` and `modifications_if_available` options to
`format_on_save`, which format only git-changed lines instead of the
entire file
- When using modifications mode, `remove_trailing_whitespace_on_save`
and `ensure_final_newline_on_save` are also scoped to changed lines,
preventing unwanted diff jitter in legacy codebases
- Added support for importing VS Code's `editor.formatOnSaveMode`
setting

---------

Co-authored-by: Kirill Bulatov <kirill@zed.dev>
2026-07-08 16:53:11 +00:00
..
account Restructure AI docs (#57614) 2026-06-04 15:55:21 +00:00
ai Fix typos and grammatical mistakes in docs (#59495) 2026-07-08 12:32:00 +00:00
business Document provider safety retention for designated Zed-hosted models (#58967) 2026-06-09 21:54:48 +00:00
collaboration docs: Update actions format (#54869) 2026-05-07 06:55:11 +00:00
development Fix typos and grammatical mistakes in docs (#59495) 2026-07-08 12:32:00 +00:00
extensions Fix typos and grammatical mistakes in docs (#59495) 2026-07-08 12:32:00 +00:00
languages Fix typos and grammatical mistakes in docs (#59495) 2026-07-08 12:32:00 +00:00
migrate Restructure AI docs (#57614) 2026-06-04 15:55:21 +00:00
reference Add support for format_on_save only changed lines (#49964) 2026-07-08 16:53:11 +00:00
all-actions.md docs: Apply documentation standards across all docs (#49177) 2026-02-17 20:58:17 -06:00
appearance.md docs: Update actions format (#54869) 2026-05-07 06:55:11 +00:00
authentication.md Fix typos and grammatical mistakes in docs (#59495) 2026-07-08 12:32:00 +00:00
command-palette.md Fix typos and grammatical mistakes in docs (#59495) 2026-07-08 12:32:00 +00:00
completions.md Remove Supermaven-related code from Zed (#50537) 2026-03-02 22:18:49 +00:00
configuring-languages.md Fix typos and grammatical mistakes in docs (#59495) 2026-07-08 12:32:00 +00:00
configuring-zed.md Restructure AI docs (#57614) 2026-06-04 15:55:21 +00:00
debugger.md Fix typos and grammatical mistakes in docs (#59495) 2026-07-08 12:32:00 +00:00
dev-containers.md dev_container: Support the classic Docker builder via a setting (#59288) 2026-06-15 07:04:03 +00:00
development.md Improve documentation for ETW profiling (#50426) 2026-02-28 23:03:49 -05:00
diagnostics.md Fix typos and grammatical mistakes in docs (#59495) 2026-07-08 12:32:00 +00:00
editing-code.md docs: SEO content improvements for AI section (#49128) 2026-02-13 13:05:57 -08:00
environment.md Fix typos and grammatical mistakes in docs (#59495) 2026-07-08 12:32:00 +00:00
extensions.md docs: Update agent server extension documentation (#58306) 2026-06-02 08:50:46 +00:00
finding-navigating.md docs: Add new text finder (#60189) 2026-07-03 18:46:05 +00:00
getting-started.md Fixes for AI docs (#58969) 2026-06-11 15:15:55 +00:00
git.md Fix typos and grammatical mistakes in docs (#59495) 2026-07-08 12:32:00 +00:00
globs.md Fix grammatical errors throughout the documentation (#58183) 2026-05-31 22:05:41 +00:00
helix.md docs: Apply documentation standards across all docs (#49177) 2026-02-17 20:58:17 -06:00
icon-themes.md docs: Update actions format (#54869) 2026-05-07 06:55:11 +00:00
installation.md Fix grammatical errors throughout the documentation (#58183) 2026-05-31 22:05:41 +00:00
key-bindings.md Fix grammatical errors throughout the documentation (#58183) 2026-05-31 22:05:41 +00:00
languages.md Fix grammatical errors throughout the documentation (#58183) 2026-05-31 22:05:41 +00:00
linux.md Fix typos and grammatical mistakes in docs (#59495) 2026-07-08 12:32:00 +00:00
macos.md install_cli: Show notification instead of failing CLI install (#59575) 2026-06-22 18:20:57 +00:00
modelines.md Add vim/emacs modeline support (#49267) 2026-03-25 03:15:51 +00:00
multibuffers.md Fix grammatical errors throughout the documentation (#58183) 2026-05-31 22:05:41 +00:00
outline-panel.md docs: Update actions format (#54869) 2026-05-07 06:55:11 +00:00
performance.md Fix typos and grammatical mistakes in docs (#59495) 2026-07-08 12:32:00 +00:00
project-panel.md project_panel: Open files in a permanent tab on middle click (#60563) 2026-07-08 13:06:10 +00:00
quick-start.md docs: Reorganize introduction (#41387) 2025-10-28 17:39:40 -03:00
remote-development.md Fix typos and grammatical mistakes in docs (#59495) 2026-07-08 12:32:00 +00:00
repl.md Fix typos and grammatical mistakes in docs (#59495) 2026-07-08 12:32:00 +00:00
roles.md Document Billing Manager role (#58447) 2026-06-03 18:17:18 +00:00
running-testing.md docs: Apply documentation standards across all docs (#49177) 2026-02-17 20:58:17 -06:00
semantic-tokens.md docs: Update actions format (#54869) 2026-05-07 06:55:11 +00:00
snippets.md Fix grammatical errors throughout the documentation (#58183) 2026-05-31 22:05:41 +00:00
soc2.md docs: Restructure nav and add Zed Business section (#51915) 2026-05-06 16:07:12 +00:00
SUMMARY.md Add agent sandboxing docs (#59774) 2026-06-23 23:54:28 +00:00
tab-switcher.md docs: Apply documentation standards across all docs (#49177) 2026-02-17 20:58:17 -06:00
tasks.md git_ui: Pass the clicked ref to git graph custom commands (#58781) 2026-06-09 06:30:07 +00:00
telemetry.md Restructure AI docs (#57614) 2026-06-04 15:55:21 +00:00
terminal.md terminal: Open links with Cmd/Ctrl-click when mouse mode is enabled (#60067) 2026-07-08 12:41:48 +00:00
themes.md docs: Update actions format (#54869) 2026-05-07 06:55:11 +00:00
toolchains.md docs: Apply documentation standards across all docs (#49177) 2026-02-17 20:58:17 -06:00
troubleshooting.md feedback: Add action for listing installed extensions (#48664) 2026-04-16 07:45:38 +00:00
uninstall.md docs: Update guide to remove user data on macOS when uninstalling Zed (#52631) 2026-03-31 05:35:04 +00:00
update.md docs: Update actions format (#54869) 2026-05-07 06:55:11 +00:00
vim.md Fix typos and grammatical mistakes in docs (#59495) 2026-07-08 12:32:00 +00:00
visual-customization.md git: Allow showing inline blame in the status bar (#59696) 2026-06-29 05:50:31 +00:00
windows-and-projects.md Fixes for AI docs (#58969) 2026-06-11 15:15:55 +00:00
windows.md docs: Apply documentation standards across all docs (#49177) 2026-02-17 20:58:17 -06:00
worktree-trust.md Fix typos and grammatical mistakes in docs (#59495) 2026-07-08 12:32:00 +00:00