Skip to content

diagnostics: Prefer activating diagnostic under cursor#52957

Merged
dinocosta merged 8 commits into
zed-industries:mainfrom
nullstalgia:feat/go-to-diagostic-at-cursor
May 28, 2026
Merged

diagnostics: Prefer activating diagnostic under cursor#52957
dinocosta merged 8 commits into
zed-industries:mainfrom
nullstalgia:feat/go-to-diagostic-at-cursor

Conversation

@nullstalgia

@nullstalgia nullstalgia commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Update the behavior of both editor: go to diagnostic and editor: go to previous diagnostic in order to ensure that, if there's a diagnostic
under the user's cursor that isn't active, it is first activated, with a
subsequent call jumping to the next or previous diagnostic,
respectively.

These changes also update how diagnostic activation handles the
situation when the global diagnostic renderer is not registered, as we
used to not update the active diagnostic group in that situation.
However, we now rely on it to determine whether the user's cursor is
already in the active diagnostic, with some tests now failing, so we now
default to an empty set of blocks for the active diagnostic group when
no global renderer is registered.

Release Notes:

  • Update both editor: go to diagnostic and editor: go to previous diagnostic to prefer activating the diagnostic under the cursor before jumping to the next or previous diagnostic, respectively

Also add some missing Diagnostics docs in all-settings.md while I was in there.
@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Apr 2, 2026
@zed-codeowner-coordinator zed-codeowner-coordinator Bot requested review from a team, as-cii and dinocosta and removed request for a team April 2, 2026 03:27
@zed-community-bot zed-community-bot Bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label Apr 2, 2026
@nullstalgia

Copy link
Copy Markdown
Contributor Author

I'm not super familiar with the test setup for Zed, but I think I was able to make relevant test cases for the new toggle being on/off!

Gently pinging @dinocosta as the tests have to be run manually again and they're the assignee according to the codeowners bot, apologies if this is uncouth!

nullstalgia and others added 5 commits May 1, 2026 21:35
Remove the `go_to_diagnostic_searches_at_cursor` setting, as its default
behavior seems to be an acceptable behavior to me, so I'd rather have
that be the default and avoid introducing another setting just to
control this behavior.

As such, with this change, everytime `editor: go to diagnostic` or
`editor: go to previous diagnostic` are used, it'll first attempt to
expand the diagnostic at the current cursor position, in case there's
one, otherwise it'll either navigate to the next or previous diagnostic,
expanding that one instead, respectively.
* Introduce `editor::diagnostics::Editor.activate_diagnostic` which,
  given a diagnostic entry, will update the cursor position and expand
  the respective diagnostic.
* Introduce `editor::diagnostics::Editor::diagnostics_before_cursor` and
  `editor::diagnostics::Editor::diagnostics_after_cursor` to make it
  easier for callers to find that information, as it used to be a
  function/method implemented inside
  `editor::diagnostics::Editor.go_to_diagnostic_impl`.
* Introduce `editor::diagnostics::Editor.go_to_diagnostic_at_cursor`,
  moving that logic outside of
  `editor::diagnostics::Editor.go_to_diagnostic_impl`. With this change,
  the `direction` argument in
  `editor::diagnostics::Editor.go_to_diagnostic_impl` no longer needs to
  be a `Option<Direction>` and can simply be a `Direction`.
* Remove the `go_to_diagnostic_with_severity_start_after_cursor` test as
  it no longer makes sense, seeing as we removed the setting.
The previous changes to how the diagnostic under the cursor was expanded
only if there were not yet any active diagnostics had a small bug where,
if a diagnostic was already expanded but the user navigated to a
different one through regular keyboard or mouse movement, then using
`editor: go to diagnostic` would not activate the diagnostic under the
cursor, but jump to the one after.

The changes in this commit fixes that issue, changing the behavior a
little bit such that, regardless of whether we're going to the next or
previous diagnostic, we always try to first expand the diagnostic under
the cursor, in case there's one and it's not yet active, otherwise we
navigate in the provided direction.

Lastly, a minor change to
`editor::diagnostics::Editor.activate_diagnostics` was made to ensure
that, even when a global diagnostic renderer is not registered, we use
an empty set of blocks and still track the active group as without this
fix, the `go_to_prev_overlapping_diagnostic` test would fail, as we rely
on the active group id in `go_to_diagnostic_at_cursor` in order to
understand if the cursor is already at the active diagnostic.

@dinocosta dinocosta left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @nullstalgia !

Thank you so much for suggesting these changes. I believe the proposed behavior is sensible enough that it doesn't warrant a setting, so I went ahead and removed the setting, updating the default behavior for both editor: go to diagnostic and editor: go to previous diagnostic such that, if there's a non-active diagnostic under the cursor, we'll first activate that one, otherwise we'll navigate away to either the next or previous diagnostic, accordingly .

Lastly, I've brought this branch up to date with main and refactored the approach a bit, splitting the navigation from the activation so we could get rid of the Option<Direction>. I'm just wrapping up some new tests and will merge afterwards 🙂

P.S.: Sorry for the late reply, was out of office for the whole month.

@dinocosta dinocosta changed the title Added toggle for "Go to Diagnostic" actions to begin search at cursor diagnostics: Prefer activating diagnostic under cursor May 28, 2026
@dinocosta

Copy link
Copy Markdown
Member

Updated the PR's description as that will be used as the commit's body. Merging now 🚢

@dinocosta dinocosta added this pull request to the merge queue May 28, 2026
Merged via the queue into zed-industries:main with commit 3bb2f2a May 28, 2026
35 checks passed
TomPlanche pushed a commit to TomPlanche/zed that referenced this pull request Jun 2, 2026
…s#52957)

Update the behavior of both `editor: go to diagnostic` and `editor: go
to previous diagnostic` in order to ensure that, if there's a diagnostic
under the user's cursor that isn't active, it is first activated, with a
subsequent call jumping to the next or previous diagnostic,
respectively.

These changes also update how diagnostic activation handles the
situation when the global diagnostic renderer is not registered, as we
used to not update the active diagnostic group in that situation.
However, we now rely on it to determine whether the user's cursor is
already in the active diagnostic, with some tests now failing, so we now
default to an empty set of blocks for the active diagnostic group when
no global renderer is registered.

Release Notes:

- Update both `editor: go to diagnostic` and `editor: go to previous
diagnostic` to prefer activating the diagnostic under the cursor before
jumping to the next or previous diagnostic, respectively

---------

Co-authored-by: dino <dinojoaocosta@gmail.com>
zed-zippy Bot added a commit that referenced this pull request Jun 5, 2026
…ry-pick to stable) (#58603)

Cherry-pick of #52957 to stable

----
Update the behavior of both `editor: go to diagnostic` and `editor: go
to previous diagnostic` in order to ensure that, if there's a diagnostic
under the user's cursor that isn't active, it is first activated, with a
subsequent call jumping to the next or previous diagnostic,
respectively.

These changes also update how diagnostic activation handles the
situation when the global diagnostic renderer is not registered, as we
used to not update the active diagnostic group in that situation.
However, we now rely on it to determine whether the user's cursor is
already in the active diagnostic, with some tests now failing, so we now
default to an empty set of blocks for the active diagnostic group when
no global renderer is registered.

Release Notes:

- Update both `editor: go to diagnostic` and `editor: go to previous
diagnostic` to prefer activating the diagnostic under the cursor before
jumping to the next or previous diagnostic, respectively

---------

Co-authored-by: dino <dinojoaocosta@gmail.com>

Co-authored-by: nullstalgia <nullstalgia@gmail.com>
Co-authored-by: dino <dinojoaocosta@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants