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

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

[nongnu] elpa/haskell-tng-mode 103e758 325/385: expose some more hsinspe


From: ELPA Syncer
Subject: [nongnu] elpa/haskell-tng-mode 103e758 325/385: expose some more hsinspect-0.0.8 index info
Date: Tue, 5 Oct 2021 23:59:57 -0400 (EDT)

branch: elpa/haskell-tng-mode
commit 103e75875b37f4358b74a192166f3d970000f6c3
Author: Tseen She <ts33n.sh3@gmail.com>
Commit: Tseen She <ts33n.sh3@gmail.com>

    expose some more hsinspect-0.0.8 index info
---
 haskell-tng-hsinspect.el           | 34 ++++++++++++++++++++++++++--------
 test/haskell-tng-hsinspect-test.el | 34 ++++++++++++++++++++++++++++++----
 2 files changed, 56 insertions(+), 12 deletions(-)

diff --git a/haskell-tng-hsinspect.el b/haskell-tng-hsinspect.el
index 6d50f03..f2fb3c0 100644
--- a/haskell-tng-hsinspect.el
+++ b/haskell-tng-hsinspect.el
@@ -61,15 +61,18 @@ A prefix argument ensures that caches are flushes."
                (sym (match-string 2 sym)))
           ;; FIXME types and data constructors
           (when-let (hit (haskell-tng--hsinspect-import-popup index sym))
-            (haskell-tng--import-symbol (car hit) fqn)))
+            (haskell-tng--import-symbol (alist-get 'module hit) fqn)))
       (when-let (hit (haskell-tng--hsinspect-import-popup index sym))
         ;; TODO add parens around operators
         ;; TODO add the type around data constructors (requires hsinspect 
changes)
-        (haskell-tng--import-symbol (car hit) nil (cdr hit))))))
+        (haskell-tng--import-symbol (alist-get 'module hit) nil (alist-get 
'name hit))))))
 
 ;; TODO expand out pattern matches (function defns and cases) based on the cons
 ;; for a type obtained from the Index.
 
+;; TODO expand out wildcards in pattern matches. We can calculate the type by
+;; looking at the names of the other data constructors that have been used.
+
 (defun haskell-tng--hsinspect-qualify (imports sym)
   (cdar
    (last
@@ -80,17 +83,20 @@ A prefix argument ensures that caches are flushes."
 (defun haskell-tng--hsinspect-import-popup (index sym)
   (when-let ((hits (haskell-tng--hsinspect-import-candidates index sym)))
     ;; TODO special case one hit
-    (when-let* ((entries (mapcar 'car hits)) ;; TODO include function name
+    ;; TODO show more context, like the type
+    (when-let* ((entries (mapcar (lambda (el) (alist-get 'module el)) hits))
                 (selected (popup-menu* entries)))
-      (seq-find (lambda (el) (equal (car el) selected)) hits))))
+      (seq-find (lambda (el) (equal (alist-get 'module el) selected)) hits))))
 
 (defun haskell-tng--hsinspect-import-candidates (index sym)
-  "Return a list of (module . symbol)"
+  "Return an list of alists with keys: unitid, module, name, type.
+When using hsinspect-0.0.8, also: class, export, flavour."
   ;; TODO threading/do syntax
   ;; TODO alist variable binding like RecordWildcards
   (seq-mapcat
    (lambda (pkg-entry)
-     (let ((modules (alist-get 'modules pkg-entry)))
+     (let ((unitid (alist-get 'unitid pkg-entry))
+           (modules (alist-get 'modules pkg-entry)))
        (seq-mapcat
         (lambda (module-entry)
           (let ((module (alist-get 'module module-entry))
@@ -98,8 +104,20 @@ A prefix argument ensures that caches are flushes."
             ;;(message "MODULE= %s" module)
             (seq-mapcat
              (lambda (entry)
-               (let ((name (alist-get 'name entry)))
-                 (when (equal name sym) `(,(cons module name)))))
+               (let ((name (alist-get 'name entry))
+                     (type (alist-get 'type entry))
+                     (class (alist-get 'class entry))
+                     (export (alist-get 'export entry))
+                     (flavour (alist-get 'flavour entry)))
+                 (when (equal name sym)
+                   ;; TODO add the hsinspect-0.0.8 bits
+                   `(((unitid . ,unitid)
+                      (module . ,module)
+                      (name . ,name)
+                      (type . ,type)
+                      (class . ,class)
+                      (export . ,export)
+                      (flavour . ,flavour))))))
              ids)))
         modules)))
    index))
diff --git a/test/haskell-tng-hsinspect-test.el 
b/test/haskell-tng-hsinspect-test.el
index 3bbccac..37aca5a 100644
--- a/test/haskell-tng-hsinspect-test.el
+++ b/test/haskell-tng-hsinspect-test.el
@@ -41,15 +41,41 @@
     (should
      (equal
       (haskell-tng--hsinspect-import-candidates index "throw")
-      '(("Control.Exception.Base" . "throw")
-        ("Control.Exception" . "throw")
-        ("GHC.Exception" . "throw"))))
+      '(((unitid . "base")
+         (module . "Control.Exception.Base")
+         (name . "throw")
+         (type . "forall a e. Exception e => e -> a")
+         (class . id)
+         (export (unitid . "base")
+                 (module . "GHC.Exception"))
+         (flavour))
+        ((unitid . "base")
+         (module . "Control.Exception")
+         (name . "throw")
+         (type . "forall a e. Exception e => e -> a")
+         (class . id)
+         (export (unitid . "base")
+                 (module . "GHC.Exception"))
+         (flavour))
+        ((unitid . "base")
+         (module . "GHC.Exception")
+         (name . "throw")
+         (type . "forall a e. Exception e => e -> a")
+         (class . id)
+         (export)
+         (flavour)))))
 
     ;; operator search
     (should
      (equal
       (haskell-tng--hsinspect-import-candidates index ">$<")
-      '(("Data.Functor.Contravariant" . ">$<"))))
+      '(((unitid . "base")
+         (module . "Data.Functor.Contravariant")
+         (name . ">$<")
+         (type . "forall (f :: * -> *) a b. Contravariant f => (a -> b) -> f b 
-> f a")
+         (class . id)
+         (export)
+         (flavour)))))
 
     ;; TODO type search
     ;; TODO constructor search



reply via email to

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