branch: externals/phpinspect commit cfc2891672431b000f15f581d54b29faf0a87797 Author: Hugo Thunnissen <de...@hugot.nl> Commit: Hugo Thunnissen <de...@hugot.nl>
WIP --- phpinspect-buffer.el | 4 ++-- phpinspect-completion.el | 42 ++++++++++++++++++++++++++++++++++++++++-- phpinspect-eldoc.el | 3 +-- phpinspect-thread.el | 27 +++++---------------------- 4 files changed, 48 insertions(+), 28 deletions(-) diff --git a/phpinspect-buffer.el b/phpinspect-buffer.el index 97e2ab3e14..caaab766d0 100644 --- a/phpinspect-buffer.el +++ b/phpinspect-buffer.el @@ -900,7 +900,7 @@ indexation")) (eq (phpi-condition-value (phpi-shadow--synced-change shadow)) (phpi-condition-value (phpi-shadow--last-change shadow)))) -(defun phpi-shadow-await-synced (shadow &optional allow-interrupt) +(defun phpi-shadow-await-synced (shadow &optional _allow-interrupt) (phpi-shadow-assert-live-p shadow) (unless (phpi-shadow-is-me-p shadow) (phpi-condition-wait (phpi-shadow--synced-change shadow) @@ -910,7 +910,7 @@ indexation")) (phpi-condition-value (phpi-shadow--last-change shadow)))))))) ;; (phpi-shadow-await-predicate shadow #'phpi-shadow-synced-p allow-interrupt)) -(defun phpi-shadow-await-index-synced (shadow &optional allow-interrupt) +(defun phpi-shadow-await-index-synced (shadow &optional _allow-interrupt) (phpi-shadow-assert-live-p shadow) ;; First wait for last change to be synced diff --git a/phpinspect-completion.el b/phpinspect-completion.el index 5bdeedbf6a..ea70f752f0 100644 --- a/phpinspect-completion.el +++ b/phpinspect-completion.el @@ -332,7 +332,8 @@ Returns list of `phpinspect--completion'." (dolist (strategy phpinspect-completion-strategies) (when-let (region (phpinspect-comp-strategy-supports strategy query rctx)) ;; Check if using the cached completion list is possible. - (if-let ((maybe-cache?) + (if-let ((nil) + (maybe-cache?) ;; There is a previous list available (last-list phpinspect--last-completion-list) ;; The list had candidates in it @@ -465,7 +466,7 @@ Returns list of `phpinspect--completion'." ('variable "<va> "))))) -(defun phpinspect-complete-at-point () +(defun phpinspect--get-completion-at-point () (catch 'phpinspect-interrupted (let ((comp-list (phpinspect-completion-query-execute (phpinspect--get-completion-query)))) @@ -504,4 +505,41 @@ Returns list of `phpinspect--completion'." (phpinspect--log "Unable to find matching completion for name %s" comp-name) nil)))))))) +(defun phpinspect-complete-at-point () +(let* ((buf (current-buffer)) + result thread + (completion-ready nil) + (start (point)) + (end (point))) + + (setq thread (phpi-run-threaded "completion-at-point" + (with-current-buffer buf + (setq result (phpinspect--get-completion-at-point)) + (setq completion-ready t) + (message "set result")))) + + (message "STARTING WAIT") + (while (thread-live-p thread) + (message "waiting") + (sit-for 0.001)) + + (message "RESULT: %s" completion-ready) + (if completion-ready + (list start end result) + ;; Return a dummy completion table that will pass the try-completion test + (list start end '("") :exclusive 'no))) ) + +;; (let* ((buf (current-buffer)) + ;; result thread) + + ;; (setq thread (phpi-run-threaded "completion-at-point" + ;; (with-current-buffer buf + ;; (setq result (phpinspect--get-completion-at-point))))) + + ;; (while (thread-live-p thread) + ;; (sit-for 0.005)) + + ;; result)) + + (provide 'phpinspect-completion) diff --git a/phpinspect-eldoc.el b/phpinspect-eldoc.el index 5de8576cac..1bec6888bb 100644 --- a/phpinspect-eldoc.el +++ b/phpinspect-eldoc.el @@ -304,9 +304,8 @@ TODO: " (when phpinspect-current-buffer (phpi-run-threaded "PHPInspect Eldoc" - (While-no-input (let ((result (phpinspect--eldoc-function-sync))) - (funcall callback result)))) + (funcall callback result))) 'async)) diff --git a/phpinspect-thread.el b/phpinspect-thread.el index d011e431e9..543b928e47 100644 --- a/phpinspect-thread.el +++ b/phpinspect-thread.el @@ -105,38 +105,21 @@ (define-inline phpi-main-thread-starving-p () (inline-quote (let ((starving (phpi--main-thread-starving-p))) - (when (eq 'yes starving) - (setf (phpi-condition-value phpinspect--main-thread-starving) starving) - t)))) - -(defun phpi-await-main-thread-nourished () - (phpinspect--log "Waiting for the main thread to be nourished") - (when (phpi-main-thread-starving-p) - (while - (eq 'yes (phpi-condition-wait - phpinspect--main-thread-starving))))) + (setf (phpi-condition-value phpinspect--main-thread-starving) starving) + (if (eq 'yes starving) + t + nil)))) (defun phpi-job-queue-end () (signal 'phpinspect-job-queue-end nil)) -(defun phpi--notify-main-thread-nourished () - (setf (phpi-condition-value phpinspect--main-thread-starving) 'no)) - -(defvar phpinspect-main-thread-nourishment 0.01 - "Amount of seconds to pause all threads when input is pending.") - -(defvar phpinspect-main-thread-nourishment-timer - (run-with-idle-timer phpinspect-main-thread-nourishment t #'phpi--notify-main-thread-nourished)) - (define-inline phpi-thread-yield () "Like `thread-yield', but takes extra care not to starve the main thread. If current thread is the main thread, this function does nothing." (inline-quote (unless (eq main-thread (current-thread)) - (if (phpi-main-thread-starving-p) - (phpi-await-main-thread-nourished) - (thread-yield))))) + (thread-yield)))) (defmacro phpi-progn (&rest body) `(prog1