3636(require 'goto-addr )
3737(require 'markdown-mode )
3838(require 'cl-lib )
39+ (require 'lsp-ui-util )
3940
4041(when (featurep 'xwidget-internal )
4142 (require 'xwidget ))
@@ -864,9 +865,7 @@ HEIGHT is the documentation number of lines."
864865
865866(defun lsp-ui-doc--make-request nil
866867 " Request the documentation to the LS."
867- (and (not track-mouse)
868- lsp-ui-doc-show-with-mouse
869- (setq-local track-mouse t ))
868+ (and (not track-mouse) lsp-ui-doc-show-with-mouse (setq-local track-mouse t ))
870869 (when (and lsp-ui-doc-show-with-cursor
871870 (not (memq this-command lsp-ui-doc--ignore-commands))
872871 (not (bound-and-true-p lsp-ui-peek-mode))
@@ -892,6 +891,19 @@ HEIGHT is the documentation number of lines."
892891 :cancel-token :lsp-ui-doc-hover )))))))
893892 (lsp-ui-doc--hide-frame))))
894893
894+ (defcustom lsp-ui-doc-post-delay 0.2
895+ " Seconds to wait before making post request."
896+ :type 'number
897+ :group 'lsp-ui-doc )
898+
899+ (defvar-local lsp-ui-doc--post-timer nil
900+ " Timer for post command." )
901+
902+ (defun lsp-ui-doc--post-command ()
903+ " Post command hook for UI doc."
904+ (lsp-ui-util-safe-kill-timer lsp-ui-doc--post-timer)
905+ (setq lsp-ui-doc--post-timer (run-with-timer lsp-ui-doc-post-delay nil #'lsp-ui-doc--make-request )))
906+
895907(defun lsp-ui-doc--extract-bounds (hover )
896908 (-when-let* ((hover hover)
897909 (data (lsp-get hover :range ))
@@ -1091,15 +1103,15 @@ If nil, do not prevent mouse on prefix keys.")
10911103 (add-hook 'window-state-change-functions 'lsp-ui-doc--on-state-changed ))
10921104 (lsp-ui-doc--setup-mouse)
10931105 (advice-add 'handle-switch-frame :before-while 'lsp-ui-doc--prevent-focus-doc )
1094- (add-hook 'post-command-hook 'lsp-ui-doc--make-request nil t )
1106+ (add-hook 'post-command-hook 'lsp-ui-doc--post-command nil t )
10951107 (add-hook 'window-scroll-functions 'lsp-ui-doc--handle-scroll nil t )
10961108 (add-hook 'delete-frame-functions 'lsp-ui-doc--on-delete nil t ))
10971109 (t
10981110 (lsp-ui-doc-hide)
10991111 (when (boundp 'window-state-change-functions )
11001112 (remove-hook 'window-state-change-functions 'lsp-ui-doc--on-state-changed ))
11011113 (remove-hook 'window-scroll-functions 'lsp-ui-doc--handle-scroll t )
1102- (remove-hook 'post-command-hook 'lsp-ui-doc--make-request t )
1114+ (remove-hook 'post-command-hook 'lsp-ui-doc--post-command t )
11031115 (remove-hook 'delete-frame-functions 'lsp-ui-doc--on-delete t ))))
11041116
11051117(defun lsp-ui-doc-enable (enable )
0 commit comments