Skip to content

Commit 1743b35

Browse files
committed
add specific company-phpactor--grab-symbol function
$ symbol has to be present in the prefix in order to match phpactor's suggestions. Thus, we need a specific function to extract this prefix.
1 parent f3b0e3d commit 1743b35

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

company-phpactor.el

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,20 @@
3131
(require 'company)
3232
(require 'phpactor)
3333

34+
(defun company-phpactor--grab-symbol ()
35+
"If point is at the end of a symbol, return it.
36+
Otherwise, if point is not inside a symbol, return an empty string.
37+
Here we create a temporary syntax table in order to add $ to symbols."
38+
(let (($temp-syn-table (make-syntax-table)))
39+
(modify-syntax-entry ?\$ "_" $temp-syn-table)
40+
41+
(with-syntax-table $temp-syn-table
42+
(if (looking-at "\\_>")
43+
(buffer-substring (point) (save-excursion (skip-syntax-backward "w_")
44+
(point)))
45+
(unless (and (char-after) (memq (char-syntax (char-after)) '(?w ?_)))
46+
"")))))
47+
3448
(defun company-phpactor--get-suggestions ()
3549
"Get completions for current cursor."
3650
(let ((response (phpactor--rpc "complete" (phpactor--command-argments :source :offset))))
@@ -42,8 +56,8 @@
4256
(interactive (list 'interactive))
4357
(cl-case command
4458
(interactive (company-begin-backend 'company-phpactor))
45-
(prefix (company-grab-symbol))
46-
(candidates (all-completions arg (mapcar #'(lambda (suggestion) (plist-get suggestion :name)) (company-phpactor--get-suggestions))))))
59+
(prefix (company-phpactor--grab-symbol))
60+
(candidates (all-completions (substring-no-properties arg) (mapcar #'(lambda (suggestion) (plist-get suggestion :name)) (company-phpactor--get-suggestions))))))
4761

4862
(provide 'company-phpactor)
4963
;;; company-phpactor.el ends here

0 commit comments

Comments
 (0)