diff --git a/.gitignore b/.gitignore index a7de514..4ab8ed0 100644 --- a/.gitignore +++ b/.gitignore @@ -10,19 +10,20 @@ UTF-8-demo.txt *.stackdump *.elc *.el# -lisp/.#ein-notebook.el *.el~ lisp/ein-autoloads.el -tests/func-test-batch-log.log -tests/test-batch-log.log *.py~ *.org~ -lisp/test-batch-log.log *.pyc -test-batch-log.log *.ipynb~ Makefile~ -.ipynb_checkpoints .ipynb_checkpoints/* *.png -tests/notebook \ No newline at end of file +tests/notebook +*.log +log/* +_images +_static +.travis.yml.swp +*.zip +.gitattributes \ No newline at end of file diff --git a/lisp/ein-company.el b/lisp/ein-company.el index 38895e9..240567a 100644 --- a/lisp/ein-company.el +++ b/lisp/ein-company.el @@ -71,6 +71,7 @@ (_ ((&key matches &allow-other-keys) ; :complete_reply _)) replies + (ein:completions--build-oinfo-cache matches) (funcall cb matches))) (defun ein:completions--prepare-matches (cb replies) @@ -78,9 +79,9 @@ ((&key matched_text matches &allow-other-keys) ; :complete_reply _) replies + (ein:completions--build-oinfo-cache matches) (funcall cb matches))) - ;;;###autoload (defun ein:company-backend (command &optional arg &rest _) (interactive (list 'interactive)) @@ -91,11 +92,9 @@ minor-mode-list) (ein:object-at-point))) (annotation (if ein:allow-company-annotations - (ein:aif (gethash arg *ein:pdef-cache*) - it - (cons :async - (lambda (cb) - (ein:completions--get-pdef cb arg)))))) + (ein:aif (gethash arg *ein:oinfo-cache*) + (plist-get it :definition) + ""))) (doc-buffer (lexical-let ((arg arg)) (cons :async (lambda (cb) diff --git a/lisp/ein-completer.el b/lisp/ein-completer.el index a0c928c..7e220b8 100644 --- a/lisp/ein-completer.el +++ b/lisp/ein-completer.el @@ -127,6 +127,7 @@ notebook buffers and connected buffers." ;;; Retrieving Python Object Info +(defvar *ein:oinfo-cache* (make-hash-table :test #'equal)) (defun ein:completions--get-oinfo (obj) (let ((d (deferred:new #'identity)) @@ -137,48 +138,31 @@ notebook buffers and connected buffers." (format "__import__('ein').print_object_info_for(%s)" obj) (list :output (cons (lambda (d &rest args) (deferred:callback-post d args)) - d))) + d))) (deferred:callback-post d (list nil nil))) d)) -(defcustom ein:function-annotation-timeout 500 - "" - :type 'integer - :group 'ein-completion) - -(defvar *ein:pdef-cache* (make-hash-table :test #'equal)) - (defun ein:clear-pdef-cache () (clrhash *ein:pdef-cache*)) -(defun ein:completions--get-pdef (callback obj) - (deferred:$ - (deferred:earlier - (deferred:$ - (deferred:next - (lambda () - (ein:completions--get-oinfo obj)))) - (deferred:$ - (deferred:wait ein:function-annotation-timeout) - (deferred:nextc it - (lambda (_) nil)))) - (deferred:nextc it - (lambda (output) - (ein:completions--prepare-pdef callback output obj))))) +(defun ein:completions--build-oinfo-cache (objs) + (dolist (o objs) + (deferred:$ + (deferred:next + (lambda () + (ein:completions--get-oinfo o))) + (deferred:nextc it + (lambda (output) + (ein:completions--prepare-oinfo output o)))))) -(defun ein:completions--prepare-pdef (callback output obj) - (if output +(defun ein:completions--prepare-oinfo (output obj) + (condition-case _ (destructuring-bind (msg-type content _) output (ein:case-equal msg-type (("stream" "display_data") - (condition-case _ - (let* ((oinfo (ein:json-read-from-string (plist-get content :text))) - (pdef (plist-get oinfo :definition))) - (setf (gethash obj *ein:pdef-cache*) pdef) - (funcall callback pdef)) - (error (funcall callback "")))))) - (setf (gethash obj *ein:pdef-cache*) "") - (funcall callback ""))) + (let* ((oinfo (ein:json-read-from-string (plist-get content :text)))) + (setf (gethash obj *ein:oinfo-cache*) oinfo))))) + (error (setf (gethash obj *ein:oinfo-cache*) "")))) ;;; Support for Eldoc