emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/phpinspect 6c767fc877 089/126: Implement eldoc for obje


From: ELPA Syncer
Subject: [elpa] externals/phpinspect 6c767fc877 089/126: Implement eldoc for object attributes
Date: Sat, 12 Aug 2023 00:58:47 -0400 (EDT)

branch: externals/phpinspect
commit 6c767fc877bd2dcb156fd5793f72479bbf70c73c
Author: Hugo Thunnissen <devel@hugot.nl>
Commit: Hugo Thunnissen <devel@hugot.nl>

    Implement eldoc for object attributes
---
 phpinspect-class.el |  2 +-
 phpinspect-eldoc.el | 67 +++++++++++++++++++++++++++++++++++++++--------------
 phpinspect-type.el  |  5 ++++
 phpinspect-util.el  |  2 +-
 4 files changed, 57 insertions(+), 19 deletions(-)

diff --git a/phpinspect-class.el b/phpinspect-class.el
index 7d756cd56c..923e5df510 100644
--- a/phpinspect-class.el
+++ b/phpinspect-class.el
@@ -97,7 +97,7 @@
 
   (phpinspect--class-trigger-update class))
 
-(cl-defmethod phpinspect--class-get-method ((class phpinspect--class) 
method-name)
+(cl-defmethod phpinspect--class-get-method ((class phpinspect--class) 
(method-name symbol))
   (gethash method-name (phpinspect--class-methods class)))
 
 (cl-defmethod phpinspect--class-get-static-method ((class phpinspect--class) 
(method-name symbol))
diff --git a/phpinspect-eldoc.el b/phpinspect-eldoc.el
index 26d82b6ab5..3e8ac35d26 100644
--- a/phpinspect-eldoc.el
+++ b/phpinspect-eldoc.el
@@ -62,20 +62,42 @@ be implemented for return values of 
`phpinspect-eld-strategy-execute'")
   ((strat phpinspect-eld-attribute) (q phpinspect-eldoc-query) (rctx 
phpinspect--resolvecontext))
   (phpinspect-attrib-p (car (last (phpinspect--resolvecontext-subject rctx)))))
 
-;; (cl-defmethod phpinspect-eld-strategy-execute
-;;   ((strat phpinspect-eld-attribute) (q phpinspect-eldoc-query) (rctx 
phpinspect--resolvecontext))
-;;   (let ((attrib (car (last (phpinspect--resolvecontext-subject rctx))))
-;;         type-before)
-;;     (setf (phpinspect--resolvecontext-subject rctx) (butlast 
(phpinspect--resolvecontext-subject rctx)))
-;;     (setq type-before (phpinspect-resolve-type-from-context rctx))
-
-;;     (when type-before
-;;       (let ((class (phpinspect-project-get-class-create
-;;                     (phpinspect--resolvecontext-project rctx)
-;;                     type-before))
-;;             attribute)
-;;         (cond ((phpinspect-static-attrib-p attrib)
-;;                (setq attribute (or (phpinspect--class-get-variable
+(cl-defmethod phpinspect-eld-strategy-execute
+  ((strat phpinspect-eld-attribute) (q phpinspect-eldoc-query) (rctx 
phpinspect--resolvecontext))
+  (let ((attrib (car (last (phpinspect--resolvecontext-subject rctx))))
+        type-before)
+    (setf (phpinspect--resolvecontext-subject rctx) (butlast 
(phpinspect--resolvecontext-subject rctx)))
+    (setq type-before (phpinspect-resolve-type-from-context rctx))
+
+    (when type-before
+      (let ((class (phpinspect-project-get-class-create
+                    (phpinspect--resolvecontext-project rctx)
+                    type-before))
+            (attribute-name (cadadr attrib))
+            variable
+            method
+            result)
+        (cond ((phpinspect-static-attrib-p attrib)
+               (setq variable (phpinspect--class-get-variable class 
attribute-name))
+
+               (if (and variable
+                        (or (phpinspect--variable-static-p variable)
+                            (phpinspect--variable-const-p variable)))
+                   (setq result variable)
+                 (setq method (phpinspect--class-get-static-method
+                               class (phpinspect-intern-name attribute-name)))
+                 (when method
+                   (setq result (phpinspect-make-function-doc :fn method)))))
+              ((phpinspect-object-attrib-p attrib)
+               (setq variable (phpinspect--class-get-variable class 
attribute-name))
+
+               (if (and variable
+                        (phpinspect--variable-vanilla-p variable))
+                   (setq result variable)
+                 (setq method (phpinspect--class-get-method
+                               class (phpinspect-intern-name attribute-name)))
+                 (when method
+                   (setq result (phpinspect-make-function-doc :fn 
method))))))))))
 
 
 (cl-defstruct (phpinspect-eld-function-args (:constructor 
phpinspect-make-eld-function-args))
@@ -143,6 +165,16 @@ be implemented for return values of 
`phpinspect-eld-strategy-execute'")
           (when method
             (phpinspect-make-function-doc :fn method :arg-pos arg-pos))))))))
 
+(cl-defmethod phpinspect-eldoc-string ((var phpinspect--variable))
+  (concat (truncate-string-to-width
+           (propertize (concat (if (phpinspect--variable-vanilla-p var) "$" "")
+                               (phpinspect--variable-name var))
+                       'face 'font-lock-variable-name-face)
+           phpinspect-eldoc-word-width)
+          ": "
+          (propertize (phpinspect--format-type-name (phpinspect--variable-type 
var))
+                      'face 'font-lock-type-face)))
+
 (cl-defstruct (phpinspect-function-doc (:constructor 
phpinspect-make-function-doc))
   (fn nil
       :type phpinspect--function)
@@ -170,10 +202,11 @@ be implemented for return values of 
`phpinspect-eld-strategy-execute'")
               (phpinspect--function-arguments fn)
               ", ")
              "): "
-             (phpinspect--format-type-name
-              (phpinspect--function-return-type fn)))))
+             (propertize
+              (phpinspect--format-type-name (phpinspect--function-return-type 
fn))
+              'face 'font-lock-type-face))))
 
-(defvar phpinspect-eldoc-strategies (list ;;(phpinspect-make-eld-attribute)
+(defvar phpinspect-eldoc-strategies (list (phpinspect-make-eld-attribute)
                                           (phpinspect-make-eld-function-args))
   "The eldoc strategies that phpinspect is currently allowed to
 employ. Strategies are queried in the order of this list. See
diff --git a/phpinspect-type.el b/phpinspect-type.el
index c4d8507391..534c20f8a3 100644
--- a/phpinspect-type.el
+++ b/phpinspect-type.el
@@ -188,6 +188,11 @@ NAMESPACE may be nil, or a string with a namespace FQN."
          type)))))
 
 (cl-defgeneric phpinspect--format-type-name (name)
+  (if name
+      (error "Unexpected value: %s" name)
+    "unknown-type"))
+
+(cl-defmethod phpinspect--format-type-name ((name string))
   (string-remove-prefix "\\" name))
 
 (cl-defmethod phpinspect--format-type-name ((type phpinspect--type))
diff --git a/phpinspect-util.el b/phpinspect-util.el
index d4ca48faaf..5286bb6124 100644
--- a/phpinspect-util.el
+++ b/phpinspect-util.el
@@ -176,7 +176,7 @@ hierarchy as long as no matching files are found.  See also
   "Find first point backwards that could contain any kind of
 context for completion."
   (save-excursion
-    (re-search-backward "[^[:blank:]\n]")
+    (re-search-backward "[^[:blank:]\n]" nil t)
     (forward-char)
     (point)))
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]