lang/php: refactor company init
This commit is contained in:
parent
429decef87
commit
56cba7828c
2 changed files with 11 additions and 12 deletions
|
@ -2,17 +2,6 @@
|
||||||
|
|
||||||
(defvar +php-composer-conf (make-hash-table :test 'equal))
|
(defvar +php-composer-conf (make-hash-table :test 'equal))
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun +php-company-backend (command &optional arg &rest _ignored)
|
|
||||||
"A delegating company-backend that uses `company-phpactor' if phpactor is
|
|
||||||
available and installed, or `php-extras-company' otherwise."
|
|
||||||
(cond ((and (require 'company-phpactor nil t)
|
|
||||||
(ignore-errors (phpactor-find-executable)))
|
|
||||||
(company-phpactor command arg))
|
|
||||||
((and (require 'php-extras nil t)
|
|
||||||
(file-exists-p (concat php-extras-eldoc-functions-file ".el")))
|
|
||||||
(php-extras-company command arg))))
|
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun +php-composer-conf (&optional project-root refresh-p)
|
(defun +php-composer-conf (&optional project-root refresh-p)
|
||||||
"Retrieve the contents of composer.json as an alist. If REFRESH-P is non-nil
|
"Retrieve the contents of composer.json as an alist. If REFRESH-P is non-nil
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
;;; lang/php/config.el -*- lexical-binding: t; -*-
|
;;; lang/php/config.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
|
(defvar +php--company-backends nil
|
||||||
|
"List of company backends to use in `php-mode'.")
|
||||||
|
|
||||||
(after! projectile
|
(after! projectile
|
||||||
(add-to-list 'projectile-project-root-files "composer.json"))
|
(add-to-list 'projectile-project-root-files "composer.json"))
|
||||||
|
|
||||||
|
@ -23,7 +26,10 @@
|
||||||
(add-hook 'php-mode-local-vars-hook #'lsp!)
|
(add-hook 'php-mode-local-vars-hook #'lsp!)
|
||||||
;; `+php-company-backend' uses `company-phpactor', `php-extras-company' or
|
;; `+php-company-backend' uses `company-phpactor', `php-extras-company' or
|
||||||
;; `company-dabbrev-code', in that order.
|
;; `company-dabbrev-code', in that order.
|
||||||
(set-company-backend! 'php-mode '+php-company-backend 'company-dabbrev-code))
|
(when +php--company-backends
|
||||||
|
(set-company-backend! 'php-mode
|
||||||
|
(cons :separate +php--company-backends)
|
||||||
|
'company-dabbrev-code)))
|
||||||
|
|
||||||
;; Use the smallest `sp-max-pair-length' for optimum `smartparens' performance
|
;; Use the smallest `sp-max-pair-length' for optimum `smartparens' performance
|
||||||
(setq-hook! 'php-mode-hook sp-max-pair-length 5)
|
(setq-hook! 'php-mode-hook sp-max-pair-length 5)
|
||||||
|
@ -43,6 +49,8 @@
|
||||||
(use-package! phpactor
|
(use-package! phpactor
|
||||||
:unless (featurep! +lsp)
|
:unless (featurep! +lsp)
|
||||||
:after php-mode
|
:after php-mode
|
||||||
|
:init
|
||||||
|
(add-to-list '+php--company-backends #'company-phpactor nil 'eq)
|
||||||
:config
|
:config
|
||||||
(set-lookup-handlers! 'php-mode
|
(set-lookup-handlers! 'php-mode
|
||||||
:definition #'phpactor-goto-definition)
|
:definition #'phpactor-goto-definition)
|
||||||
|
@ -74,6 +82,8 @@
|
||||||
:preface
|
:preface
|
||||||
;; We'll set up company support ourselves
|
;; We'll set up company support ourselves
|
||||||
(advice-add #'php-extras-company-setup :override #'ignore)
|
(advice-add #'php-extras-company-setup :override #'ignore)
|
||||||
|
:init
|
||||||
|
(add-to-list '+php--company-backends #'php-extras-company)
|
||||||
:config
|
:config
|
||||||
(setq php-extras-eldoc-functions-file
|
(setq php-extras-eldoc-functions-file
|
||||||
(concat doom-etc-dir "php-extras-eldoc-functions"))
|
(concat doom-etc-dir "php-extras-eldoc-functions"))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue