   "Fetch the metadata text-property from a candidate string."
   (get-text-property 0 'detailed_info candidate))
 
+(defun company-ycmd--params (candidate)
+  (let ((params (get-text-property 0 'menu_text candidate)))
+    (cond
+     ((null params) nil)
+     ((string-match "[^:]:[^:]" params)
+      (substring params (1+ (match-beginning 0))))
+     ((string-match "\\((.*)[ a-z]*\\'\\)" params)
+      (match-string 1 params)))))
+
 (defun company-ycmd--annotation (candidate)
   "Fetch the annotation text-property from a candidate string."
-  (let ((params (get-text-property 0 'menu_text candidate))
-        (type (get-text-property 0 'kind candidate))
+  (let ((type (get-text-property 0 'kind candidate))
         (extra (get-text-property 0 'extra_menu_info candidate)))
-    (concat (unless (zerop (length params))
-              (when (string-match "\(\\(.*\\)\)" params)
-                (match-string 0 params)))
+    (concat (company-ycmd--params candidate)
             (unless (zerop (length type))
               (format " [%s]" (downcase (substring type 0 1))))
             (unless (zerop (length extra))

  "The company-backend command handler for ycmd."
  (interactive (list 'interactive))
  (cl-case command
    (interactive (company-begin-backend 'company-ycmd-backend))
    (prefix      (company-ycmd--prefix))
    (candidates  (company-ycmd--candidates arg))
    (meta        (company-ycmd--meta arg))
    (annotation  (company-ycmd--annotation arg))
    (match       (company-ycmd--match arg))
    (no-cache    't) ; Don't cache. It interferes with fuzzy matching.
    ))

(defun company-ycmd-enable-comprehensive-automatic-completion ()

(require 'cc-cmds)
(require 'cl-lib)
(require 'company)
(require 'company-template)
(require 'deferred)
(require 'ycmd)

