-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Namespaces autocompletion #72
Comments
i not know what you say . show me exmaple please:> |
Thanks for answer. namespace Tests;
class Test {
public function load($id) {
// UserModel namespace is \App\Models\UserModel
// How do I automatically insert "use App\Models\UserModel" to file header?
UserModel::find($id);
}
} |
@firstrow This makes no sense and is a job for the "ac-php" is an autocompleter to find function definitions. "php-mode" is an extension responsible for PHP code formatting etc... Furthermore: Why would you automatically insert "\App\Models\UserModel" when your file is in "namespace Tests"? Trying to guess that is dangerous. It would need some kind of map of the whole filesystem and find that file. Either way this is not a job for ac-php, you can close this @xcwen... It's a job for "php-mode" or for a brand new, different emacs plugin. Not a job for ac-php. Edit: I thought about it again. Here is ONE area where it IS a good idea: Instead of being "automatic" (dangerous), make it manual... Perhaps add a new command such as Also: after you select a class from the popup, ac-php should check a few things, and NOT insert |
@aitte2 yes, popup with matches and manual selection is better option. |
So here is code I came up with. It helps me to save a lot of time. It would be nice to add support for helm/ido also and make custom variable to choose "popup" completion frontend. Can you guys help with this? (defun ac-php-add-use ()
(interactive)
(save-excursion
(ac-php-goto-use)
(end-of-line)
(newline)
;; get rid of leading slash and insert use statement
(insert (format "use %s;" (subseq (ac-php-classes-popup) 1)))))
(defun ac-php-classes-popup ()
(ivy-completing-read "Enter class name: " (ac-php-g--class-map (ac-php-get-tags-data)) nil nil ""))
(defun ac-php-goto-use ()
(interactive)
(xref-push-marker-stack)
(goto-char (point-min))
;; try to find first "namespace" keyword to add new "use"s after it.
(re-search-forward "^namespace [a-zA-Z0-9\].*;$" nil t)
;; find last "use" keyword.
(while (re-search-forward "^use [a-zA-Z0-9\].*;$" nil t)))
(evil-leader/set-key-for-mode 'php-mode "ia" 'ac-php-add-use)
(evil-leader/set-key-for-mode 'php-mode "ig" 'ac-php-goto-use) |
Cool. I have no time to help but I love that you are making progress. Awesome! |
Hi.
Is there any way to search and insert class namespaces, like auto-complete for
use
keyword?The text was updated successfully, but these errors were encountered: