[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/haskell-tng-mode e3c6dc6 336/385: follow re-exports
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/haskell-tng-mode e3c6dc6 336/385: follow re-exports |
Date: |
Tue, 5 Oct 2021 23:59:59 -0400 (EDT) |
branch: elpa/haskell-tng-mode
commit e3c6dc6d92513e4f8014f673d6f472811b7a8771
Author: Tseen She <ts33n.sh3@gmail.com>
Commit: Tseen She <ts33n.sh3@gmail.com>
follow re-exports
---
haskell-tng-hsinspect.el | 68 ++++++++++++++++++++++++++++++++----------------
1 file changed, 46 insertions(+), 22 deletions(-)
diff --git a/haskell-tng-hsinspect.el b/haskell-tng-hsinspect.el
index 37fbf09..339a124 100644
--- a/haskell-tng-hsinspect.el
+++ b/haskell-tng-hsinspect.el
@@ -58,10 +58,12 @@ TODO: support local / git packages by consulting
`plan.json'"
;; TODO imports and index can be calculated in parallel
(sym (haskell-tng--hsinspect-symbol-at-point))
(found (haskell-tng--hsinspect-qualify imports sym))
+ ;; TODO pcase would be better here
(parts (haskell-tng--string-split-last found "."))
- (module (car parts))
(name (cdr parts))
- (srcid (haskell-tng--hsinspect-find-srcid index module))
+ (followed (haskell-tng--hsinspect-follow index nil (car parts)
name))
+ (srcid (car followed))
+ (module (cdr followed))
(tarball (haskell-tng--hsinspect-srcid-source srcid))
(file (concat
;; TODO string-replace would be nice...
@@ -73,11 +75,11 @@ TODO: support local / git packages by consulting
`plan.json'"
;; code, so no point looking.
;;
;; WORKAROUND https://github.com/haskell/cabal/issues/6443
+ ;; TODO curl or a built-in emacs downloader, so cabal is not necessary
(shell-command (format "cabal get %s -d /var/empty &" srcid))
(error "%s was not found, attempting to download: please try again
later" tarball))
(message "Loading %s from %s" sym tarball)
- ;; TODO follow re-exports
(find-file tarball)
(let ((archive (current-buffer)))
(goto-char (point-min))
@@ -86,12 +88,10 @@ TODO: support local / git packages by consulting
`plan.json'"
(kill-buffer archive)
(read-only-mode 1)
(goto-char (point-min))
- ;; TODO re-use the imenu top-level parser
- ;; avoid false positives in export lists
+ ;; TODO re-use the imenu top-level parser, this is a massive hack
(re-search-forward (rx line-start "import" word-end) nil t)
- ;; will unfortunately find first uses
(or
- (re-search-forward (rx-to-string `(: (| bol "| " "data " "type " "class
") ,name symbol-end)))
+ (re-search-forward (rx-to-string `(: (| bol "| " "data " "type " "class
") ,name symbol-end)) nil t)
(re-search-forward (rx-to-string `(: symbol-start ,name
symbol-end)))))))
(defun haskell-tng--string-split-last (str sep)
@@ -103,26 +103,13 @@ TODO: support local / git packages by consulting
`plan.json'"
(cons front back)))
(defun haskell-tng--hsinspect-srcid-source (srcid)
+ (message "[haskell-tng] [DEBUG] tarball %s" srcid)
(let* ((parts (haskell-tng--string-split-last srcid "-"))
(package (car parts))
(version (cdr parts)))
(expand-file-name
(concat "~/.cabal/packages/hackage.haskell.org/" package "/" version "/"
srcid ".tar.gz"))))
-;; TODO expose the inplace information instead of filtering
-(defun haskell-tng--hsinspect-find-srcid (index module)
- ;; requires 0.0.9+
- (alist-get
- 'srcid
- (seq-find
- (lambda (pkg-entry)
- (when (not (alist-get 'inplace pkg-entry))
- (seq-find
- (lambda (module-entry)
- (equal module (alist-get 'module module-entry)))
- (alist-get 'modules pkg-entry))))
- index)))
-
;; TODO haskell-tng-show-documentation
(defvar-local haskell-tng-hsinspect-as
@@ -163,7 +150,7 @@ Respects the `C-u' cache invalidation convention."
(flush-cache (and alt (not (eq '- alt)))))
(when-let ((index (haskell-tng--hsinspect-index flush-cache))
(sym (haskell-tng--hsinspect-symbol-at-point)))
- (message "Seaching for '%s' in %s modules" sym (length index))
+ (message "Searching for '%s' in %s packages" sym (length index))
(when (string-match (rx bos (group (+ anything)) "." (group (+ (not (any
".")))) eos) sym)
(setq qual (match-string 1 sym))
@@ -247,6 +234,43 @@ Respects the `C-u' cache invalidation convention."
(lambda (names) (member sym (seq-map #'cdr names)))
imports))))
+(defun haskell-tng--hsinspect-follow (index srcid module name)
+ "Follow re-exports of MODULE to find which (srcid . module)
+originally defined NAME.
+
+The original module may not be exported and is therefore not
+present in the index. If an unexported module exports another
+unexported module's definition, we are unable to locate it."
+ ;; TODO probably doesn't work for 'tycon
+ ;; TODO use seq-find instead of seq-mapcat
+ ;; TODO `hsinspect index' could include unexported modules
+ (when srcid
+ (message "[haskell-tng] [DEBUG] follow %s %s %s" srcid module name))
+ (or
+ (car
+ (seq-mapcat
+ (lambda (pkg-entry)
+ (let ((srcid_ (alist-get 'srcid pkg-entry)))
+ (when (or (null srcid) (equal srcid srcid_))
+ (seq-mapcat
+ (lambda (module-entry)
+ (when (equal module (alist-get 'module module-entry))
+ (seq-mapcat
+ (lambda (entry)
+ (let ((id (pcase (alist-get 'class entry)
+ ((or 'id 'con 'pat) (alist-get 'name entry))
+ ('tycon (alist-get 'type entry)))))
+ (when (equal id name)
+ (if-let* ((export (alist-get 'export entry))
+ (from (alist-get 'module export))
+ (pkg (or (alist-get 'srcid export) srcid_)))
+ (list (haskell-tng--hsinspect-follow index pkg from
name))
+ (list (cons srcid_ module))))))
+ (alist-get 'ids module-entry))))
+ (alist-get 'modules pkg-entry)))))
+ index))
+ (cons srcid module)))
+
(defun haskell-tng--hsinspect-import-popup (index sym)
(when-let ((hits (haskell-tng--hsinspect-import-candidates index sym)))
;; TODO special case one hit
- [nongnu] elpa/haskell-tng-mode fe9d65d 222/385: helper for yatemplates, (continued)
- [nongnu] elpa/haskell-tng-mode fe9d65d 222/385: helper for yatemplates, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode bc93c3d 224/385: very alpha hsinspect support, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 658ddb6 251/385: docs, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 73a60f5 309/385: cache `which hsinspect` per project, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 5707166 365/385: use new ghcflags-provided PATH, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode b1c664b 364/385: allow hsinspect population in the background, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode ce17d96 376/385: new hsinspect release, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode eb6b487 357/385: test fqn-at-point and fix a longstanding bug, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 103e758 325/385: expose some more hsinspect-0.0.8 index info, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 374835c 355/385: a test for interactive commands, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode e3c6dc6 336/385: follow re-exports,
ELPA Syncer <=
- [nongnu] elpa/haskell-tng-mode 9904e72 366/385: jump-to-definition works inside the project, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 1c68e79 381/385: requires emacs 27, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 55d8e69 385/385: upgrade hsinspect, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 97e4a66 379/385: bump hsinspect, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 3870bf1 367/385: time to remove the cabal v2- prefixes, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 47f1f9f 180/385: lex CONSYM correctly, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 9bc086a 187/385: easier install, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 4f40db3 218/385: fast-tags is stack compatible by default, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 59640ce 234/385: cleanups thanks to MELPA review, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 35d3830 306/385: cache improvements, ELPA Syncer, 2021/10/06