Function: semantic-analyze-possible-completions-default
semantic-analyze-possible-completions-default is a byte-compiled
function defined in complete.el.gz.
Signature
(semantic-analyze-possible-completions-default CONTEXT &optional FLAGS)
Documentation
Default method for producing smart completions.
Argument CONTEXT is an object specifying the locally derived context.
The optional argument FLAGS changes which return options are returned.
FLAGS can be any number of:
no-tc - do not apply data-type constraint.
no-longprefix - ignore long multi-symbol prefixes.
no-unique - do not apply unique by name filtering.
Source Code
;; Defined in /usr/src/emacs/lisp/cedet/semantic/analyze/complete.el.gz
(defun semantic-analyze-possible-completions-default (context &optional flags)
"Default method for producing smart completions.
Argument CONTEXT is an object specifying the locally derived context.
The optional argument FLAGS changes which return options are returned.
FLAGS can be any number of:
`no-tc' - do not apply data-type constraint.
`no-longprefix' - ignore long multi-symbol prefixes.
`no-unique' - do not apply unique by name filtering."
(let* ((a context)
(desired-type (semantic-analyze-type-constraint a))
(desired-class (oref a prefixclass))
(prefix (oref a prefix))
(semantic--prefixtypes (oref a prefixtypes))
(completetext nil)
(completetexttype nil)
(scope (oref a scope))
(localvar (when scope (oref scope localvar)))
(origc nil)
(c nil)
;; (any nil)
(do-typeconstraint (not (memq 'no-tc flags)))
(do-longprefix (not (memq 'no-longprefix flags)))
(do-unique (not (memq 'no-unique flags)))
)
(when (not do-longprefix)
;; If we are not doing the long prefix, shorten all the key
;; elements.
(setq prefix (list (car (reverse prefix)))
semantic--prefixtypes nil))
;; Calculate what our prefix string is so that we can
;; find all our matching text.
(setq completetext (car (reverse prefix)))
(if (semantic-tag-p completetext)
(setq completetext (semantic-tag-name completetext)))
(if (and (not completetext) (not desired-type))
(error "Nothing to complete"))
(if (not completetext) (setq completetext ""))
;; This better be a reasonable type, or we should fry it.
;; The prefixtypes should always be at least 1 less than
;; the prefix since the type is never looked up for the last
;; item when calculating a sequence.
(setq completetexttype (car (reverse semantic--prefixtypes)))
(when (or (not completetexttype)
(not (and (semantic-tag-p completetexttype)
(eq (semantic-tag-class completetexttype) 'type))))
;; What should I do here? I think this is an error condition.
(setq completetexttype nil)
;; If we had something that was a completetexttype but it wasn't
;; valid, then express our dismay!
(when (> (length prefix) 1)
(let* ((errprefix (car (cdr (reverse prefix)))))
(error "Cannot find types for `%s'"
(cond ((semantic-tag-p errprefix)
(semantic-format-tag-prototype errprefix))
(t
(format "%S" errprefix)))))
))
;; There are many places to get our completion stream for.
;; Here we go.
(if completetexttype
(setq c (semantic-find-tags-for-completion
completetext
(semantic-analyze-scoped-type-parts completetexttype scope)
))
;; No type based on the completetext. This is a free-range
;; var or function. We need to expand our search beyond this
;; scope into semanticdb, etc.
(setq c (nconc
;; Argument list and local variables
(semantic-find-tags-for-completion completetext localvar)
;; The current scope
(semantic-find-tags-for-completion completetext (when scope (oref scope fullscope)))
;; The world
(semantic-analyze-find-tags-by-prefix completetext))
)
)
(let ((loopc c)
(dtname (semantic-tag-name desired-type)))
;; Save off our first batch of completions
(setq origc c)
;; Reset c.
(setq c nil)
;; Loop over all the found matches, and categorize them
;; as being possible features.
(while (and loopc do-typeconstraint)
(cond
;; Strip operators
((semantic-tag-get-attribute (car loopc) :operator-flag)
nil
)
;; If we are completing from within some prefix,
;; then we want to exclude constructors and destructors
((and completetexttype
(or (semantic-tag-get-attribute (car loopc) :constructor-flag)
(semantic-tag-get-attribute (car loopc) :destructor-flag)))
nil
)
;; If there is a desired type, we need a pair of restrictions
(desired-type
(cond
;; Ok, we now have a completion list based on the text we found
;; we want to complete on. Now filter that stream against the
;; type we want to search for.
((string= dtname (semantic-analyze-type-to-name (semantic-tag-type (car loopc))))
(setq c (cons (car loopc) c))
)
;; Now anything that is a compound type which could contain
;; additional things which are of the desired type
((semantic-tag-type (car loopc))
(let ((att (semantic-analyze-tag-type (car loopc) scope))
)
(if (and att (semantic-tag-type-members att))
(setq c (cons (car loopc) c))))
)
) ; cond
); desired type
;; No desired type, no other restrictions. Just add.
(t
(setq c (cons (car loopc) c)))
); cond
(setq loopc (cdr loopc)))
(when desired-type
;; Some types, like the enum in C, have special constant values that
;; we could complete with. Thus, if the target is an enum, we can
;; find possible symbol values to fill in that value.
(let ((constants
(semantic-analyze-type-constants desired-type)))
(if constants
(progn
;; Filter
(setq constants
(semantic-find-tags-for-completion
completetext constants))
;; Add to the list
(setq c (nconc c constants)))
)))
)
(when desired-class
(setq c (semantic-analyze-tags-of-class-list c desired-class)))
(if do-unique
(if c
;; Pull out trash.
;; NOTE TO SELF: Is this too slow?
(setq c (semantic-unique-tag-table-by-name c))
(setq c (semantic-unique-tag-table-by-name origc)))
(when (not c)
(setq c origc)))
;; All done!
c))