From d713ca07e6cf149a258c8f1c758b02f2949f53ad Mon Sep 17 00:00:00 2001 From: JenChieh Date: Sat, 19 Jun 2021 16:52:32 +0800 Subject: [PATCH 1/3] Rename timer util to public --- lsp-ui-imenu.el | 2 +- lsp-ui-util.el | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lsp-ui-imenu.el b/lsp-ui-imenu.el index 08d85e34..a23c471e 100644 --- a/lsp-ui-imenu.el +++ b/lsp-ui-imenu.el @@ -379,7 +379,7 @@ ITEMS are used when the kind position is 'left." (defun lsp-ui-imenu--start-refresh (&rest _) "Starts the auto refresh timer." - (lsp-ui-util--safe-kill-timer lsp-ui-imenu--refresh-timer) + (lsp-ui-util-safe-kill-timer lsp-ui-imenu--refresh-timer) (setq lsp-ui-imenu--refresh-timer (run-with-idle-timer lsp-ui-imenu-auto-refresh-delay nil #'lsp-ui-imenu--refresh))) diff --git a/lsp-ui-util.el b/lsp-ui-util.el index 3d1daf51..f9844317 100644 --- a/lsp-ui-util.el +++ b/lsp-ui-util.el @@ -32,7 +32,7 @@ ;;; Code: -(defun lsp-ui-util--safe-kill-timer (timer) +(defun lsp-ui-util-safe-kill-timer (timer) "Safely kill the TIMER." (when (timerp timer) (cancel-timer timer))) From 616ee91ba03bd92912514d5e88cb6068519fb146 Mon Sep 17 00:00:00 2001 From: JenChieh Date: Sat, 19 Jun 2021 16:58:50 +0800 Subject: [PATCH 2/3] Delay post request --- lsp-ui-doc.el | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lsp-ui-doc.el b/lsp-ui-doc.el index be1d9567..257ba88d 100644 --- a/lsp-ui-doc.el +++ b/lsp-ui-doc.el @@ -864,9 +864,7 @@ HEIGHT is the documentation number of lines." (defun lsp-ui-doc--make-request nil "Request the documentation to the LS." - (and (not track-mouse) - lsp-ui-doc-show-with-mouse - (setq-local track-mouse t)) + (and (not track-mouse) lsp-ui-doc-show-with-mouse (setq-local track-mouse t)) (when (and lsp-ui-doc-show-with-cursor (not (memq this-command lsp-ui-doc--ignore-commands)) (not (bound-and-true-p lsp-ui-peek-mode)) @@ -892,6 +890,19 @@ HEIGHT is the documentation number of lines." :cancel-token :lsp-ui-doc-hover))))))) (lsp-ui-doc--hide-frame)))) +(defcustom lsp-ui-doc-post-delay 0.2 + "Seconds to wait before making post request." + :type 'number + :group 'lsp-ui-doc) + +(defvar-local lsp-ui-doc--post-timer nil + "Timer for post command.") + +(defun lsp-ui-doc--post-command () + "Post command hook for UI doc." + (lsp-ui-util-safe-kill-timer lsp-ui-doc--post-timer) + (setq lsp-ui-doc--post-timer (run-with-timer lsp-ui-doc-post-delay nil #'lsp-ui-doc--make-request))) + (defun lsp-ui-doc--extract-bounds (hover) (-when-let* ((hover hover) (data (lsp-get hover :range)) @@ -1091,7 +1102,7 @@ If nil, do not prevent mouse on prefix keys.") (add-hook 'window-state-change-functions 'lsp-ui-doc--on-state-changed)) (lsp-ui-doc--setup-mouse) (advice-add 'handle-switch-frame :before-while 'lsp-ui-doc--prevent-focus-doc) - (add-hook 'post-command-hook 'lsp-ui-doc--make-request nil t) + (add-hook 'post-command-hook 'lsp-ui-doc--post-command nil t) (add-hook 'window-scroll-functions 'lsp-ui-doc--handle-scroll nil t) (add-hook 'delete-frame-functions 'lsp-ui-doc--on-delete nil t)) (t @@ -1099,7 +1110,7 @@ If nil, do not prevent mouse on prefix keys.") (when (boundp 'window-state-change-functions) (remove-hook 'window-state-change-functions 'lsp-ui-doc--on-state-changed)) (remove-hook 'window-scroll-functions 'lsp-ui-doc--handle-scroll t) - (remove-hook 'post-command-hook 'lsp-ui-doc--make-request t) + (remove-hook 'post-command-hook 'lsp-ui-doc--post-command t) (remove-hook 'delete-frame-functions 'lsp-ui-doc--on-delete t)))) (defun lsp-ui-doc-enable (enable) From 705853bb91533afd1b2ba9c7fd64166c32f013c7 Mon Sep 17 00:00:00 2001 From: JenChieh Date: Sat, 19 Jun 2021 17:02:35 +0800 Subject: [PATCH 3/3] Add missing module --- lsp-ui-doc.el | 1 + 1 file changed, 1 insertion(+) diff --git a/lsp-ui-doc.el b/lsp-ui-doc.el index 257ba88d..f4850e73 100644 --- a/lsp-ui-doc.el +++ b/lsp-ui-doc.el @@ -36,6 +36,7 @@ (require 'goto-addr) (require 'markdown-mode) (require 'cl-lib) +(require 'lsp-ui-util) (when (featurep 'xwidget-internal) (require 'xwidget))