Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions lsp-ui-doc.el
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
(require 'goto-addr)
(require 'markdown-mode)
(require 'cl-lib)
(require 'lsp-ui-util)

(when (featurep 'xwidget-internal)
(require 'xwidget))
Expand Down Expand Up @@ -864,9 +865,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))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replace it with just one line so it's much cleaner IMO.

(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))
Expand All @@ -892,6 +891,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))
Expand Down Expand Up @@ -1091,15 +1103,15 @@ 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
(lsp-ui-doc-hide)
(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)
Expand Down
2 changes: 1 addition & 1 deletion lsp-ui-imenu.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand Down
2 changes: 1 addition & 1 deletion lsp-ui-util.el
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

;;; Code:

(defun lsp-ui-util--safe-kill-timer (timer)
(defun lsp-ui-util-safe-kill-timer (timer)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just rename the util function from private to public.

"Safely kill the TIMER."
(when (timerp timer) (cancel-timer timer)))

Expand Down