|
29 | 29 | (require 'phpactor nil t) |
30 | 30 | (require 'popup nil t) |
31 | 31 |
|
32 | | -(defvar-local php-ui-phpactor-buffer nil |
33 | | - ".") |
| 32 | +(defvar-local php-ui-phpactor-buffer nil) |
| 33 | +(defvar-local php-ui-phpactor-hover-last-pos nil) |
| 34 | +(defvar-local php-ui-phpactor-hover-last-msg nil) |
34 | 35 |
|
35 | | -(defvar-local php-ui-phpactor-last-hover-pos nil |
36 | | - ".") |
| 36 | +(declare-function phpactor--command-argments (&rest arg-keys)) |
| 37 | +(declare-function phpactor--parse-json (buffer)) |
| 38 | +(declare-function phpactor--rpc-async "phpactor" (action arguments callback)) |
| 39 | +(declare-function phpactor-goto-definition "phpactor" ()) |
| 40 | +(declare-function popup-tip "popup" (string)) |
37 | 41 |
|
38 | 42 | (defvar php-ui-phpactor-timer nil |
39 | | - ".") |
| 43 | + "Timer object for execute Phpactor and display hover message.") |
40 | 44 |
|
41 | 45 | (defun php-ui-phpactor-hover () |
42 | | - "" |
| 46 | + "Show brief information about the symbol underneath the cursor." |
43 | 47 | (interactive) |
44 | | - (when (and php-ui-phpactor-buffer (not (eq (point) php-ui-phpactor-last-hover-pos))) |
45 | | - (setq php-ui-phpactor-last-hover-pos (point)) |
46 | | - (popup-tip (phpactor-hover)))) |
| 48 | + (when php-ui-phpactor-buffer |
| 49 | + (if (eq (point) php-ui-phpactor-hover-last-pos) |
| 50 | + (when php-ui-phpactor-hover-last-msg |
| 51 | + (let ((msg php-ui-phpactor-hover-last-msg)) |
| 52 | + (setq php-ui-phpactor-hover-last-msg nil) |
| 53 | + (popup-tip msg))) |
| 54 | + (setq php-ui-phpactor-hover-last-pos (point)) |
| 55 | + (let ((main-buffer (current-buffer))) |
| 56 | + (phpactor--rpc-async "hover" (phpactor--command-argments :source :offset) |
| 57 | + (lambda (proc) |
| 58 | + (let* ((response (phpactor--parse-json (process-buffer proc))) |
| 59 | + (msg (plist-get (plist-get response :parameters) :message))) |
| 60 | + (with-current-buffer main-buffer |
| 61 | + (setq php-ui-phpactor-hover-last-msg msg))))))))) |
47 | 62 |
|
48 | 63 | ;;;###autoload |
49 | 64 | (defun php-ui-phpactor-activate () |
50 | | - "" |
| 65 | + "Activate PHP-UI using phpactor.el." |
51 | 66 | (interactive) |
52 | 67 | (unless php-ui-phpactor-timer |
53 | | - (setq php-ui-phpactor-timer (run-with-timer 1.0 5 #'php-ui-phpactor-hover))) |
| 68 | + (setq php-ui-phpactor-timer (run-with-timer 1.0 1 #'php-ui-phpactor-hover))) |
54 | 69 | (setq php-ui-phpactor-buffer t)) |
55 | 70 |
|
56 | 71 | ;;;###autoload |
57 | 72 | (defun php-ui-phpactor-deactivate () |
58 | | - "" |
| 73 | + "Dectivate PHP-UI using phpactor.el." |
59 | 74 | (interactive) |
| 75 | + (when php-ui-phpactor-timer |
| 76 | + (cancel-timer php-ui-phpactor-timer) |
| 77 | + (setq php-ui-phpactor-timer nil)) |
60 | 78 | (setq php-ui-phpactor-buffer nil)) |
61 | 79 |
|
62 | 80 | (provide 'php-ui-phpactor) |
|
0 commit comments