diagnostics: Prefer activating diagnostic under cursor#52957
Conversation
Also add some missing Diagnostics docs in all-settings.md while I was in there.
|
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! |
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.
There was a problem hiding this comment.
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.
|
Updated the PR's description as that will be used as the commit's body. Merging now 🚢 |
…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>
…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>
Update the behavior of both
editor: go to diagnosticandeditor: go to previous diagnosticin order to ensure that, if there's a diagnosticunder 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:
editor: go to diagnosticandeditor: go to previous diagnosticto prefer activating the diagnostic under the cursor before jumping to the next or previous diagnostic, respectively