zed/crates/collab/tests/integration
Buyun Xu 3624a5bfda
project: Anchor diagnostic related information that points into the buffer (#62805)
Closes #62796. Follow-up to #62110.

# Objective

The range of a diagnostic entry is anchored when it is ingested, so it
follows edits. The ranges in the related information kept on the
diagnostic were the ones the server published. A code action request
carried both and reported the same note at two different lines: the
entry Zed flattened that note into had followed the edit, the related
information had not.

The distance does not correct itself either. When diagnostics are merged
rather than replaced, the existing entries are re-collected from their
anchors while the payload is cloned as it is, so the two positions drift
further apart with every edit that passes.

`mlir-lsp-server` shows what this costs. `MLIRTextFile::getCodeActions`
takes the line number out of `relatedInformation`, and
`getCodeActionForDiagnostic` resolves it against its own current
document, reading that line to copy its indentation before inserting the
`expected-note` check.

## Solution

The related information moves from `Diagnostic` onto
`DiagnosticEntry<T>`, next to the range it belongs with. The locations
of the diagnostic's own file are then in the same coordinate space as
that range: anchors inside the buffer, points in the worktree's store.
`Diagnostic` carries no coordinates again, so nothing that is only
meaningful inside one buffer travels with a payload that outlives it.

Every transition goes through `DiagnosticEntry::map_coordinates`: the
unsaved-edit adjustment and the clipping when diagnostics are ingested,
the anchoring in `DiagnosticSet::new`, and the conversion back to points
in `merge_diagnostic_entries`. Only the diagnostic's own range is
widened when it is empty, since that is for how it is rendered, while
the related locations are reported back as the server framed them.

Locations in another file have nothing here to anchor to and are kept as
published, which is also what `mlir-lsp-server` expects, since it skips
them.

`DiagnosticEntryRef` is left alone. It is what the rendering path
iterates, down to the scrollbar markers that walk every diagnostic of
the buffer on each frame, so nothing there converts or allocates. The
entries are read through `diagnostic_entries_in_range` where the request
is built, and `diagnostics_in_range` is now implemented on top of it.

The field is an `Option`, as an empty `Arc<[_]>` still allocates and
most diagnostics carry no related information.

`data` has the same staleness and cannot be anchored, as it is opaque.

## Commits

The third commit is mechanical: it introduces `DiagnosticEntry::new` and
rewrites the literals at its call sites, so that the last commit holds
only the change of behaviour.

## Testing

Three tests, all failing before this change. The first two are added as
separate commits, so that they can be run against `main`:

- `test_code_actions_related_information_follows_edits` edits above the
note and requests code actions, where the two positions for it used to
disagree.
- `test_code_actions_related_information_drifts_across_merges` edits and
pulls diagnostics twice, where the distance used to be every line
inserted since the diagnostic was published rather than the last edit
alone.
- `test_code_actions_related_information_of_disk_based_diagnostics`
publishes a diagnostic computed against the file on disk while the
buffer holds an unsaved edit, covering the adjustment the two positions
share.

- `cargo test -p project`
- `cargo test -p language -p diagnostics -p editor`
- `cargo fmt --all -- --check`
- `./script/clippy -p project -p language`

## 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 adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

---

Release Notes:

- Fixed language servers receiving outdated positions for the related
information of a diagnostic when code actions are requested.
2026-08-18 15:06:02 +00:00
..
db_tests Unship shared threads (#59981) 2026-06-26 20:50:37 +00:00
auto_watch_tests.rs Disable auto watch when leaving a call (#57196) 2026-05-19 21:31:34 +00:00
channel_buffer_tests.rs client: Rename UserId to LegacyUserId (#56185) 2026-05-08 15:53:40 +00:00
channel_guest_tests.rs collab: Introduce UserService (#55449) 2026-05-06 18:15:36 +00:00
channel_tests.rs livekit_api: Fix LiveKit token revocation timestamps (#60157) 2026-07-03 09:50:42 +00:00
collab_panel_tests.rs Add the ability to reorder favorited collab channels (#52649) 2026-03-30 13:07:13 +00:00
collab_tests.rs client: Add username to User and start using it (#60107) 2026-06-29 20:21:46 +00:00
db_tests.rs collab: Remove writes to github_user_id and github_login (#58474) 2026-06-04 15:43:03 +00:00
editor_tests.rs git: Decode non-UTF-8 blobs for project diffs (#60821) 2026-08-17 01:47:11 +00:00
following_tests.rs Add support for the "..." entry in file_scan_exclusions (#62769) 2026-08-18 09:57:38 +00:00
git_tests.rs Support loading Git commit templates when remote (#55490) 2026-07-22 12:01:29 +00:00
integration_tests.rs project: Anchor diagnostic related information that points into the buffer (#62805) 2026-08-18 15:06:02 +00:00
notification_tests.rs
random_channel_buffer_tests.rs
random_project_collaboration_tests.rs Bump rustc to 1.97 (#62395) 2026-08-09 22:29:52 +00:00
randomized_test_helpers.rs collab: Remove writes to github_user_id and github_login (#58474) 2026-06-04 15:43:03 +00:00
remote_editing_collaboration_tests.rs language: Refactor available_languages into its own struct (#61388) 2026-07-23 11:22:43 +00:00
test_server.rs livekit_api: Fix LiveKit token revocation timestamps (#60157) 2026-07-03 09:50:42 +00:00