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

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

[elpa] externals/hcel a58ea9ffa8 2/3: initial version of integration wit


From: ELPA Syncer
Subject: [elpa] externals/hcel a58ea9ffa8 2/3: initial version of integration with help mode.
Date: Wed, 28 Sep 2022 08:57:42 -0400 (EDT)

branch: externals/hcel
commit a58ea9ffa8cf563bfd7b30db5f3c6b55cf89f632
Author: Yuchen Pei <hi@ypei.me>
Commit: Yuchen Pei <hi@ypei.me>

    initial version of integration with help mode.
---
 hcel-results.el | 118 +++++++++++++++++++++++++++++++++++---------------------
 1 file changed, 74 insertions(+), 44 deletions(-)

diff --git a/hcel-results.el b/hcel-results.el
index be8e6cb9cd..d3e2325f1c 100644
--- a/hcel-results.el
+++ b/hcel-results.el
@@ -268,28 +268,40 @@ Start by choosing a package."
                     hcel-results-max-page-number))
     (mapc
      (lambda (result)
-       (let* ((location-info (alist-get 'locationInfo result))
-              (doc (hcel-render-html
-                    (or (alist-get 'doc result)
-                        (alist-get 'documentation
-                                   (ignore-errors
-                                     (hcel-definition-site-location-info
-                                      location-info)))))))
-         (insert "--\n")
-         (insert (propertize
-                  (format "%s :: %s\n"
-                          (alist-get 'demangledOccName result)
-                          (hcel-render-id-type (alist-get 'idType result)))
-                  'location-info location-info
-                  'match-line t))
-         (insert (format "Defined in %s %s\n"
-                         (hcel-format-package-id
-                          (alist-get 'packageId location-info) "-")
-                         (alist-get 'modulePath location-info)))
-         (when doc (insert doc))))
+       (insert "--\n")
+       (insert (hcel-ids-render-result result)))
      (alist-get 'json results))
     (goto-char (point-min))))
 
+(defun hcel-ids-render-result (result)
+  (let* ((location-info (alist-get 'locationInfo result))
+         (doc (hcel-render-html
+               (or (alist-get 'doc result)
+                   (alist-get 'documentation
+                              (ignore-errors
+                                (hcel-definition-site-location-info
+                                 location-info)))))))
+    ;; TODO: remove
+    ;; (print (with-temp-buffer
+    ;;          (insert (alist-get 'doc result))
+    ;;          (libxml-parse-html-region (point-min) (point-max))))
+    (concat
+     (propertize
+      (format "%s :: %s\n"
+              (alist-get 'demangledOccName result)
+              (hcel-render-id-type (alist-get 'idType result)))
+      'location-info location-info
+      'match-line t)
+     (concat "Defined in "
+             (button-buttonize
+              (format "%s %s"
+                      (hcel-format-package-id
+                       (alist-get 'packageId location-info) "-")
+                      (alist-get 'modulePath location-info))
+              (lambda (&rest _) (hcel-load-module-location-info 
location-info)))
+             "\n")
+     (when doc (concat "\n" doc)))))
+
 (defun hcel-ids-reload ()
   (interactive)
   (hcel-ids-update))
@@ -319,29 +331,35 @@ Start by choosing a package."
 ;; Caching results to prevent to many hits
 (defvar hcel-ids--minibuffer-saved-query nil)
 (defvar hcel-ids--minibuffer-saved-results nil)
+(defvar hcel-ids--minibuffer-selected nil)
 
 (defun hcel-ids--affixation-internal (scope items)
-  (mapcar
-   (lambda (item)
-     (let* ((location-info (get-text-property 0 'location-info item))
-           (suffix
-            (propertize 
-             (format
-              " :: %s"
-              (hcel-render-components (get-text-property 0 'components item)))
-             'face 'completions-annotations))
-           (prefix
-            (propertize
-             (if (eq scope 'global)
-                 (format "(%s %s) "
-                         (alist-get 'moduleName location-info)
-                         (hcel-format-package-id
-                          (alist-get 'packageId location-info) "-"))
-                 (format "(%s) "
-                         (alist-get 'moduleName location-info)))
-             'face 'completions-annotations)))
-       (list (car (split-string item " ")) prefix suffix)))
-   items))
+  (let ((results
+         (mapcar
+          (lambda (item)
+            (let* ((info (get-text-property 0 'info item))
+                   (location-info (alist-get 'locationInfo info))
+                   (suffix
+                    (propertize 
+                     (format
+                      " :: %s"
+                      (hcel-render-components
+                       (alist-get 'components (alist-get 'idType info))))
+                     'face 'completions-annotations))
+                   (prefix
+                    (propertize
+                     (if (eq scope 'global)
+                         (format "(%s %s) "
+                                 (alist-get 'moduleName location-info)
+                                 (hcel-format-package-id
+                                  (alist-get 'packageId location-info) "-"))
+                       (format "(%s) "
+                               (alist-get 'moduleName location-info)))
+                     'face 'completions-annotations)))
+              (list (car (split-string item " ")) prefix suffix)))
+          items)))
+    (setq hcel-ids--minibuffer-selected (car (car results)))
+    results))
 
 (defun hcel-ids--affixation-function (scope)
   (lambda (items)
@@ -364,6 +382,7 @@ Start by choosing a package."
                   (format "%s %s"
                           (alist-get 'demangledOccName result)
                           (alist-get 'externalId result))
+                  'info result
                   'location-info (alist-get 'locationInfo result)
                   'components (alist-get 'components
                                          (alist-get 'idType result))))
@@ -372,8 +391,6 @@ Start by choosing a package."
                 (number-to-string hcel-ids-live-per-page))))
         hcel-ids--minibuffer-saved-results))))
 
-(defvar hcel-ids-selected-ids-location-info nil)
-
 (defun hcel-global-ids-minibuffer-collection (query pred action)
   (hcel-ids-minibuffer-collection 'global query action))
 
@@ -382,11 +399,12 @@ Start by choosing a package."
     (hcel-ids-minibuffer-collection 'package query action package-id)))
 
 (defun hcel-ids (scope query &optional package-id)
+  ;; FIXME: hacky way to detecting completion.
   (let ((splitted (split-string query " ")))
     (if (length= splitted 2)
         (hcel-load-module-location-info
-         (alist-get 'location
-                    (hcel-definition-site-external-id (cadr splitted))))
+         (alist-get 'locationInfo
+                    (get-text-property 0 'info hcel-ids--minibuffer-selected)))
       (let ((buffer-name (hcel-ids-buffer-name scope query)))
         (with-current-buffer (get-buffer-create buffer-name)
           (hcel-ids-mode)
@@ -416,5 +434,17 @@ Start by choosing a package."
   (hcel-ids 'package query hcel-package-id))
 (define-key hcel-mode-map "i" #'hcel-package-ids)
 
+(defun hcel-help (query)
+  (interactive
+   (list
+    (let ((minibuffer-allow-text-properties t))
+      (completing-read "Find help for identifier: "
+                       #'hcel-global-ids-minibuffer-collection))))
+  (when (length= (split-string query " ") 2)
+    (with-help-window "*hcel-help*"
+      (with-current-buffer standard-output
+        (insert (hcel-ids-render-result
+                (get-text-property 0 'info hcel-ids--minibuffer-selected)))))))
+
 (provide 'hcel-results)
 ;;; hcel-results.el ends here.



reply via email to

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