 ;;; lang/php/config.el -*- lexical-binding: t; -*-
+
+(defvar +php--company-backends nil)
 
 ;; (def-package! hack-mode
 ;;   :mode "\\.hh$"

  (unless (file-exists-p (concat php-extras-eldoc-functions-file ".el"))
    (message "Generating PHP eldoc files...")
    (require 'async)
    (async-start `(lambda ()
                    ,(async-inject-variables "\\`\\(load-path\\|php-extras-eldoc-functions-file\\)$")
                    (require 'php-extras-gen-eldoc)
                    (php-extras-generate-eldoc-1 t))
                 (lambda (_)
                   (load (concat php-extras-eldoc-functions-file ".el"))
                   (message "PHP eldoc updated!")))))


(def-package! php-refactor-mode
  :hook php-mode)


(def-package! phpunit
  :commands (phpunit-current-test phpunit-current-class phpunit-current-project))


(def-package! php-boris :commands php-boris)


(def-package! company-php
  :when (featurep! :completion company)
  :commands (company-ac-php-backend ac-php-remake-tags ac-php-remake-tags-all ac-php-core-eldoc-setup)
  :config (setq ac-php-tags-path (concat doom-cache-dir "ac-php/")))




  ;; ac-php provides custom autocompletion, php-extras provides autocompletion
  ;; for built-in libraries
  (when +php--company-backends
    (set-company-backend! 'php-mode +php--company-backends))

  ;; Use the smallest `sp-max-pair-length' for optimum `smartparens' performance
  (setq-hook! 'php-mode-hook sp-max-pair-length 6)

  (sp-with-modes '(php-mode)
