branch: externals/phpinspect commit 1f145665ef5b0bdc594768307c6ebb1a11a0fc7d Author: Hugo Thunnissen <de...@hugot.nl> Commit: Hugo Thunnissen <de...@hugot.nl>
Exclude "return" from resolvecontext subject + count comma at point for eldoc arg number --- phpinspect-eldoc.el | 20 +++++++++----------- phpinspect-resolvecontext.el | 18 ++++++++++++++++-- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/phpinspect-eldoc.el b/phpinspect-eldoc.el index fef7b69d91..bc65c3586d 100644 --- a/phpinspect-eldoc.el +++ b/phpinspect-eldoc.el @@ -40,6 +40,7 @@ (catch 'matched (dolist (strategy phpinspect-eldoc-strategies) (when (phpinspect-eld-strategy-supports strategy query rctx) + (phpinspect--log "Found matching eldoc strategy. Executing...") (throw 'matched (phpinspect-eld-strategy-execute strategy query rctx))))))) (cl-defgeneric phpinspect-eld-strategy-supports (strategy (query phpinspect-eldoc-query) (context phpinspect--resolvecontext)) @@ -85,20 +86,15 @@ be implemented for return values of `phpinspect-eld-strategy-execute'") ;; When our subject is inside a list, it is probably an argument of a ;; function/method call, which is what this strategy provides information for. (or (phpinspect-list-p parent-token) - - ;; When our subject IS a list, we're probably in an empty/incomplete - ;; argument list. - (and (= 1 (length (phpinspect--resolvecontext-subject rctx))) - (phpinspect-list-p - (car (last (phpinspect--resolvecontext-subject rctx))))) - - ;; When the last token in our subject is an incomplete list, we're - ;; probably at the end of the buffer in an unfinished argument list. - (phpinspect-incomplete-list-p + ;; When the last token in our subject is a list, we're either at the end + ;; of a buffer in an incomplete argument list (no closing paren), or in + ;; an empty argument list of a function call. + (phpinspect-list-p (car (last (phpinspect--resolvecontext-subject rctx))))))) (cl-defmethod phpinspect-eld-strategy-execute ((strat phpinspect-eld-function-args) (q phpinspect-eldoc-query) (rctx phpinspect--resolvecontext)) + (phpinspect--log "Executing `phpinspect-eld-function-args' strategy") (let* ((token-map (phpinspect-buffer-parse-map (phpinspect-eldoc-query-buffer q))) (enclosing-token (cadr (phpinspect--resolvecontext-enclosing-tokens rctx))) @@ -107,19 +103,21 @@ be implemented for return values of `phpinspect-eld-strategy-execute'") (phpinspect-eldoc-query-point q))) match-result static arg-list arg-pos) + (phpinspect--log "Eldoc statement is: %s" statement) (when enclosing-token (cond ;; Method call ((setq match-result (phpinspect--match-sequence (last statement 2) :f #'phpinspect-attrib-p :f #'phpinspect-list-p)) + (phpinspect--log "Eldoc context is a method call") (setq arg-list (car (last match-result)) static (phpinspect-static-attrib-p (car match-result)) arg-pos (seq-reduce (lambda (count token) (if (and (phpinspect-comma-p token) - (> (phpinspect-eldoc-query-point q) + (>= (phpinspect-eldoc-query-point q) (phpinspect-meta-end (phpinspect-bmap-token-meta token-map token)))) (+ count 1) diff --git a/phpinspect-resolvecontext.el b/phpinspect-resolvecontext.el index c6e4382705..526ad4087b 100644 --- a/phpinspect-resolvecontext.el +++ b/phpinspect-resolvecontext.el @@ -55,6 +55,10 @@ (phpinspect-class-p token) (phpinspect-namespace-p token))) +(defsubst phpinspect-return-p (token) + (and (phpinspect-word-p token) + (string= "return" (cadr token)))) + (defun phpinspect-find-statement-before-point (bmap meta point) (let ((children (reverse (cdr (phpinspect-meta-token meta))))) (let ((previous-siblings)) @@ -66,7 +70,8 @@ (if (and (not previous-siblings) (phpinspect-blocklike-p (phpinspect-meta-token child))) (progn (throw 'return (phpinspect-find-statement-before-point bmap child point))) - (when (phpinspect-end-of-statement-p (phpinspect-meta-token child)) + (when (or (phpinspect-return-p (phpinspect-meta-token child)) + (phpinspect-end-of-statement-p (phpinspect-meta-token child))) (throw 'return previous-siblings)) (push (phpinspect-meta-token child) previous-siblings))))) previous-siblings)))) @@ -79,7 +84,16 @@ (subject (phpinspect-bmap-last-token-before-point bmap point)) (subject-token) (siblings)) - (phpinspect--log "Last token before point: %s" subject) + (phpinspect--log "Last token before point: %s" (phpinspect-meta-token subject)) + + (let ((next-sibling (car (phpinspect-meta-right-siblings subject)))) + ;; When the right sibling of the last ending token overlaps point, this is + ;; our actual subject. + (when (and next-sibling + (setq next-sibling (phpinspect-bmap-token-meta bmap next-sibling)) + (phpinspect-meta-overlaps-point next-sibling point)) + (setq subject next-sibling))) + ;; Dig down through tokens that can contain statements (catch 'break (while (and subject