 
 (defun company-ycmd--candidates (prefix)
   "Candidates-command handler for the company backend."
-  (cons :async 'company-ycmd--get-candidates))
+  (cons :async (lambda (cb)
+                 (company-ycmd--get-candidates cb prefix))))
 
 (defun company-ycmd--post-completion (arg)
   (let ((params (company-ycmd--params arg)))

    (candidates      (company-ycmd--candidates arg))
    (meta            (company-ycmd--meta arg))
    (annotation      (company-ycmd--annotation arg))
    (no-cache        company-ycmd-enable-fuzzy-matching)
    (sorted          't)
    (post-completion (company-ycmd--post-completion arg))))


(defcustom company-ycmd-enable-fuzzy-matching t
  "When non-nil, use fuzzy matching for completion candidates.

Setting this to nil enables the `company-mode' internal cache
feature."
  :type 'boolean
  :group 'company-ycmd)

(defcustom company-ycmd-no-cache t
  "When non-nil, disable `company-mode' internal caching feature.

When setting this to non-nil, a completion request is sent to
`ycmd' when completion progresses, e.g. the user inserts a new
character."
  :type 'boolean
  :group 'company-ycmd)

(defun company-ycmd--prefix-candidate-p (candidate prefix)
  "Return t if CANDIDATE string begins with PREFIX."
  (let ((insertion-text (assoc-default 'insertion_text candidate))
        (case-fold-search t))
    (equal (string-match (regexp-quote prefix) insertion-text) 0)))

(defun company-ycmd--construct-candidates (completion-vector prefix)
  "Contruct candidates list from COMPLETION-VECTOR.

When `company-ycmd-enable-fuzzy-matching' is nil, check if
candidate starts with PREFIX, whether to include candidate in
candidates list."
  (let ((completion-list (append completion-vector nil))
        (candidates '()))
    (dolist (candidate completion-list (nreverse candidates))
      (let* ((detailed-info (assoc-default 'detailed_info candidate))
             (function-signatures (and (stringp detailed-info)
                                       (s-split "\n" detailed-info t))))
        (when (or company-ycmd-enable-fuzzy-matching
                  (company-ycmd--prefix-candidate-p candidate prefix))
          (if (and company-ycmd-insert-arguments function-signatures)
              (dolist (meta function-signatures)
                (push (company-ycmd--construct-candidate candidate meta)
                      candidates))
            (push (company-ycmd--construct-candidate candidate)
                  candidates)))))))

(defun company-ycmd--construct-candidate (src &optional meta)
  "Converts a ycmd completion structure SRC to a candidate string.
