Display childframe alongside company popup
This commit is contained in:
		
							parent
							
								
									5dbd37009e
								
							
						
					
					
						commit
						f292d28712
					
				
							
								
								
									
										55
									
								
								eldoc-box.el
									
									
									
									
									
								
							
							
						
						
									
										55
									
								
								eldoc-box.el
									
									
									
									
									
								
							| @ -219,9 +219,8 @@ WINDOW nil means use selected window." | |||||||
| 	(cons (+ (nth 0 edges) (nth 0 pos-in-window)) | 	(cons (+ (nth 0 edges) (nth 0 pos-in-window)) | ||||||
| 	      (+ (nth 1 edges) (nth 1 pos-in-window))))))) | 	      (+ (nth 1 edges) (nth 1 pos-in-window))))))) | ||||||
| 
 | 
 | ||||||
| (defun eldoc-box--default-at-point-position-function (width height) | (defun eldoc-box--default-at-point-position-function-1 (width height) | ||||||
|   "Set `eldoc-box-position-function' to this function to have childframe appear under point. |   "See `eldoc-box--default-at-point-position-function'." | ||||||
| Position is calculated base on WIDTH and HEIGHT of childframe text window" |  | ||||||
|   (let* ((point-pos (eldoc-box--point-position-relative-to-native-frame)) |   (let* ((point-pos (eldoc-box--point-position-relative-to-native-frame)) | ||||||
|          ;; calculate point coordinate relative to native frame |          ;; calculate point coordinate relative to native frame | ||||||
|          ;; because childframe coordinate is relative to native frame |          ;; because childframe coordinate is relative to native frame | ||||||
| @ -243,6 +242,15 @@ Position is calculated base on WIDTH and HEIGHT of childframe text window" | |||||||
|             ;; normal, just return y + em |             ;; normal, just return y + em | ||||||
|             (+ y em))))) |             (+ y em))))) | ||||||
| 
 | 
 | ||||||
|  | (defun eldoc-box--default-at-point-position-function (width height) | ||||||
|  |   "Set `eldoc-box-position-function' to this function to have childframe appear under point. | ||||||
|  | Position is calculated base on WIDTH and HEIGHT of childframe text window." | ||||||
|  |   (let* ((pos (eldoc-box--default-at-point-position-function-1 width height)) | ||||||
|  |          (x (car pos)) | ||||||
|  |          (y (cdr pos))) | ||||||
|  |     (cons (or (eldoc-box--at-point-x-by-company) x) | ||||||
|  |           y))) | ||||||
|  | 
 | ||||||
| (defun eldoc-box--get-frame (buffer) | (defun eldoc-box--get-frame (buffer) | ||||||
|   "Return a childframe displaying BUFFER. |   "Return a childframe displaying BUFFER. | ||||||
| Checkout `lsp-ui-doc--make-frame', `lsp-ui-doc--move-frame'." | Checkout `lsp-ui-doc--make-frame', `lsp-ui-doc--move-frame'." | ||||||
| @ -370,41 +378,28 @@ If (point) != last point, cleanup frame.") | |||||||
|     (let ((eldoc-box-position-function #'eldoc-box--default-at-point-position-function)) |     (let ((eldoc-box-position-function #'eldoc-box--default-at-point-position-function)) | ||||||
|       (eldoc-box--display |       (eldoc-box--display | ||||||
|        (eglot--dbind ((Hover) contents range) |        (eglot--dbind ((Hover) contents range) | ||||||
|            (jsonrpc-request (eglot--current-server-or-lose) :textDocument/hover |                      (jsonrpc-request (eglot--current-server-or-lose) :textDocument/hover | ||||||
|                             (eglot--TextDocumentPositionParams)) |                                       (eglot--TextDocumentPositionParams)) | ||||||
|          (when (seq-empty-p contents) (eglot--error "No hover info here")) |                      (when (seq-empty-p contents) (eglot--error "No hover info here")) | ||||||
|          (eglot--hover-info contents range)))) |                      (eglot--hover-info contents range)))) | ||||||
|     (setq eldoc-box-eglot-help-at-point-last-point (point)) |     (setq eldoc-box-eglot-help-at-point-last-point (point)) | ||||||
|     (run-with-timer 0.1 nil #'eldoc-box--eglot-help-at-point-cleanup))) |     (run-with-timer 0.1 nil #'eldoc-box--eglot-help-at-point-cleanup))) | ||||||
| 
 | 
 | ||||||
| ;;;; Comany compatibility | ;;;; Comany compatibility | ||||||
| ;; | ;; | ||||||
| ;; Hide childframe when company pops up |  | ||||||
| 
 | 
 | ||||||
| (defvar eldoc-box--chilframe-visible-before-company-popup nil | ;; see also `eldoc-box--default-at-point-position-function' | ||||||
|   "Set to t if company kills childframe for its popup.") |  | ||||||
| 
 | 
 | ||||||
| (defun eldoc-box--company-on-hook (&rest _) | ;; please compiler | ||||||
|   "Hide at-point doc when company popup show up." | (defvar company-pseudo-tooltip-overlay) | ||||||
|   (eldoc-box-hover-mode -1) |  | ||||||
|   (when eldoc-box-hover-at-point-mode |  | ||||||
|     (eldoc-box-quit-frame))) |  | ||||||
| 
 | 
 | ||||||
| (defun eldoc-box--company-cancel-hook (&rest _) | (defun eldoc-box--at-point-x-by-company () | ||||||
|   "Show doc when company canceled completion." |   "Return the x position that accommodates company's popup." | ||||||
|   (eldoc-box-hover-mode) |   (if (and (featurep 'company) company-pseudo-tooltip-overlay) | ||||||
|   (when (and eldoc-box-hover-at-point-mode |       (* (frame-char-width) | ||||||
|              eldoc-box--chilframe-visible-before-company-popup) |          (+ (overlay-get company-pseudo-tooltip-overlay 'company-width) | ||||||
|     (eldoc-box-show-frame))) |             (overlay-get company-pseudo-tooltip-overlay 'company-column))) | ||||||
| 
 |     nil)) | ||||||
| (defun eldoc-box--company-finish-hook (&rest _) |  | ||||||
|   "Show doc when company finished completion." |  | ||||||
|   (eldoc-box--company-cancel-hook)) |  | ||||||
| 
 |  | ||||||
| (with-eval-after-load 'company |  | ||||||
|   (add-hook 'company-completion-started-hook #'eldoc-box--company-on-hook t) |  | ||||||
|   (add-hook 'company-completion-cancelled-hook #'eldoc-box--company-cancel-hook t) |  | ||||||
|   (add-hook 'company-completion-finished-hook #'eldoc-box--company-finish-hook t)) |  | ||||||
| 
 | 
 | ||||||
| (provide 'eldoc-box) | (provide 'eldoc-box) | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Yuan Fu
						Yuan Fu