@@ -114,7 +114,8 @@ ACTIVATEP non-nil means activate mouse motion events."
114114 (kill-local-variable 'track-mouse ))))
115115
116116(defun dap-tooltip-mouse-motion (event )
117- " Command handler for mouse movement events in `dap-mode-map' ."
117+ " Command handler for mouse movement events in `dap-mode-map' .
118+ EVENT is the last mouse movement event."
118119 (interactive " e" )
119120 (tooltip-hide )
120121 (when (car (mouse-pixel-position ))
@@ -168,22 +169,17 @@ If there is an active selection - return it."
168169 (setq dap-mouse--hide-timer nil )
169170 (remove-hook 'post-command-hook #'dap-tooltip-post-tooltip )))))))
170171
171- (defun dap-tooltip-tips (event )
172- " Show tip for identifier or selection under the mouse.
173- The mouse must either point at an identifier or inside a selected
174- region for the tip window to be shown. In the case of a C program
175- controlled by GDB, show the associated #define directives when program is
176- not executing.
177-
178- This function must return nil if it doesn't handle EVENT."
179- (setq dap-tooltip--request (1+ dap-tooltip--request))
180-
172+ (defun dap-tooltip-at-point (&optional pos )
173+ " Show information about the variable under point.
174+ The result is displayed in a `treemacs' `posframe' . POS,
175+ defaulting to `point' , specifies where the cursor is and
176+ consequently where to show the `posframe' ."
177+ (interactive )
178+ (cl-incf dap-tooltip--request)
181179 (let ((debug-session (dap--cur-session))
182- (mouse-point (posn-point ( event-end event )))
180+ (mouse-point (or pos ( point )))
183181 (request-id dap-tooltip--request))
184- (when (and (eventp event)
185- (dap--session-running debug-session)
186- dap-tooltip-mode
182+ (when (and (dap--session-running debug-session)
187183 mouse-point)
188184 (-when-let* ((active-frame-id (-some->> debug-session
189185 dap--debug-session-active-frame
@@ -197,38 +193,40 @@ This function must return nil if it doesn't handle EVENT."
197193 (list :expression expression
198194 :frameId active-frame-id
199195 :context " hover" ))
200- (-lambda ((&hash " success" " body"
201- (&hash? " result"
202- " variablesReference" variables-reference)))
203- (when (and success
204- ; ; REVIEW: hover failure will yield weird errors involving
205- ; ; process filters, so I resorted to this hack; we should
206- ; ; perhaps do proper error handling?
207- (= request-id dap-tooltip--request))
208- (add-text-properties
209- start end '(mouse-face dap-mouse-eval-thing-face))
210- ; ; REVIEW: I inherited this code; why kill the buffer first,
211- ; ; then show it, and then initialize it?
212- (when (get-buffer dap-mouse-buffer)
213- (kill-buffer dap-mouse-buffer))
214- (unless (and (zerop variables-reference) (string-empty-p result))
215- (apply #'posframe-show dap-mouse-buffer
216- :position start
217- :accept-focus t
218- dap-mouse-posframe-properties)
219- (with-current-buffer (get-buffer-create dap-mouse-buffer)
220- (lsp-treemacs-render
221- `((:key , expression
222- :label , result
223- :icon dap-field
224- ,@(unless (zerop variables-reference)
225- (list :children
226- (-partial #'dap-ui-render-variables
227- debug-session
228- variables-reference)))))
229- " " nil (buffer-name ))))
230- (add-hook 'post-command-hook 'dap-tooltip-post-tooltip )))
231- debug-session))))
196+ (dap--resp-handler
197+ (-lambda ((&hash " body" (&hash? " result"
198+ " variablesReference" variables-reference)))
199+ (when (= request-id dap-tooltip--request)
200+ (add-text-properties
201+ start end '(mouse-face dap-mouse-eval-thing-face))
202+ ; ; Show a dead buffer so that the `posframe' size is consistent.
203+ (when (get-buffer dap-mouse-buffer)
204+ (kill-buffer dap-mouse-buffer))
205+ (unless (and (zerop variables-reference) (string-empty-p result))
206+ (apply #'posframe-show dap-mouse-buffer
207+ :position start
208+ :accept-focus t
209+ dap-mouse-posframe-properties)
210+ (with-current-buffer (get-buffer-create dap-mouse-buffer)
211+ (dap-ui-render-value debug-session expression
212+ result variables-reference)))
213+ (add-hook 'post-command-hook 'dap-tooltip-post-tooltip )))
214+ ; ; TODO: hover failure will yield weird errors involving process
215+ ; ; filters, so I resorted to this hack; we should proably do proper
216+ ; ; error handling, with a whitelist of allowable errors.
217+ #'ignore )
218+ debug-session)))))
219+
220+ (defun dap-tooltip-tips (event )
221+ " Show tip for identifier or selection under the mouse.
222+ The mouse must either point at an identifier or inside a selected
223+ region for the tip window to be shown. In the case of a C program
224+ controlled by GDB, show the associated #define directives when
225+ program is not executing.
226+
227+ This function must return nil if it doesn't handle EVENT."
228+ (when (and (eventp event) dap-tooltip-mode)
229+ (dap-tooltip-at-point (posn-point (event-end event))))
232230 " " )
233231
234232(provide 'dap-mouse )
0 commit comments