Skip to content

Commit

Permalink
[overlays] Fix overlay slowness when huge result is displayed
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-yakushev authored and bbatsov committed Feb 14, 2025
1 parent e905618 commit 7e9e70c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
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

0 comments on commit 7e9e70c

Please sign in to comment.