Skip to content

Commit

Permalink
toggle completion caching whether number of candidates reaches limit
Browse files Browse the repository at this point in the history
if the number of suggested candidates reaches the limit, the desired
candidate might be missing.

If that occurs, caching should not be used when typing more characters
of the completed string, as phpactor will be invoked with a longer
prefix, and have more chances to return the desired candidate.
  • Loading branch information
kermorgant committed Aug 22, 2018
1 parent 705790f commit df34adf
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions company-phpactor.el
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
(require 'company)
(require 'phpactor)

; this should have the same value as phpactor's completion.completor.class.limit value
; by default, phpactor sets this to 100
(defvar company-phpactor--completion-limit 100)
(defvar company-phpactor--ignore-cache nil)

(defun company-phpactor--grab-symbol ()
"If point is at the end of a symbol, return it.
Otherwise, if point is not inside a symbol, return an empty string.
Expand All @@ -53,6 +58,7 @@ Here we create a temporary syntax table in order to add $ to symbols."
(defun company-phpactor--get-candidates ()
"Build a list of candidates with text-properties extracted from phpactor's output."
(let ((suggestions (company-phpactor--get-suggestions)) candidate)
(setq company-phpactor--ignore-cache (= (length suggestions) company-phpactor--completion-limit))
(mapcar
(lambda (suggestion)
(setq candidate (plist-get suggestion :name))
Expand All @@ -77,6 +83,7 @@ Here we create a temporary syntax table in order to add $ to symbols."
(save-restriction
(widen)
(cl-case command
(no-cache company-phpactor--ignore-cache)
(post-completion (company-phpactor--post-completion arg))
(annotation (company-phpactor--annotation arg))
(interactive (company-begin-backend 'company-phpactor))
Expand Down

0 comments on commit df34adf

Please sign in to comment.