Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[overlays] Fix overlay slowness when huge result is displayed #3774

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
### Bugs fixed

- [#3763](https://github.com/clojure-emacs/cider/issues/3763): Fix `cider-docview-render` completion popup error when symbol being completed does not have a docstring.
- [#3774](https://github.com/clojure-emacs/cider/issues/3774): Fix overlay hangup when evaluating huge values.

## 1.16.1 (2024-12-03)

Expand Down
19 changes: 13 additions & 6 deletions cider-overlays.el
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ overlay."
;; Specify `default' face, otherwise unformatted text will
;; inherit the face of the following text.
(display-string (format (propertize format 'face 'default) value))
;; Maximum value width at which we truncate it.
(truncation-threshold (* 3 (window-width)))
(o nil))
;; Remove any overlay at the position we're creating a new one, if it
;; exists.
Expand All @@ -245,17 +247,22 @@ overlay."
;; If the display spans multiple lines or is very long, display it at
;; the beginning of the next line.
(when (or (string-match "\n." display-string)
;; string-width can be very slow on large results, so check
;; with a cheaper predicate first. Conservatively limit to
;; truncation threshold.
(> (length display-string) truncation-threshold)
(> (string-width display-string)
(- (window-width) (current-column))))
(setq display-string (concat " \n" display-string)))
;; Put the cursor property only once we're done manipulating the
;; string, since we want it to be at the first char.
(put-text-property 0 1 'cursor 0 display-string)
(when (> (string-width display-string) (* 3 (window-width)))
(when (or (> (length display-string) truncation-threshold)
(> (string-width display-string) truncation-threshold))
(setq display-string
(concat (substring display-string 0 (* 3 (window-width)))
(concat (substring display-string 0 truncation-threshold)
(substitute-command-keys
"...\nResult truncated. Type `\\[cider-inspect-last-result]' to inspect it."))))
;; Put the cursor property only once we're done manipulating the
;; string, since we want it to be at the first char.
(put-text-property 0 1 'cursor 0 display-string)
;; Create the result overlay.
(setq o (apply #'cider--make-overlay
beg end type
Expand Down Expand Up @@ -285,7 +292,7 @@ overlay."
(when (and (<= (window-start win) (point) (window-end win))
;; Right edge is visible. This is a little conservative
;; if the overlay contains line breaks.
(or (< (+ (current-column) (string-width value))
(or (< (+ (current-column) (string-width display-string))
(window-width win))
(not truncate-lines)))
o)))))))
Expand Down