Skip to content

Commit e5d4645

Browse files
authored
Revert from #674 (#676)
1 parent de4796c commit e5d4645

7 files changed

+341
-295
lines changed

lsp-ui-doc.el

+104-93
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
;;; Code:
3232

33+
(require 'lsp-ui-util)
34+
3335
(require 'lsp-protocol)
3436
(require 'lsp-mode)
3537
(require 'dash)
@@ -52,9 +54,6 @@
5254
(declare-function xwidget-webkit-execute-script-rv "ext:xwidget" (xwidget script &optional default))
5355
(declare-function xwidget-resize "ext:xwidget" (xwidget new-width new-height))
5456

55-
(declare-function lsp-ui--with-no-redisplay 'lsp-ui)
56-
(declare-function lsp-ui--safe-kill-timer 'lsp-ui)
57-
5857
(defgroup lsp-ui-doc nil
5958
"Display informations of the current line."
6059
:group 'tools
@@ -181,29 +180,29 @@ Only the `background' is used in this face."
181180
:group 'lsp-ui-doc)
182181

183182
(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)
203202
(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))
207206
"Frame parameters used to create the frame.")
208207

209208
(defvar lsp-ui-doc-render-function nil
@@ -247,14 +246,19 @@ Because some variables are buffer local.")
247246
(defmacro lsp-ui-doc--with-buffer (&rest body)
248247
"Execute BODY in the lsp-ui-doc buffer."
249248
(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))))))
258262

259263
(defmacro lsp-ui-doc--get-parent (var)
260264
"Return VAR in `lsp-ui-doc--parent-vars'."
@@ -308,7 +312,7 @@ Because some variables are buffer local.")
308312
(or (lsp:marked-string-language marked-string)
309313
(lsp:markup-content-kind marked-string)))
310314
language))
311-
markdown-hr-display-char)
315+
(markdown-hr-display-char nil))
312316
(cond
313317
(lsp-ui-doc-use-webkit
314318
(if (and language
@@ -398,7 +402,8 @@ We don't extract the string that `lps-line' is already displaying."
398402

399403
(defun lsp-ui-doc--webkit-get-xwidget ()
400404
"Return Xwidget instance."
401-
(lsp-ui-doc--with-buffer (xwidget-at 1)))
405+
(lsp-ui-doc--with-buffer
406+
(xwidget-at 1)))
402407

403408
(defun lsp-ui-doc--webkit-execute-script (script &optional fn)
404409
"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."
414419
"Hide the frame."
415420
(setq lsp-ui-doc--bounds nil
416421
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)
419424
(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))))
421427

422428
(defun lsp-ui-doc--buffer-width ()
423429
"Calcul the max width of the buffer."
@@ -506,57 +512,59 @@ FRAME just below the symbol at point."
506512

507513
(defun lsp-ui-doc--move-frame (frame)
508514
"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))))
560568

561569
(defun lsp-ui-doc--visit-file (filename)
562570
"Visit FILENAME in the parent frame."
@@ -905,7 +913,7 @@ HEIGHT is the documentation number of lines."
905913
(and (looking-at "[[:graph:]]") (cons (point) (1+ (point))))))
906914
(unless (equal lsp-ui-doc--bounds bounds)
907915
(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)
909917
(setq lsp-ui-doc--timer
910918
(run-with-idle-timer
911919
lsp-ui-doc-delay nil
@@ -1185,7 +1193,8 @@ It is supposed to be called from `lsp-ui--toggle'"
11851193
(visible (lsp-ui-doc--frame-visible-p)))
11861194
(set-frame-parameter frame 'lsp-ui-doc--no-focus nil)
11871195
(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))
11891198
(select-frame-set-input-focus frame)))
11901199

11911200
(defun lsp-ui-doc-unfocus-frame ()
@@ -1195,8 +1204,10 @@ It is supposed to be called from `lsp-ui--toggle'"
11951204
(when-let* ((frame (lsp-ui-doc--get-frame)))
11961205
(set-frame-parameter frame 'lsp-ui-doc--no-focus t)
11971206
(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))))
12001211

12011212
(provide 'lsp-ui-doc)
12021213
;;; lsp-ui-doc.el ends here

lsp-ui-flycheck.el

+6-4
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@ whole workspace."
5050
(defvar-local lsp-ui-flycheck--save-mode nil)
5151

5252
(defun lsp-ui-flycheck-list--post-command ()
53-
(when (eobp) (forward-line -1)))
53+
(when (eobp)
54+
(forward-line -1)))
5455

5556
(defun lsp-ui-flycheck-list--update (window workspace)
5657
"Update flycheck buffer in WINDOW belonging to WORKSPACE.
5758
Use `lsp-diagnostics' to receive diagnostics from your LSP server."
58-
(let ((lsp--cur-workspace workspace) buffer-read-only)
59+
(let ((buffer-read-only nil)
60+
(lsp--cur-workspace workspace))
5961
(erase-buffer)
6062
(remove-overlays)
6163
(maphash (lambda (file diagnostic)
@@ -159,8 +161,8 @@ Use `lsp-diagnostics' to receive diagnostics from your LSP server."
159161

160162
(define-derived-mode lsp-ui-flycheck-list-mode special-mode "lsp-ui-flycheck-list"
161163
"Mode showing flycheck diagnostics for the whole workspace."
162-
(setq truncate-lines t
163-
mode-line-format nil)
164+
(setq truncate-lines t)
165+
(setq mode-line-format nil)
164166
(add-hook 'post-command-hook 'lsp-ui-flycheck-list--post-command nil t))
165167

166168
(declare-function lsp-ui--workspace-path "lsp-ui" (path))

lsp-ui-imenu.el

+2-3
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535

3636
(require 'lsp-mode)
3737
(require 'dash)
38-
39-
(declare-function lsp-ui--safe-kill-timer 'lsp-ui)
38+
(require 'lsp-ui-util)
4039

4140
(defgroup lsp-ui-imenu nil
4241
"Display imenu entries."
@@ -380,7 +379,7 @@ ITEMS are used when the kind position is 'left."
380379

381380
(defun lsp-ui-imenu--start-refresh (&rest _)
382381
"Starts the auto refresh timer."
383-
(lsp-ui--safe-kill-timer lsp-ui-imenu--refresh-timer)
382+
(lsp-ui-util-safe-kill-timer lsp-ui-imenu--refresh-timer)
384383
(setq lsp-ui-imenu--refresh-timer
385384
(run-with-idle-timer lsp-ui-imenu-auto-refresh-delay nil #'lsp-ui-imenu--refresh)))
386385

lsp-ui-peek.el

+10-10
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
(require 'xref)
4040
(require 'dash)
4141

42-
(declare-function lsp-ui--mute-apply 'lsp-ui)
43-
4442
(defgroup lsp-ui-peek nil
4543
"Improve version of xref with peek feature."
4644
:group 'tools
@@ -183,12 +181,12 @@ will cause performances issues.")
183181
(eval '(progn
184182
(evil-define-motion lsp-ui-peek-jump-backward (count)
185183
(lsp-ui-peek--with-evil-jumps
186-
(evil--jump-backward count)
187-
(run-hooks 'xref-after-return-hook)))
184+
(evil--jump-backward count)
185+
(run-hooks 'xref-after-return-hook)))
188186
(evil-define-motion lsp-ui-peek-jump-forward (count)
189187
(lsp-ui-peek--with-evil-jumps
190-
(evil--jump-forward count)
191-
(run-hooks 'xref-after-return-hook))))
188+
(evil--jump-forward count)
189+
(run-hooks 'xref-after-return-hook))))
192190
t))
193191

194192
(defmacro lsp-ui-peek--prop (prop &optional string)
@@ -348,8 +346,10 @@ XREFS is a list of references/definitions."
348346
(with-temp-buffer
349347
(insert string)
350348
(delay-mode-hooks
351-
(lsp-ui--mute-apply (funcall major))
352-
(ignore-errors (font-lock-ensure)))
349+
(let ((inhibit-message t))
350+
(funcall major))
351+
(ignore-errors
352+
(font-lock-ensure)))
353353
(buffer-string)))
354354

355355
(defun lsp-ui-peek--peek ()
@@ -687,9 +687,9 @@ LOCATION can be either a LSP Location or SymbolInformation."
687687
(unless buffer-file-name
688688
(make-local-variable 'delay-mode-hooks)
689689
(let ((buffer-file-name filename)
690+
(enable-local-variables nil)
690691
(inhibit-message t)
691-
(delay-mode-hooks t)
692-
enable-local-variables)
692+
(delay-mode-hooks t))
693693
(set-auto-mode)))
694694
(font-lock-ensure)))
695695

0 commit comments

Comments
 (0)