@@ -62,10 +62,9 @@ Here we create a temporary syntax table in order to add $ to symbols."
6262 (let ((response (phpactor--rpc " complete" (phpactor--command-argments :source :offset ))))
6363 (plist-get (plist-get (plist-get response :parameters ) :value ) :suggestions )))
6464
65- (defun company-phpactor--get-candidates (&optional suggestions )
66- " Build a list of candidates with text-properties extracted from phpactor's output."
67- (let ((suggestions (or suggestions (company-phpactor--get-suggestions)))
68- candidate)
65+ (defun company-phpactor--get-candidates (suggestions )
66+ " Build a list of candidates with text-properties extracted from phpactor's output `SUGGESTIONS' ."
67+ (let (candidate)
6968 (mapcar
7069 (lambda (suggestion )
7170 (setq candidate (plist-get suggestion :name ))
@@ -88,8 +87,15 @@ Here we create a temporary syntax table in order to add $ to symbols."
8887 (message (concat " " (get-text-property 0 'annotation arg))))
8988
9089(defun company-phpactor--get-candidates-async (callback )
91- " Get completion candidates asynchronously."
92- (funcall callback (company-phpactor--get-candidates)))
90+ " Get completion candidates asynchronously calling `CALLBACK' by Phpactor."
91+ (if (not company-phpactor-request-async)
92+ (funcall callback (company-phpactor--get-candidates (company-phpactor--get-suggestions)))
93+ (phpactor--rpc-async " complete" (phpactor--command-argments :source :offset )
94+ (lambda (proc )
95+ (let* ((response (phpactor--parse-json (process-buffer proc)))
96+ (suggestions
97+ (plist-get (plist-get (plist-get response :parameters ) :value ) :suggestions )))
98+ (funcall callback (company-phpactor--get-candidates suggestions)))))))
9399
94100;;;### autoload
95101(defun company-phpactor (command &optional arg &rest ignored )
@@ -103,9 +109,7 @@ Here we create a temporary syntax table in order to add $ to symbols."
103109 (`annotation (company-phpactor--annotation arg))
104110 (`interactive (company-begin-backend 'company-phpactor ))
105111 (`prefix (company-phpactor--grab-symbol))
106- (`candidates
107- (cons :async (lambda (callback )
108- (company-phpactor--get-candidates-async callback))))))))
112+ (`candidates (cons :async #'company-phpactor--get-candidates-async ))))))
109113
110114(provide 'company-phpactor )
111115; ;; company-phpactor.el ends here
0 commit comments