@@ -147,8 +147,6 @@ They are added to `markdown-code-lang-modes'")
147
147
" Hooks run on child-frame creation.
148
148
The functions receive 2 parameters: the frame and its window." )
149
149
150
- (defvar-local lsp-ui-doc--bounds nil )
151
-
152
150
; ; Avoid warning with emacs < 26
153
151
(declare-function display-buffer-in-child-frame " window.el" )
154
152
@@ -265,59 +263,38 @@ MODE is the mode used in the parent frame."
265
263
CONTENTS can be differents type of values:
266
264
MarkedString | MarkedString[] | MarkupContent (as defined in the LSP).
267
265
We don't extract the string that `lps-line' is already displaying."
268
- (when contents
269
- (cond
270
- ((stringp contents) contents)
271
- ((sequencep contents) ; ; MarkedString[]
272
- (mapconcat 'lsp-ui-doc--extract-marked-string
273
- (lsp-ui-doc--filter-marked-string contents)
274
- " \n\n "
275
- ; ; (propertize "\n\n" 'face '(:height 0.4))
276
- ))
277
- ((gethash " kind" contents) (gethash " value" contents)) ; ; MarkupContent
278
- ((gethash " language" contents) ; ; MarkedString
279
- (lsp-ui-doc--extract-marked-string contents)))))
280
-
281
- (defun lsp-ui-doc--hover (orig-fn )
282
- " Request the documentation to the LS."
266
+ (cond
267
+ ((stringp contents) contents)
268
+ ((sequencep contents) ; ; MarkedString[]
269
+ (mapconcat 'lsp-ui-doc--extract-marked-string
270
+ (lsp-ui-doc--filter-marked-string contents)
271
+ " \n\n "
272
+ ; ; (propertize "\n\n" 'face '(:height 0.4))
273
+ ))
274
+ ((gethash " kind" contents) (gethash " value" contents)) ; ; MarkupContent
275
+ ((gethash " language" contents) ; ; MarkedString
276
+ (lsp-ui-doc--extract-marked-string contents))))
277
+
278
+ (defun lsp-ui-doc--render-on-hover-content (orig-fn contents &rest args )
283
279
(if lsp-ui-doc-mode
284
- (when (and (not (bound-and-true-p lsp-ui-peek-mode))
285
- (lsp--capability " hoverProvider" ))
286
- (cond
287
- ((symbol-at-point )
288
- (let ((bounds (bounds-of-thing-at-point 'symbol )))
289
- (unless (equal lsp-ui-doc--bounds bounds)
290
- (lsp--send-request-async (lsp--make-request " textDocument/hover"
291
- (lsp--text-document-position-params))
292
- (lambda (hover )
293
- (lsp-ui-doc--callback hover bounds))))))
294
- ((looking-at " [[:graph:]]" )
295
- (lsp--send-request-async (lsp--make-request " textDocument/hover"
296
- (lsp--text-document-position-params))
297
- (lambda (hover )
298
- (lsp-ui-doc--callback hover (cons (point ) (1+ (point )))))))
299
- (t
300
- (eldoc-message nil )
301
- (lsp-ui-doc--hide-frame))))
302
- (funcall orig-fn))
303
- nil )
304
-
305
- (defun lsp-ui-doc--callback (hover bounds )
280
+ contents
281
+ (apply orig-fn contents args)))
282
+
283
+ (defun lsp-ui-doc--hover-callback (orig-fn from-cache )
306
284
" Process the received documentation.
307
285
HOVER is the doc returned by the LS.
308
286
BOUNDS are points of the symbol that have been requested.
309
287
BUFFER is the buffer where the request has been made."
310
- (if ( and hover
311
- ( lsp--point-is-within-bounds-p ( car bounds) ( cdr bounds)))
312
- ( let ((doc (lsp-ui-doc--extract ( gethash " contents " hover))) )
313
- ( setq lsp-ui-doc--bounds bounds )
314
- (lsp-ui-doc--display ( thing-at-point 'symbol t ) doc) )
315
- ( eldoc-message nil )
316
- (lsp-ui-doc--hide-frame )))
288
+ (if lsp-ui-doc-mode
289
+ ( if lsp--hover-saved-contents
290
+ (lsp-ui-doc--display ( thing-at-point 'symbol t )
291
+ ( lsp-ui-doc--extract lsp--hover-saved-contents) )
292
+ (eldoc-message nil )
293
+ (lsp-ui-doc--hide-frame) )
294
+ (funcall orig-fn )))
317
295
318
296
(defun lsp-ui-doc--hide-frame ()
319
297
" Hide the frame."
320
- (setq lsp-ui-doc--bounds nil )
321
298
(when (overlayp lsp-ui-doc--inline-ov)
322
299
(delete-overlay lsp-ui-doc--inline-ov))
323
300
(when (lsp-ui-doc--get-frame)
@@ -633,7 +610,8 @@ HEIGHT is the documentation number of lines."
633
610
(cl-callf copy-tree frameset-filter-alist)
634
611
(push '(lsp-ui-doc-frame . :never ) frameset-filter-alist)))
635
612
636
- (advice-add 'lsp-hover :around #'lsp-ui-doc--hover )
613
+ (advice-add 'lsp--render-on-hover-content :around #'lsp-ui-doc--render-on-hover-content )
614
+ (advice-add 'lsp--hover-callback :around #'lsp-ui-doc--hover-callback )
637
615
(add-hook 'delete-frame-functions 'lsp-ui-doc--on-delete nil t )))
638
616
(t
639
617
(remove-hook 'delete-frame-functions 'lsp-ui-doc--on-delete t ))))
0 commit comments