Display childframe alongside company popup

This commit is contained in:
Yuan Fu 2019-06-07 20:31:35 +08:00
parent 5dbd37009e
commit f292d28712
No known key found for this signature in database
GPG Key ID: 56E19BC57664A442

View File

@ -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'."
@ -379,32 +387,19 @@ If (point) != last point, cleanup frame.")
;;;; 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)