 
 (defun candidate-documentation (candidate)
   (get-pos-property 0 'value candidate))
-
-(defvar *my-candidate* nil)
 
 (defun pjs-local-vars-action ()
   (message (candidate-documentation candidate)))

	  (setq *current-pjs-namespace-prefix* (downcase (match-string-no-properties 1)))
	  (1+ (match-beginning 2)))))))

(defun pjs-namespaces-functions-ac-action ()  
  )

(defun pjs-namespaces-functions-ac-candidates ()
  (let ((functions (list-pjs-namespace-functions *current-pjs-namespace-prefix*))
	(vars      (list-pjs-namespace-variables *current-pjs-namespace-prefix*)))
    (append functions vars)))

(defun pjs-namespaces-functions-ac-document (docstr)
  docstr)

;;; find functions from current namespaces.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(ac-define-source "pjs-current-namespace-functions"
  '((candidates . pjs-current-namespace-functions-ac-candidates)
;;    (document . pjs-namespaces-functions-ac-document)
    ;;    (action . pjs-namespaces-functions-ac-action)
    (symbol . "f ")
    (requires . -1)))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(ac-define-source "pjs-variable-members"
  '(;;(prefix . pjs-variable-members-ac-prefix)
    (candidates . pjs-variable-members-ac-candidates)
    (symbol . "m ")
    (requires . -1)))

;;(defvar *current-pjs-variable* nil)

;; (defun pjs-variable-members-ac-prefix ()
;;   ;; detects the current namespace
;;   (save-excursion
;;     (save-match-data
;;       (let ((match (re-search-backward (format "\\(\\<%s\\>\\)\\([.]\\)\\(%s\\)?\\=" *js-variable-name* *js-variable-name*) (line-beginning-position) t)))	
;; 	(when match
;; 	  (1+ (setq *current-pjs-variable* (match-beginning 2))))))))

(defun pjs-variable-members-ac-candidates ()
  ;; get the type of the variable
  (let ((variable (save-excursion
		    (save-match-data
		      (let ((match (re-search-backward (format "\\(\\<%s\\>\\)\\([.]\\)\\(%s\\)?\\=" *js-variable-name* *js-variable-name*) (line-beginning-position) t)))	
			(when match
			  (1+ (setq *current-pjs-variable* (match-beginning 2)))))))))
    (when variable
      (let ((var-type (get-variable-type-in-context variable))
	    res)
	(when var-type
	  (let* ((members (pjs-class-members (car var-type) (cdr var-type)))
		 (res (pjs-class-methods (car var-type) (cdr var-type))))
	    (maphash #'(lambda (k v)
			 (push k res)) members)
	    res))))))

;;; find locally defined variables
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
