Skip to content

[inspect] Rework view-mode toggling #343

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

Merged
merged 1 commit into from
May 28, 2025
Merged

Conversation

alexander-yakushev
Copy link
Member

@alexander-yakushev alexander-yakushev commented May 27, 2025

Because there are more view modes now, and they all work conditionally, and also to facilitate discovery, I've reworked how they are displayed and changed. Orchard now has its own "toggle view mode" functionality (previously it was in cider-nrepl).

All view modes that are available for the currently inspected objects are displayed, and the enabled one is marked with a special symbol.

image
  • You've added tests to cover your change(s)
  • You've updated the changelog (if adding/changing user-visible functionality)

@alexander-yakushev alexander-yakushev force-pushed the view-mode-toggle branch 5 times, most recently from 88fe3f7 to 86be9ee Compare May 27, 2025 12:28
(pre-ex (view-mode-supported? inspector mode))
(inspect-render (assoc inspector :view-mode mode)))

(defn toggle-view-mode
Copy link
Member

Choose a reason for hiding this comment

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

Toggle usually implies that something is binary. I think here it's more like "cycle".

Copy link
Member Author

@alexander-yakushev alexander-yakushev May 28, 2025

Choose a reason for hiding this comment

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

I agree but that ship kinda sailed since we have inspect-toggle-view-mode nrepl op, and it makes sense to keep things consistent. Wrt renaming it everywhere, I don't think it warrants a full rename right now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's put it off until the big op namespacing refactor.

Copy link
Member

Choose a reason for hiding this comment

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

Fine by me.

@bbatsov
Copy link
Member

bbatsov commented May 28, 2025

The proposed changes look good to me.

@alexander-yakushev alexander-yakushev merged commit 8675eb9 into master May 28, 2025
18 checks passed
@alexander-yakushev alexander-yakushev deleted the view-mode-toggle branch May 28, 2025 06:41
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the inspector’s view-mode system to support cycling through available modes and better discovery.

  • Introduces a multimethod view-mode-supported? and replaces the static supported-view-modes set
  • Adds set-view-mode, toggle-view-mode, and updates render-view-mode to show mode toggles (including pretty-print)
  • Updates tests to match the new display format and adds coverage for toggle-view-mode

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/orchard/inspect.clj Replaced static mode set with multimethods, added toggle logic, updated rendering of “View mode” section
test/orchard/inspect_test.clj Updated many expected outputs to remove extra newlines, added tests for toggle-view-mode
CHANGELOG.md Added entry for rework of view-mode toggling
Comments suppressed due to low confidence (2)

src/orchard/inspect.clj:291

  • [nitpick] Consider renaming view-mode-supported? to supports-view-mode? to match predicate naming conventions and make it immediately clear that it returns a boolean.
(defmethod view-mode-supported? :normal [_ _] true)

src/orchard/inspect.clj:1043

  • [nitpick] Extract the add-circle helper and the joined formatting of supported modes into a separate function (e.g. format-view-mode-line) to declutter render-view-mode and improve readability.
(defn render-view-mode [inspector]


(def ^:private view-mode-order [:normal :hex :table :object])

(defmulti view-mode-supported? (fn [_inspector view-mode] view-mode))
Copy link
Preview

Copilot AI May 28, 2025

Choose a reason for hiding this comment

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

Add a docstring to view-mode-supported? explaining its parameters (inspector, mode) and return value (boolean) to clarify dispatch behavior.

Suggested change
(defmulti view-mode-supported? (fn [_inspector view-mode] view-mode))
(defmulti view-mode-supported?
"Determines whether the given `mode` is supported for the provided `inspector`.
Parameters:
- `inspector`: The current inspector object containing the value and metadata.
- `mode`: The view mode to check for support.
Returns:
- A boolean indicating whether the specified view mode is supported."
(fn [_inspector view-mode] view-mode))

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants