|
23 | 23 |
|
24 | 24 | (require 'lsp-mode)
|
25 | 25 |
|
26 |
| -(defcustom lsp-lens-debounce-interval 0.2 |
| 26 | +(defcustom lsp-lens-debounce-interval 0.001 |
27 | 27 | "Debounce interval for loading lenses."
|
28 | 28 | :group 'lsp-mode
|
29 | 29 | :type 'number)
|
@@ -85,18 +85,12 @@ Results are meaningful only if FROM and TO are on the same line."
|
85 | 85 |
|
86 | 86 | (defun lsp-lens--overlay-ensure-at (pos)
|
87 | 87 | "Find or create a lens for the line at POS."
|
88 |
| - (or (when-let ((ov (-first (lambda (ov) (lsp-lens--overlay-matches-pos ov pos)) lsp-lens--overlays))) |
89 |
| - (save-excursion |
90 |
| - (goto-char pos) |
91 |
| - (move-overlay ov (point-at-bol) (1+ (point-at-eol)))) |
92 |
| - ov) |
93 |
| - (let* ((ov (save-excursion |
94 |
| - (goto-char pos) |
95 |
| - (make-overlay (point-at-bol) (1+ (point-at-eol)) nil t t)))) |
96 |
| - (overlay-put ov 'lsp-lens t) |
97 |
| - (overlay-put ov 'evaporate t) |
98 |
| - (overlay-put ov 'lsp-lens-position pos) |
99 |
| - ov))) |
| 88 | + (-doto (save-excursion |
| 89 | + (goto-char pos) |
| 90 | + (make-overlay (point-at-bol) (1+ (point-at-eol)) nil t t)) |
| 91 | + (overlay-put 'lsp-lens t) |
| 92 | + (overlay-put 'evaporate t) |
| 93 | + (overlay-put 'lsp-lens-position pos))) |
100 | 94 |
|
101 | 95 | (defun lsp-lens--show (str pos metadata)
|
102 | 96 | "Show STR in an inline window at POS including METADATA."
|
@@ -168,50 +162,42 @@ See `lsp-lens--schedule-refresh' for details."
|
168 | 162 | "Show LENSES."
|
169 | 163 | ;; rerender only if there are lenses which are not processed or if their count
|
170 | 164 | ;; has changed(e. g. delete lens should trigger redisplay).
|
171 |
| - (setq lsp-lens--modified? nil) |
172 |
| - (when (or (-any? (-lambda ((&CodeLens :_processed processed)) |
173 |
| - (not processed)) |
174 |
| - lenses) |
175 |
| - (eq (length lenses) lsp-lens--last-count) |
176 |
| - (not lenses)) |
177 |
| - (setq lsp-lens--last-count (length lenses)) |
178 |
| - (let ((overlays |
179 |
| - (->> lenses |
180 |
| - (-filter #'lsp:code-lens-command?) |
181 |
| - (--map (prog1 it (lsp-put it :_processed t))) |
182 |
| - (-group-by (-compose #'lsp:position-line #'lsp:range-start #'lsp:code-lens-range)) |
183 |
| - (-map |
184 |
| - (-lambda ((_ . lenses)) |
185 |
| - (let* ((sorted (-sort (-on #'< (-compose #'lsp:position-character |
186 |
| - #'lsp:range-start |
187 |
| - #'lsp:code-lens-range)) |
188 |
| - lenses)) |
189 |
| - (data (-map |
190 |
| - (-lambda ((lens &as &CodeLens |
191 |
| - :command? (command &as |
192 |
| - &Command :title :_face face))) |
193 |
| - (propertize |
194 |
| - title |
195 |
| - 'face (or face 'lsp-lens-face) |
196 |
| - 'action (lsp-lens--create-interactive-command command) |
197 |
| - 'point 'hand |
198 |
| - 'mouse-face 'lsp-lens-mouse-face |
199 |
| - 'local-map (lsp-lens--keymap command))) |
200 |
| - sorted))) |
201 |
| - (lsp-lens--show |
202 |
| - (s-join (propertize "|" 'face 'lsp-lens-face) data) |
203 |
| - (-> sorted cl-first lsp:code-lens-range lsp:range-start lsp--position-to-point) |
204 |
| - data))))))) |
205 |
| - (mapc (lambda (overlay) |
206 |
| - (unless (and (-contains? overlays overlay) |
207 |
| - (overlay-start overlay) |
208 |
| - ;; buffer narrowed, overlay outside of it |
209 |
| - (<= (point-min) |
210 |
| - (overlay-get overlay 'lsp-lens-position ) |
211 |
| - (point-max))) |
212 |
| - (delete-overlay overlay))) |
213 |
| - lsp-lens--overlays) |
214 |
| - (setq lsp-lens--overlays overlays)))) |
| 165 | + (let ((scroll-preserve-screen-position t)) |
| 166 | + (setq lsp-lens--modified? nil) |
| 167 | + (when (or (-any? (-lambda ((&CodeLens :_processed processed)) |
| 168 | + (not processed)) |
| 169 | + lenses) |
| 170 | + (eq (length lenses) lsp-lens--last-count) |
| 171 | + (not lenses)) |
| 172 | + (setq lsp-lens--last-count (length lenses)) |
| 173 | + (mapc #'delete-overlay lsp-lens--overlays) |
| 174 | + (setq lsp-lens--overlays |
| 175 | + (->> lenses |
| 176 | + (-filter #'lsp:code-lens-command?) |
| 177 | + (--map (prog1 it (lsp-put it :_processed t))) |
| 178 | + (-group-by (-compose #'lsp:position-line #'lsp:range-start #'lsp:code-lens-range)) |
| 179 | + (-map |
| 180 | + (-lambda ((_ . lenses)) |
| 181 | + (let* ((sorted (-sort (-on #'< (-compose #'lsp:position-character |
| 182 | + #'lsp:range-start |
| 183 | + #'lsp:code-lens-range)) |
| 184 | + lenses)) |
| 185 | + (data (-map |
| 186 | + (-lambda ((lens &as &CodeLens |
| 187 | + :command? (command &as |
| 188 | + &Command :title :_face face))) |
| 189 | + (propertize |
| 190 | + title |
| 191 | + 'face (or face 'lsp-lens-face) |
| 192 | + 'action (lsp-lens--create-interactive-command command) |
| 193 | + 'point 'hand |
| 194 | + 'mouse-face 'lsp-lens-mouse-face |
| 195 | + 'local-map (lsp-lens--keymap command))) |
| 196 | + sorted))) |
| 197 | + (lsp-lens--show |
| 198 | + (s-join (propertize "|" 'face 'lsp-lens-face) data) |
| 199 | + (-> sorted cl-first lsp:code-lens-range lsp:range-start lsp--position-to-point) |
| 200 | + data))))))))) |
215 | 201 |
|
216 | 202 | (defun lsp-lens-refresh (buffer-modified? &optional buffer)
|
217 | 203 | "Refresh lenses using lenses backend.
|
|
0 commit comments