 (require 'cc-cmds)
 (require 'cl-lib)
 (require 'company)
+(require 'deferred)
 (require 'ycmd)
 
 (defconst company-ycmd-completion-properties


(defun company-ycmd-get-candidates (prefix)
  "Candidates-command handler for the company backend."
  (cons :async
        (lambda (cb) (funcall cb (company-ycmd-candidates)))))

(defun company-ycmd-get-match (prefix)
  (point))

    (dolist (prop company-ycmd-completion-properties candidate)
      (put-text-property 0 1 prop (assoc-default prop src) candidate))))

(defun company-ycmd-candidates (cb)
  "Get list of completion candidate strings at point.

The returned strings have annotation, metadata, and other pieces
of information added as text-properties.
"
  (lexical-let ((cb cb))
    (deferred:$
      
      (deferred:try
        (deferred:$
          (if (ycmd-running?)
              (ycmd-get-completions)))
        :catch (lambda (err) nil))
      
      (deferred:nextc it
        (lambda (c)
          (funcall
           cb
           (mapcar 'company-ycmd-construct-candidate
                   (assoc-default 'completions c))))))))

(defun company-ycmd-get-metadata (candidate)
  "Fetch the metadata text-property from a candidate string."
