30
30
31
31
; ;; Code:
32
32
33
- (require 'lsp-ui-util )
34
-
35
33
(require 'lsp-protocol )
36
34
(require 'lsp-mode )
37
35
(require 'dash )
54
52
(declare-function xwidget-webkit-execute-script-rv " ext:xwidget" (xwidget script &optional default ))
55
53
(declare-function xwidget-resize " ext:xwidget" (xwidget new-width new-height))
56
54
55
+ (declare-function lsp-ui--with-no-redisplay 'lsp-ui )
56
+ (declare-function lsp-ui--safe-kill-timer 'lsp-ui )
57
+
57
58
(defgroup lsp-ui-doc nil
58
59
" Display informations of the current line."
59
60
:group 'tools
@@ -180,29 +181,29 @@ Only the `background' is used in this face."
180
181
:group 'lsp-ui-doc )
181
182
182
183
(defvar lsp-ui-doc-frame-parameters
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 )
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 )
202
203
(inhibit-double-buffering . t )
203
- (drag-internal-border . t )
204
- (no-special-glyphs . t )
205
- (desktop-dont-save . t ))
204
+ (drag-internal-border . t )
205
+ (no-special-glyphs . t )
206
+ (desktop-dont-save . t ))
206
207
" Frame parameters used to create the frame." )
207
208
208
209
(defvar lsp-ui-doc-render-function nil
@@ -246,19 +247,14 @@ Because some variables are buffer local.")
246
247
(defmacro lsp-ui-doc--with-buffer (&rest body )
247
248
" Execute BODY in the lsp-ui-doc buffer."
248
249
(declare (indent 0 ) (debug t ))
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))))))
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)))))))
262
258
263
259
(defmacro lsp-ui-doc--get-parent (var )
264
260
" Return VAR in `lsp-ui-doc--parent-vars' ."
@@ -312,7 +308,7 @@ Because some variables are buffer local.")
312
308
(or (lsp:marked-string-language marked-string)
313
309
(lsp:markup-content-kind marked-string)))
314
310
language))
315
- ( markdown-hr-display-char nil ) )
311
+ markdown-hr-display-char)
316
312
(cond
317
313
(lsp-ui-doc-use-webkit
318
314
(if (and language
@@ -402,8 +398,7 @@ We don't extract the string that `lps-line' is already displaying."
402
398
403
399
(defun lsp-ui-doc--webkit-get-xwidget ()
404
400
" Return Xwidget instance."
405
- (lsp-ui-doc--with-buffer
406
- (xwidget-at 1 )))
401
+ (lsp-ui-doc--with-buffer (xwidget-at 1 )))
407
402
408
403
(defun lsp-ui-doc--webkit-execute-script (script &optional fn )
409
404
" Execute SCRIPT in embedded Xwidget and run optional callback FN."
@@ -419,11 +414,10 @@ We don't extract the string that `lps-line' is already displaying."
419
414
" Hide the frame."
420
415
(setq lsp-ui-doc--bounds nil
421
416
lsp-ui-doc--from-mouse nil )
422
- (lsp-ui-util-safe- delete-overlay lsp-ui-doc--inline-ov)
423
- (lsp-ui-util-safe- delete-overlay lsp-ui-doc--highlight-ov)
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) )
424
419
(when-let ((frame (lsp-ui-doc--get-frame)))
425
- (when (frame-visible-p frame)
426
- (make-frame-invisible frame))))
420
+ (when (frame-visible-p frame) (make-frame-invisible frame))))
427
421
428
422
(defun lsp-ui-doc--buffer-width ()
429
423
" Calcul the max width of the buffer."
@@ -512,59 +506,57 @@ FRAME just below the symbol at point."
512
506
513
507
(defun lsp-ui-doc--move-frame (frame )
514
508
" Place our FRAME on screen."
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))))
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)))))
568
560
569
561
(defun lsp-ui-doc--visit-file (filename )
570
562
" Visit FILENAME in the parent frame."
@@ -913,7 +905,7 @@ HEIGHT is the documentation number of lines."
913
905
(and (looking-at " [[:graph:]]" ) (cons (point ) (1+ (point ))))))
914
906
(unless (equal lsp-ui-doc--bounds bounds)
915
907
(lsp-ui-doc--hide-frame)
916
- (lsp-ui-util -safe-kill-timer lsp-ui-doc--timer)
908
+ (lsp-ui--safe-kill-timer lsp-ui-doc--timer)
917
909
(setq lsp-ui-doc--timer
918
910
(run-with-idle-timer
919
911
lsp-ui-doc-delay nil
@@ -1193,8 +1185,7 @@ It is supposed to be called from `lsp-ui--toggle'"
1193
1185
(visible (lsp-ui-doc--frame-visible-p)))
1194
1186
(set-frame-parameter frame 'lsp-ui-doc--no-focus nil )
1195
1187
(set-frame-parameter frame 'cursor-type t )
1196
- (lsp-ui-doc--with-buffer
1197
- (setq cursor-type 'box ))
1188
+ (lsp-ui-doc--with-buffer (setq cursor-type 'box ))
1198
1189
(select-frame-set-input-focus frame)))
1199
1190
1200
1191
(defun lsp-ui-doc-unfocus-frame ()
@@ -1204,10 +1195,8 @@ It is supposed to be called from `lsp-ui--toggle'"
1204
1195
(when-let* ((frame (lsp-ui-doc--get-frame)))
1205
1196
(set-frame-parameter frame 'lsp-ui-doc--no-focus t )
1206
1197
(set-frame-parameter frame 'cursor-type nil )
1207
- (lsp-ui-doc--with-buffer
1208
- (setq cursor-type nil ))
1209
- (when lsp-ui-doc--from-mouse
1210
- (make-frame-invisible frame))))
1198
+ (lsp-ui-doc--with-buffer (setq cursor-type nil ))
1199
+ (when lsp-ui-doc--from-mouse (make-frame-invisible frame))))
1211
1200
1212
1201
(provide 'lsp-ui-doc )
1213
1202
; ;; lsp-ui-doc.el ends here
0 commit comments