@@ -148,7 +148,6 @@ They are added to `markdown-code-lang-modes'")
148
148
The functions receive 2 parameters: the frame and its window." )
149
149
150
150
(defvar-local lsp-ui-doc--bounds nil )
151
- (defvar-local lsp-ui-doc--string-eldoc nil )
152
151
153
152
(declare-function lsp-ui-sideline--get-renderer 'lsp-ui-sideline )
154
153
@@ -194,17 +193,6 @@ Because some variables are buffer local.")
194
193
(frame-parameter nil 'name ))
195
194
" *" ))
196
195
197
- (defun lsp-ui-doc--set-eldoc (marked-string )
198
- (when marked-string
199
- (let ((string (lsp-ui-doc--extract-marked-string marked-string)))
200
- (setq lsp-ui-doc--string-eldoc string))))
201
-
202
- (defun lsp-ui-doc--eldoc (&rest _ )
203
- (when (and (lsp--capability " documentHighlightProvider" )
204
- lsp-highlight-symbol-at-point)
205
- (lsp-symbol-highlight))
206
- lsp-ui-doc--string-eldoc)
207
-
208
196
; ; ‘markdown-fontify-code-block-default-mode’ isn’t yet available in
209
197
; ; Markdown 2.3.
210
198
(defvar markdown-fontify-code-block-default-mode )
@@ -268,7 +256,9 @@ MODE is the mode used in the parent frame."
268
256
(let ((groups (--separate (and (hash-table-p it)
269
257
(lsp-ui-sideline--get-renderer (gethash " language" it)))
270
258
(append list-marked-string nil ))))
271
- (lsp-ui-doc--set-eldoc (caar groups))
259
+ (when-let ((marked-string (caar groups)))
260
+ ; ; Without run-with-idle-timer, echo area will be cleared after displaying the message instantly.
261
+ (run-with-idle-timer 0 nil (lambda () (eldoc-message (lsp-ui-doc--extract-marked-string marked-string)))))
272
262
(if lsp-ui-doc-include-signature
273
263
list-marked-string
274
264
(cadr groups))))
@@ -291,27 +281,30 @@ We don't extract the string that `lps-line' is already displaying."
291
281
((gethash " language" contents) ; ; MarkedString
292
282
(lsp-ui-doc--extract-marked-string contents)))))
293
283
294
- (defun lsp-ui-doc--make-request ( )
284
+ (defun lsp-ui-doc--hover ( orig-fn )
295
285
" Request the documentation to the LS."
296
- (when (and (bound-and-true-p lsp--cur-workspace)
297
- (not (bound-and-true-p lsp-ui-peek-mode))
298
- (lsp--capability " hoverProvider" ))
299
- (cond
300
- ((symbol-at-point )
301
- (let ((bounds (bounds-of-thing-at-point 'symbol )))
302
- (unless (equal lsp-ui-doc--bounds bounds)
286
+ (if lsp-ui-doc-mode
287
+ (when (and (bound-and-true-p lsp--cur-workspace)
288
+ (not (bound-and-true-p lsp-ui-peek-mode))
289
+ (lsp--capability " hoverProvider" ))
290
+ (cond
291
+ ((symbol-at-point )
292
+ (let ((bounds (bounds-of-thing-at-point 'symbol )))
293
+ (unless (equal lsp-ui-doc--bounds bounds)
294
+ (lsp--send-request-async (lsp--make-request " textDocument/hover"
295
+ (lsp--text-document-position-params))
296
+ (lambda (hover )
297
+ (lsp-ui-doc--callback hover bounds))))))
298
+ ((looking-at " [[:graph:]]" )
303
299
(lsp--send-request-async (lsp--make-request " textDocument/hover"
304
300
(lsp--text-document-position-params))
305
301
(lambda (hover )
306
- (lsp-ui-doc--callback hover bounds))))))
307
- ((looking-at " [[:graph:]]" )
308
- (lsp--send-request-async (lsp--make-request " textDocument/hover"
309
- (lsp--text-document-position-params))
310
- (lambda (hover )
311
- (lsp-ui-doc--callback hover (cons (point ) (1+ (point )))))))
312
- (t
313
- (setq lsp-ui-doc--string-eldoc nil )
314
- (lsp-ui-doc--hide-frame)))))
302
+ (lsp-ui-doc--callback hover (cons (point ) (1+ (point )))))))
303
+ (t
304
+ (eldoc-message nil )
305
+ (lsp-ui-doc--hide-frame))))
306
+ (funcall orig-fn))
307
+ nil )
315
308
316
309
(defun lsp-ui-doc--callback (hover bounds )
317
310
" Process the received documentation.
@@ -323,7 +316,7 @@ BUFFER is the buffer where the request has been made."
323
316
(let ((doc (lsp-ui-doc--extract (gethash " contents" hover))))
324
317
(setq lsp-ui-doc--bounds bounds)
325
318
(lsp-ui-doc--display (thing-at-point 'symbol t ) doc))
326
- (setq lsp-ui-doc--string- eldoc nil )
319
+ (eldoc-message nil )
327
320
(lsp-ui-doc--hide-frame)))
328
321
329
322
(defun lsp-ui-doc--hide-frame ()
@@ -643,14 +636,11 @@ HEIGHT is the documentation number of lines."
643
636
; ; ‘frameset-filter-alist’ for explanation.
644
637
(cl-callf copy-tree frameset-filter-alist)
645
638
(push '(lsp-ui-doc-frame . :never ) frameset-filter-alist)))
646
- ( add-hook 'lsp-after-open-hook 'lsp-ui-doc-enable-eldoc nil t )
647
- (add-hook 'post-command-hook 'lsp-ui-doc--make-request nil t )
639
+
640
+ (advice-add 'lsp-hover :around # 'lsp-ui-doc--hover )
648
641
(add-hook 'delete-frame-functions 'lsp-ui-doc--on-delete nil t )))
649
642
(t
650
- (remove-hook 'delete-frame-functions 'lsp-ui-doc--on-delete t )
651
- (remove-hook 'post-command-hook 'lsp-ui-doc--make-request t )
652
- (remove-hook 'lsp-after-open-hook 'lsp-ui-doc-enable-eldoc t )
653
- (setq-local eldoc-documentation-function 'lsp--on-hover ))))
643
+ (remove-hook 'delete-frame-functions 'lsp-ui-doc--on-delete t ))))
654
644
655
645
(defun lsp-ui-doc-enable (enable )
656
646
" Enable/disable ‘lsp-ui-doc-mode’.
0 commit comments