Function: semantic-collector-calculate-completions

semantic-collector-calculate-completions is a byte-compiled function defined in complete.el.gz.

Signature

(semantic-collector-calculate-completions ARG &rest ARGS)

Implementations

((obj semantic-collector-abstract) prefix partial) in `semantic/complete.el'.

Calculate completions for prefix as setup for other queries.

Source Code

;; Defined in /usr/src/emacs/lisp/cedet/semantic/complete.el.gz
(cl-defmethod semantic-collector-calculate-completions
  ((obj semantic-collector-abstract) prefix _partial)
  "Calculate completions for prefix as setup for other queries."
  (let* ((case-fold-search semantic-case-fold)
	 (same-prefix-p (semantic-collector-last-prefix= obj prefix))
	 (last-prefix (and (slot-boundp obj 'last-prefix)
			   (oref obj last-prefix)))
	 (completionlist
	  (cond ((or same-prefix-p
		     (and last-prefix (eq (compare-strings
					   last-prefix 0 nil
					   prefix 0 (length last-prefix))
					  t)))
		 ;; We have the same prefix, or last-prefix is a
		 ;; substring of the of new prefix, in which case we are
		 ;; refining our symbol so just re-use cache.
		 (oref obj last-all-completions))
		((and last-prefix
		      (> (length prefix) 1)
		      (eq (compare-strings
			   prefix 0 nil
			   last-prefix 0 (length prefix))
			  t))
		   ;; The new prefix is a substring of the old
		   ;; prefix, and it's longer than one character.
		   ;; Perform a full search to pull in additional
		   ;; matches.
		 (let ((context (semantic-analyze-current-context (point))))
		   ;; Set new context and make first-pass-completions
		   ;; unbound so that they are newly calculated.
		   (oset obj context context)
		   (when (slot-boundp obj 'first-pass-completions)
		     (slot-makeunbound obj 'first-pass-completions)))
		 nil)))
	 ;; Get the result
	 (answer (if same-prefix-p
		     completionlist
		   (semantic-collector-calculate-completions-raw
		    obj prefix completionlist)))
	 (completion nil)
	 (complete-not-uniq nil)
	 )
    ;;(semanticdb-find-result-test answer)
    (when (not same-prefix-p)
      ;; Save results if it is interesting and beneficial
      (oset obj last-prefix prefix)
      (oset obj last-all-completions answer))
    ;; Now calculate the completion.
    (setq completion (try-completion
		      prefix
		      (semanticdb-strip-find-results answer)))
    (oset obj last-whitespace-completion nil)
    (oset obj current-exact-match nil)
    ;; Only do this if a completion was found.  Letting a nil in
    ;; could cause a full semanticdb search by accident.
    (when completion
      (oset obj last-completion
	    (cond
	     ;; Unique match in AC.  Last completion is a match.
	     ;; Also set the current-exact-match.
	     ((eq completion t)
	      (oset obj current-exact-match answer)
	      prefix)
	     ;; It may be complete (a symbol) but still not unique.
	     ;; We can capture a match
	     ((setq complete-not-uniq
		    (semanticdb-find-tags-by-name
		     prefix
		     answer))
	      (oset obj current-exact-match
		    complete-not-uniq)
	      prefix
	      )
	     ;; Non unique match, return the string that handles
	     ;; completion
	     (t (or completion prefix))
	     )))
    ))