reddit / emacs

goto definition hangs for a long time when using php-mode + phpactor

BrokenMayo · 2022-09-08 10:36
I've been using emacs for about a week on and off, and I've just started setting it up for php Here is my init.el file \`\`\` ;; My emacs init.el &#x200B; ;; Disable Menu Bar (menu-bar-mode -1) &#x200B; ;; Disble the scrollbar and toolbar (if (display-graphic-p) (progn (tool-bar-mode -1) (scroll-bar-mode -1))) &#x200B; ;; Enable Line Numbers? (global-display-line-numbers-mode 1) &#x200B; ;; Font Settings (set-face-attribute 'default nil :height 180) &#x200B; ;; Cursor Type (setq-default cursor-type 'bar) (set-cursor-color "#fff") (add-to-list 'default-frame-alist '(cursor-color . "#fff")) &#x200B; &#x200B; ;; Margin Settings (setq-default left-margin-width 4 right-margin-width 4) (set-window-buffer nil (current-buffer)) &#x200B; ;; use-package (add-to-list 'load-path "\~/.emacs.d/site-lisp/use-package") (require 'use-package) &#x200B; (with-eval-after-load 'info (info-initialize) (add-to-list 'Info-directory-list "\~/.emacs.d/site-list/use-package")) &#x200B; &#x200B; ;; js2 (require 'js2-mode) (add-to-list 'auto-mode-alist '("\\\\.js\\\\'" . js2-mode)) &#x200B; ;; Better imenu (add-hook 'js2-mode-hook #'js2-imenu-extras-mode) &#x200B; ;; more js2 (require 'js2-refactor) (require 'xref-js2) &#x200B; (add-hook 'js2-mode-hook #'js2-refactor-mode) (js2r-add-keybindings-with-prefix "C-c C-r") (define-key js2-mode-map (kbd "C-k") #'js2r-kill) &#x200B; (define-key js-mode-map (kbd "M-.") nil) &#x200B; (add-hook 'js2-mode-hook (lambda () (add-hook 'xref-backend-functions #'xref-js2-xref-backend nil t))) &#x200B; ;; php (use-package phpactor :ensure t) (use-package company-phpactor :ensure t) &#x200B; (use-package php-mode :hook ((php-mode . (lambda () (set (make-local-variable 'company-backends) '( company-phpactor company-files )))))) &#x200B; (with-eval-after-load 'php-mode (define-key php-mode-map (kbd "M-.") #'phpactor-goto-definition) (define-key php-mode-map (kbd "M-?") #'phpactor-find-references)) &#x200B; &#x200B; ;; Projectile Settings (projectile-mode +1) (setq project-project-search-path '("\~/Projects/" . 1)) (define-key projectile-mode-map (kbd "s-p") 'projectile-command-map) &#x200B; (require 'package) (add-to-list 'package-archives '("melpa" . "[https://melpa.org/packages/](https://melpa.org/packages/)") t) (package-initialize) &#x200B; (ivy-mode) (setq ivy-use-virtual-buffers t) (setq enable-recursive-minibuffers t) ;; enable this if you want \`swiper' to use it ;; (setq search-default-mode #'char-fold-to-regexp) (global-set-key "\\C-s" 'swiper) (global-set-key (kbd "C-c C-r") 'ivy-resume) (global-set-key (kbd "<f6>") 'ivy-resume) (global-set-key (kbd "M-x") 'counsel-M-x) (global-set-key (kbd "C-x C-f") 'counsel-find-file) (global-set-key (kbd "<f1> f") 'counsel-describe-function) (global-set-key (kbd "<f1> v") 'counsel-describe-variable) (global-set-key (kbd "<f1> o") 'counsel-describe-symbol) (global-set-key (kbd "<f1> l") 'counsel-find-library) (global-set-key (kbd "<f2> i") 'counsel-info-lookup-symbol) (global-set-key (kbd "<f2> u") 'counsel-unicode-char) (global-set-key (kbd "C-c g") 'counsel-git) (global-set-key (kbd "C-c j") 'counsel-git-grep) (global-set-key (kbd "C-c k") 'counsel-ag) (global-set-key (kbd "C-x l") 'counsel-locate) (global-set-key (kbd "C-S-o") 'counsel-rhythmbox) (define-key minibuffer-local-map (kbd "C-r") 'counsel-minibuffer-history) (custom-set-variables ;; custom-set-variables was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(custom-enabled-themes '(misterioso)) '(package-selected-packages '(use-package company-phpactor phpactor xref-js2 js2-refactor js2-mode php-mode swiper-helm helm-projectile counsel))) (custom-set-faces ;; custom-set-faces was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. ) &#x200B; \`\`\` &#x200B; Would anyone be able to help me figure out if I could make the definition jumps quick? &#x200B; The project I work inside is pretty big, I'm sure that things like phpStorm probably have some sort of indexing going on to make the definition jump so quick there &#x200B; Thanks in advance and sorry if this post is formatted horribly
7890yuiop · 2022-09-08 11:39
I would test performance independently of Emacs to start with, to see whether or not Emacs has anything to do with it. I guess you want this: https://phpactor.readthedocs.io/en/master/reference/indexer.html#querying-from-the-cli Failing anything else, http://ctags.io/ should be fast.
hexmode · 2022-09-08 20:51
You ask about "definition jumps" by which I guess you mean `M-.` or `xref-find-definition`. I've set up lsp with php and intelephense and used it happily. `M-.` has been one of my favorite things. Note that I've just discovered a problem with using projectile instead of project, but dropping projectile for now seems to have fixed it.
BrokenMayo · 2022-09-08 23:21
Just to confirm - you noticed some issues with your M-. Being slow too? And dropping projectile seems to have fixed that? Do you mind sharing your init.el? Sorry to be an utter pain
hexmode · 2022-09-09 00:09
no problem. Let me see if I can get you a minimal setup.
hexmode · 2022-09-09 01:25
I put this in an empty user's `init.el` and it seemed to work after `M-x lsp` in the PHP buffers I opened under my clone of the [symfony repo](https://github.com/symfony/symfony) (which I chose because I didn't already have it and it is relatively common). ``` (require 'package) (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) (package-initialize) (use-package direnv) (use-package flycheck :init (progn (define-fringe-bitmap 'my-flycheck-fringe-indicator (vector #b00000000 #b00000000 #b00000000 #b00000000 #b00000000 #b00000000 #b00000000 #b00011100 #b00111110 #b00111110 #b00111110 #b00011100 #b00000000 #b00000000 #b00000000 #b00000000 #b00000000)) (flycheck-define-error-level 'error :severity 2 :overlay-category 'flycheck-error-overlay :fringe-bitmap 'my-flycheck-fringe-indicator :fringe-face 'flycheck-fringe-error) (flycheck-define-error-level 'warning :severity 1 :overlay-category 'flycheck-warning-overlay :fringe-bitmap 'my-flycheck-fringe-indicator :fringe-face 'flycheck-fringe-warning) (flycheck-define-error-level 'info :severity 0 :overlay-category 'flycheck-info-overlay :fringe-bitmap 'my-flycheck-fringe-indicator :fringe-face 'flycheck-fringe-info)) (global-flycheck-mode)) (use-package bind-key) (use-package magit :bind (("C-x v d" . magit-status)) :init (fset 'vc-dir 'magit-status)) (use-package forge :ensure t :after (magit)) (use-package php-mode :mode (("\\.inc\\'" . php-mode) ("\\.php\\'" . php-mode))) (use-package company :after php-mode :init :config (setq company-idle-delay 0.3) (push 'company-files company-backends) (global-set-key (kbd "M-<tab>") 'company-complete)) (use-package phpunit :after php-mode) (use-package js2-mode :ensure t :mode "\\.js$" :bind (("C-M-S-p" . previous-error) ("C-M-S-n" . next-error))) (use-package lsp-mode :requires company :init (setq read-process-output-max (* 1024 1024) lsp-serenata-server-path (expand-file-name "~/bin/serenata") lsp-keymap-prefix "C-c l") :hook (php-mode . (lambda () (lsp) (direnv-mode))) (lsp-mode . lsp-enable-which-key-integration) :config (push 'company-lsp company-backends) (lsp-register-custom-settings '(("gopls.completeUnimported" t t) ("gopls.staticcheck" t t))) :commands lsp) (use-package lsp-ui :requires (lsp-ui-flycheck lsp-php flycheck) :after lsp-mode :commands lsp-ui-mode :config (setq lsp-ui-doc-enable t lsp-ui-doc-include-signature t lsp-ui-flycheck-list-position 'right lsp-ui-flycheck-live-reporting t lsp-ui-imenu-enable t lsp-ui-peek-enable t lsp-ui-peek-list-width 60 lsp-ui-peek-peek-height 25 lsp-ui-sideline-enable nil lsp-ui-sideline-update-mode 'line lsp-ui-sideline-show-code-actions t lsp-ui-sideline-show-hover nil) :bind (:map lsp-ui-mode-map ("C-c C-j" . lsp-ui-peek-find-definitions) ("C-c i" . lsp-ui-peek-find-implementation) ("C-c m" . lsp-ui-imenu)) :hook (lsp-after-open-hook . (lambda () (lsp-ui-flycheck-list-mode))) (lsp-mode . lsp-ui-mode)) (custom-set-variables ;; custom-set-variables was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(package-selected-packages '(lsp-ui lsp-mode direnv phpunit company php-mode forge magit flycheck use-package cmake-mode))) (custom-set-faces ;; custom-set-faces was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. ) ``` (updated to fix a hook.)
7890yuiop · 2022-09-09 04:40
For lots of readers your message looks like this: https://old.reddit.com/r/emacs/comments/x8wzi9/goto_definition_hangs_for_a_long_time_when_using/ino3l9j/ The only [code block formatting](https://reddithelp.com/hc/en-us/articles/360043033952-Formatting-Guide#wiki_code_blocks_and_inline_code) method which works for *both* old and new reddit is to switch the reddit editor to markdown mode* and indent the code by 4 spaces (you can use `M-4 C-x C-i` on a region followed by `M-x untabify` to achieve this in Emacs); and you need to use empty lines to separate the indented lines from the other text. (* Switching to the markdown editor may or may not still be necessary; it prevented problems in the past, though.)
BrokenMayo · 2022-09-09 09:55
This is absolutely perfect, I've done some tinkering &#x200B; I've been trying to figure out how I can have this work without having too execute lsp every time I open a file, do you know how I could achieve that one too? Edit: I've figured this out By adding :config (lsp) to php-mode in the use-package expression THanks a bunch :)
hexmode · 2022-09-09 13:37
I'm surprised `:config (lsp)` works because I thought `:config` was only executed the first time `php-mode` is loaded. In any case, I forgot to fix up the hook for `php-mode` and that is probably why you have to run lsp each time. Try this hook there: ``` :hook (php-mode . (lambda () (lsp) (direnv-mode))) ```
BrokenMayo · 2022-09-09 13:38
Thank you I didn’t look too deeply into it I think it could be because php-mode is maybe loaded on a per buffer basis? I have no idea, still getting to grips - thanks for all of your assistance here :)
BrokenMayo · 2022-09-13 13:30
>php-mode I didn't realise that you'd updated this After spending time reading the use package docs today (and reading elisp manuals), I'd come to type out this exact hook to tell you about it! - Thanks again :)