Merge pull request #17 from casouri/cover-company-fix

Display childframe alongside company popup
This commit is contained in:
Yuan Fu 2019-06-10 20:30:43 +08:00 committed by GitHub
commit 46027fb449
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -219,9 +219,8 @@ WINDOW nil means use selected window."
(cons (+ (nth 0 edges) (nth 0 pos-in-window))
(+ (nth 1 edges) (nth 1 pos-in-window)))))))
(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"
(defun eldoc-box--default-at-point-position-function-1 (width height)
"See `eldoc-box--default-at-point-position-function'."
(let* ((point-pos (eldoc-box--point-position-relative-to-native-frame))
;; calculate point coordinate 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
(+ 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)
"Return a childframe displaying BUFFER.
Checkout `lsp-ui-doc--make-frame', `lsp-ui-doc--move-frame'."
@ -379,32 +387,19 @@ If (point) != last point, cleanup frame.")
;;;; Comany compatibility
;;
;; Hide childframe when company pops up
(defvar eldoc-box--chilframe-visible-before-company-popup nil
"Set to t if company kills childframe for its popup.")
;; see also `eldoc-box--default-at-point-position-function'
(defun eldoc-box--company-on-hook (&rest _)
"Hide at-point doc when company popup show up."
(eldoc-box-hover-mode -1)
(when eldoc-box-hover-at-point-mode
(eldoc-box-quit-frame)))
;; please compiler
(defvar company-pseudo-tooltip-overlay)
(defun eldoc-box--company-cancel-hook (&rest _)
"Show doc when company canceled completion."
(eldoc-box-hover-mode)
(when (and eldoc-box-hover-at-point-mode
eldoc-box--chilframe-visible-before-company-popup)
(eldoc-box-show-frame)))
(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))
(defun eldoc-box--at-point-x-by-company ()
"Return the x position that accommodates company's popup."
(if (and (featurep 'company) company-pseudo-tooltip-overlay)
(* (frame-char-width)
(+ (overlay-get company-pseudo-tooltip-overlay 'company-width)
(overlay-get company-pseudo-tooltip-overlay 'company-column)))
nil))
(provide 'eldoc-box)