mirror of
https://github.com/vale981/emacs-ipython-notebook
synced 2025-03-04 16:51:38 -05:00
ein-company: Function annotations via oinfo db
As ein builds completions for company it will build a database of object-info data that can later be used for function annotations.
This commit is contained in:
parent
8b7f26d668
commit
7320c16b47
3 changed files with 29 additions and 45 deletions
15
.gitignore
vendored
15
.gitignore
vendored
|
@ -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
|
||||
tests/notebook
|
||||
*.log
|
||||
log/*
|
||||
_images
|
||||
_static
|
||||
.travis.yml.swp
|
||||
*.zip
|
||||
.gitattributes
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue