From b1c1536d62f5459274f7ffbb79807fd4e0f505cf Mon Sep 17 00:00:00 2001 From: JenChieh Date: Thu, 18 Apr 2024 03:34:31 -0700 Subject: [PATCH] fix(doc): Hovering tooltip --- lsp-ui-doc.el | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/lsp-ui-doc.el b/lsp-ui-doc.el index 23f4358f..742a40d5 100644 --- a/lsp-ui-doc.el +++ b/lsp-ui-doc.el @@ -662,7 +662,7 @@ FN is the function to call on click." (when (< fill-column (length first-line)) (fill-region start (point-max)))))) -(defun lsp-ui-doc--make-smaller-empty-lines nil +(defun lsp-ui-doc--make-smaller-empty-lines () "Make empty lines half normal lines." (progn ; Customize line before header (goto-char 1) @@ -682,7 +682,7 @@ FN is the function to call on click." (forward-line)) (insert (propertize "\n\n" 'face '(:height 0.3)))) -(defun lsp-ui-doc--fix-hr-props nil +(defun lsp-ui-doc--fix-hr-props () ;; We insert the right display prop after window-text-pixel-size (lsp-ui-doc--with-buffer (let (next) @@ -767,7 +767,7 @@ FN is the function to call on click." (defvar-local lsp-ui-doc--inline-width nil) -(defun lsp-ui-doc--inline-window-width nil +(defun lsp-ui-doc--inline-window-width () (- (min (window-text-width) (window-body-width)) (if (bound-and-true-p display-line-numbers-mode) (+ 2 (line-number-display-width)) @@ -854,7 +854,7 @@ HEIGHT is the documentation number of lines." (not (display-graphic-p)) (not (fboundp 'display-buffer-in-child-frame)))) -(defun lsp-ui-doc--highlight-hover nil +(defun lsp-ui-doc--highlight-hover () (when lsp-ui-doc--from-mouse-current (-let* (((start . end) lsp-ui-doc--bounds) (ov (if (overlayp lsp-ui-doc--highlight-ov) lsp-ui-doc--highlight-ov @@ -930,9 +930,10 @@ HEIGHT is the documentation number of lines." keyboard-quit ignore handle-switch-frame - mwheel-scroll)) + mwheel-scroll) + "List of command to ignore requests.") -(defun lsp-ui-doc--make-request nil +(defun lsp-ui-doc--make-request () "Request the documentation to the LS." (and (not track-mouse) lsp-ui-doc-show-with-mouse (setq-local track-mouse t)) (when (and lsp-ui-doc-show-with-cursor @@ -1094,9 +1095,18 @@ Argument WIN is current applying window." :mode 'tick :cancel-token :lsp-ui-doc-hover)))))) +(defun lsp-ui-doc--tooltip-mouse-motion (event) + "Default tooltip (EVENT) action." + (interactive "e") + (tooltip-hide) + (when (car (mouse-pixel-position)) + (tooltip-start-delayed-tip) + (setq tooltip-last-mouse-motion-event event))) + (defun lsp-ui-doc--handle-mouse-movement (event) "Show the documentation corresponding to the text under EVENT." (interactive "e") + (lsp-ui-doc--tooltip-mouse-motion event) (when lsp-ui-doc-show-with-mouse (lsp-ui-util-safe-kill-timer lsp-ui-doc--timer-mouse-movement) (let* ((e (cadr event)) @@ -1128,14 +1138,24 @@ Argument WIN is current applying window." "Nil if `track-mouse' was set by another package. If nil, do not prevent mouse on prefix keys.") -(defun lsp-ui-doc--setup-mouse nil - (when lsp-ui-doc-show-with-mouse +(defvar lsp-ui-doc-mode-map + (let ((map (make-sparse-keymap))) + map) + "Keymap for `lsp-ui-doc-mode'.") + +(defun lsp-ui-doc--setup-mouse () + "Setup mouse." + (cond + (lsp-ui-doc-show-with-mouse + (define-key lsp-ui-doc-mode-map (kbd "") #'lsp-ui-doc--handle-mouse-movement) (setq lsp-ui-doc--mouse-tracked-by-us (not track-mouse)) (setq-local track-mouse t) (unless lsp-ui-doc--timer-mouse-idle ;; Set only 1 timer for all buffers (setq lsp-ui-doc--timer-mouse-idle - (run-with-idle-timer 0 t 'lsp-ui-doc--disable-mouse-on-prefix))))) + (run-with-idle-timer 0 t 'lsp-ui-doc--disable-mouse-on-prefix)))) + (t + (define-key lsp-ui-doc-mode-map (kbd "") nil)))) (defun lsp-ui-doc--prevent-focus-doc (e) (not (frame-parameter (cadr e) 'lsp-ui-doc--no-focus))) @@ -1143,7 +1163,7 @@ If nil, do not prevent mouse on prefix keys.") (define-minor-mode lsp-ui-doc-mode "Minor mode for showing hover information in child frame." :init-value nil - :keymap `((,(kbd "") . lsp-ui-doc--handle-mouse-movement)) + :keymap lsp-ui-doc-mode-map :group lsp-ui-doc (cond (lsp-ui-doc-mode