Skip to content

Commit b5ec5f1

Browse files
authored
Merge pull request #29 from kermorgant/variable-completion
add specific company-phpactor--grab-symbol function
2 parents f3b0e3d + 2192a13 commit b5ec5f1

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-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

phpactor.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@
121121
(json-object-type 'plist)
122122
(json-array-type 'list)
123123
(output (get-buffer-create "*Phpactor Output*")))
124+
(with-current-buffer output (erase-buffer))
124125
(with-current-buffer (get-buffer-create "*Phpactor Input*")
125126
(erase-buffer)
126127
(insert json)

0 commit comments

Comments
 (0)