30
30
31
31
; ;; Code:
32
32
33
+ (require 'lsp-ui-util )
34
+
33
35
(require 'lsp-protocol )
34
36
(require 'lsp-mode )
35
37
(require 'dash )
52
54
(declare-function xwidget-webkit-execute-script-rv " ext:xwidget" (xwidget script &optional default ))
53
55
(declare-function xwidget-resize " ext:xwidget" (xwidget new-width new-height))
54
56
55
- (declare-function lsp-ui--with-no-redisplay 'lsp-ui )
56
- (declare-function lsp-ui--safe-kill-timer 'lsp-ui )
57
-
58
57
(defgroup lsp-ui-doc nil
59
58
" Display informations of the current line."
60
59
:group 'tools
@@ -181,29 +180,29 @@ Only the `background' is used in this face."
181
180
:group 'lsp-ui-doc )
182
181
183
182
(defvar lsp-ui-doc-frame-parameters
184
- '((left . -1 )
185
- (no-focus-on-map . t )
186
- (min-width . 0 )
187
- (width . 0 )
188
- (min-height . 0 )
189
- (height . 0 )
190
- (internal-border-width . 1 )
191
- (vertical-scroll-bars . nil )
192
- (horizontal-scroll-bars . nil )
193
- (right-fringe . 0 )
194
- (menu-bar-lines . 0 )
195
- (tool-bar-lines . 0 )
196
- (line-spacing . 0 )
197
- (unsplittable . t )
198
- (undecorated . t )
199
- (top . -1 )
200
- (visibility . nil )
201
- (mouse-wheel-frame . nil )
202
- (no-other-frame . t )
183
+ '((left . -1 )
184
+ (no-focus-on-map . t )
185
+ (min-width . 0 )
186
+ (width . 0 )
187
+ (min-height . 0 )
188
+ (height . 0 )
189
+ (internal-border-width . 1 )
190
+ (vertical-scroll-bars . nil )
191
+ (horizontal-scroll-bars . nil )
192
+ (right-fringe . 0 )
193
+ (menu-bar-lines . 0 )
194
+ (tool-bar-lines . 0 )
195
+ (line-spacing . 0 )
196
+ (unsplittable . t )
197
+ (undecorated . t )
198
+ (top . -1 )
199
+ (visibility . nil )
200
+ (mouse-wheel-frame . nil )
201
+ (no-other-frame . t )
203
202
(inhibit-double-buffering . t )
204
- (drag-internal-border . t )
205
- (no-special-glyphs . t )
206
- (desktop-dont-save . t ))
203
+ (drag-internal-border . t )
204
+ (no-special-glyphs . t )
205
+ (desktop-dont-save . t ))
207
206
" Frame parameters used to create the frame." )
208
207
209
208
(defvar lsp-ui-doc-render-function nil
@@ -247,14 +246,19 @@ Because some variables are buffer local.")
247
246
(defmacro lsp-ui-doc--with-buffer (&rest body )
248
247
" Execute BODY in the lsp-ui-doc buffer."
249
248
(declare (indent 0 ) (debug t ))
250
- `(lsp-ui--with-no-redisplay
251
- (let ((parent-vars (list :buffer (current-buffer ) :window (get-buffer-window ))))
252
- (with-current-buffer (get-buffer-create (lsp-ui-doc--make-buffer-name))
253
- (setq lsp-ui-doc--parent-vars parent-vars)
254
- (prog1 (let (buffer-read-only ) ,@body )
255
- (setq buffer-read-only t )
256
- (let ((text-scale-mode-step 1.1 ))
257
- (text-scale-set lsp-ui-doc-text-scale-level)))))))
249
+ `(let ((parent-vars (list :buffer (current-buffer )
250
+ :window (get-buffer-window )))
251
+ (buffer-list-update-hook nil ))
252
+ (with-current-buffer (get-buffer-create (lsp-ui-doc--make-buffer-name))
253
+ (setq lsp-ui-doc--parent-vars parent-vars)
254
+ (prog1 (let ((buffer-read-only nil )
255
+ (inhibit-modification-hooks t )
256
+ (inhibit-point-motion-hooks t )
257
+ (inhibit-redisplay t ))
258
+ ,@body )
259
+ (setq buffer-read-only t )
260
+ (let ((text-scale-mode-step 1.1 ))
261
+ (text-scale-set lsp-ui-doc-text-scale-level))))))
258
262
259
263
(defmacro lsp-ui-doc--get-parent (var )
260
264
" Return VAR in `lsp-ui-doc--parent-vars' ."
@@ -308,7 +312,7 @@ Because some variables are buffer local.")
308
312
(or (lsp:marked-string-language marked-string)
309
313
(lsp:markup-content-kind marked-string)))
310
314
language))
311
- markdown-hr-display-char)
315
+ ( markdown-hr-display-char nil ) )
312
316
(cond
313
317
(lsp-ui-doc-use-webkit
314
318
(if (and language
@@ -398,7 +402,8 @@ We don't extract the string that `lps-line' is already displaying."
398
402
399
403
(defun lsp-ui-doc--webkit-get-xwidget ()
400
404
" Return Xwidget instance."
401
- (lsp-ui-doc--with-buffer (xwidget-at 1 )))
405
+ (lsp-ui-doc--with-buffer
406
+ (xwidget-at 1 )))
402
407
403
408
(defun lsp-ui-doc--webkit-execute-script (script &optional fn )
404
409
" Execute SCRIPT in embedded Xwidget and run optional callback FN."
@@ -414,10 +419,11 @@ We don't extract the string that `lps-line' is already displaying."
414
419
" Hide the frame."
415
420
(setq lsp-ui-doc--bounds nil
416
421
lsp-ui-doc--from-mouse nil )
417
- (when ( overlayp lsp-ui-doc--inline-ov) ( delete-overlay lsp-ui-doc--inline-ov) )
418
- (when ( overlayp lsp-ui-doc--highlight-ov) ( delete-overlay lsp-ui-doc--highlight-ov) )
422
+ (lsp-ui-util-safe- delete-overlay lsp-ui-doc--inline-ov)
423
+ (lsp-ui-util-safe- delete-overlay lsp-ui-doc--highlight-ov)
419
424
(when-let ((frame (lsp-ui-doc--get-frame)))
420
- (when (frame-visible-p frame) (make-frame-invisible frame))))
425
+ (when (frame-visible-p frame)
426
+ (make-frame-invisible frame))))
421
427
422
428
(defun lsp-ui-doc--buffer-width ()
423
429
" Calcul the max width of the buffer."
@@ -506,57 +512,59 @@ FRAME just below the symbol at point."
506
512
507
513
(defun lsp-ui-doc--move-frame (frame )
508
514
" Place our FRAME on screen."
509
- (lsp-ui--with-no-redisplay
510
- (-let* (((left top right _bottom) (window-edges nil t nil t ))
511
- (window (frame-root-window frame))
512
- (char-h (frame-char-height frame))
513
- (char-w (frame-char-width frame))
514
- ((width . height) (window-text-pixel-size window nil nil 10000 10000 t ))
515
- (width (+ width (* char-w 1 ))) ; ; margins
516
- (height (min (- (* lsp-ui-doc-max-height char-h) (/ char-h 2 )) height))
517
- (width (min width (* lsp-ui-doc-max-width char-w)))
518
- (frame-right (pcase lsp-ui-doc-alignment
519
- ('frame (frame-pixel-width ))
520
- ('window right)))
521
- ((left . top) (if (eq lsp-ui-doc-position 'at-point )
522
- (lsp-ui-doc--mv-at-point width height left top)
523
- (cons (max (- frame-right width char-w) 10 )
524
- (pcase lsp-ui-doc-position
525
- ('top (+ top char-w))
526
- ('bottom (- (lsp-ui-doc--line-height 'mode-line )
527
- height
528
- 10 ))))))
529
- (frame-resize-pixelwise t )
530
- move-frame-functions
531
- window-size-change-functions
532
- window-state-change-hook
533
- window-state-change-functions)
534
- ; ; Dirty way to fix unused variable in emacs 26
535
- (and window-state-change-functions
536
- window-state-change-hook)
537
- ; ; Make frame invisible before moving/resizing it to avoid flickering:
538
- ; ; We set the position and size in 1 call, modify-frame-parameters, but
539
- ; ; internally emacs makes 2 different calls, which can be visible
540
- ; ; to the user
541
- (and (frame-visible-p frame)
542
- (lsp-ui-doc--size-and-pos-changed frame left top width height)
543
- (make-frame-invisible frame))
544
- (modify-frame-parameters
545
- frame
546
- `((width . (text-pixels . , width ))
547
- (height . (text-pixels . , height ))
548
- (user-size . t )
549
- (left . (+ , left ))
550
- (top . (+ , top ))
551
- (user-position . t )
552
- (lsp-ui-doc--window-origin . ,(selected-window ))
553
- (lsp-ui-doc--buffer-origin . ,(current-buffer ))
554
- (lsp-ui-doc--no-focus . t )
555
- (right-fringe . 0 )
556
- (left-fringe . 0 )))
557
- ; ; Insert hr lines after width is computed
558
- (lsp-ui-doc--fix-hr-props)
559
- (unless (frame-visible-p frame) (make-frame-visible frame)))))
515
+ (-let* (((left top right _bottom) (window-edges nil t nil t ))
516
+ (window (frame-root-window frame))
517
+ (char-h (frame-char-height frame))
518
+ (char-w (frame-char-width frame))
519
+ ((width . height) (window-text-pixel-size window nil nil 10000 10000 t ))
520
+ (width (+ width (* char-w 1 ))) ; ; margins
521
+ (height (min (- (* lsp-ui-doc-max-height char-h) (/ char-h 2 )) height))
522
+ (width (min width (* lsp-ui-doc-max-width char-w)))
523
+ (frame-right (pcase lsp-ui-doc-alignment
524
+ ('frame (frame-pixel-width ))
525
+ ('window right)))
526
+ ((left . top) (if (eq lsp-ui-doc-position 'at-point )
527
+ (lsp-ui-doc--mv-at-point width height left top)
528
+ (cons (max (- frame-right width char-w) 10 )
529
+ (pcase lsp-ui-doc-position
530
+ ('top (+ top char-w))
531
+ ('bottom (- (lsp-ui-doc--line-height 'mode-line )
532
+ height
533
+ 10 ))))))
534
+ (frame-resize-pixelwise t )
535
+ (move-frame-functions nil )
536
+ (window-size-change-functions nil )
537
+ (window-state-change-hook nil )
538
+ (window-state-change-functions nil )
539
+ (window-configuration-change-hook nil )
540
+ (inhibit-redisplay t ))
541
+ ; ; Dirty way to fix unused variable in emacs 26
542
+ (and window-state-change-functions
543
+ window-state-change-hook)
544
+ ; ; Make frame invisible before moving/resizing it to avoid flickering:
545
+ ; ; We set the position and size in 1 call, modify-frame-parameters, but
546
+ ; ; internally emacs makes 2 different calls, which can be visible
547
+ ; ; to the user
548
+ (and (frame-visible-p frame)
549
+ (lsp-ui-doc--size-and-pos-changed frame left top width height)
550
+ (make-frame-invisible frame))
551
+ (modify-frame-parameters
552
+ frame
553
+ `((width . (text-pixels . , width ))
554
+ (height . (text-pixels . , height ))
555
+ (user-size . t )
556
+ (left . (+ , left ))
557
+ (top . (+ , top ))
558
+ (user-position . t )
559
+ (lsp-ui-doc--window-origin . ,(selected-window ))
560
+ (lsp-ui-doc--buffer-origin . ,(current-buffer ))
561
+ (lsp-ui-doc--no-focus . t )
562
+ (right-fringe . 0 )
563
+ (left-fringe . 0 )))
564
+ ; ; Insert hr lines after width is computed
565
+ (lsp-ui-doc--fix-hr-props)
566
+ (unless (frame-visible-p frame)
567
+ (make-frame-visible frame))))
560
568
561
569
(defun lsp-ui-doc--visit-file (filename )
562
570
" Visit FILENAME in the parent frame."
@@ -905,7 +913,7 @@ HEIGHT is the documentation number of lines."
905
913
(and (looking-at " [[:graph:]]" ) (cons (point ) (1+ (point ))))))
906
914
(unless (equal lsp-ui-doc--bounds bounds)
907
915
(lsp-ui-doc--hide-frame)
908
- (lsp-ui--safe-kill-timer lsp-ui-doc--timer)
916
+ (lsp-ui-util -safe-kill-timer lsp-ui-doc--timer)
909
917
(setq lsp-ui-doc--timer
910
918
(run-with-idle-timer
911
919
lsp-ui-doc-delay nil
@@ -1185,7 +1193,8 @@ It is supposed to be called from `lsp-ui--toggle'"
1185
1193
(visible (lsp-ui-doc--frame-visible-p)))
1186
1194
(set-frame-parameter frame 'lsp-ui-doc--no-focus nil )
1187
1195
(set-frame-parameter frame 'cursor-type t )
1188
- (lsp-ui-doc--with-buffer (setq cursor-type 'box ))
1196
+ (lsp-ui-doc--with-buffer
1197
+ (setq cursor-type 'box ))
1189
1198
(select-frame-set-input-focus frame)))
1190
1199
1191
1200
(defun lsp-ui-doc-unfocus-frame ()
@@ -1195,8 +1204,10 @@ It is supposed to be called from `lsp-ui--toggle'"
1195
1204
(when-let* ((frame (lsp-ui-doc--get-frame)))
1196
1205
(set-frame-parameter frame 'lsp-ui-doc--no-focus t )
1197
1206
(set-frame-parameter frame 'cursor-type nil )
1198
- (lsp-ui-doc--with-buffer (setq cursor-type nil ))
1199
- (when lsp-ui-doc--from-mouse (make-frame-invisible frame))))
1207
+ (lsp-ui-doc--with-buffer
1208
+ (setq cursor-type nil ))
1209
+ (when lsp-ui-doc--from-mouse
1210
+ (make-frame-invisible frame))))
1200
1211
1201
1212
(provide 'lsp-ui-doc )
1202
1213
; ;; lsp-ui-doc.el ends here
0 commit comments