[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/haskell-tng-mode 5a064fd 328/385: hypen prefix asks to qua
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/haskell-tng-mode 5a064fd 328/385: hypen prefix asks to qualify the import |
Date: |
Tue, 5 Oct 2021 23:59:58 -0400 (EDT) |
branch: elpa/haskell-tng-mode
commit 5a064fd5ab2de9b78776bef1c378596f659cdb14
Author: Tseen She <ts33n.sh3@gmail.com>
Commit: Tseen She <ts33n.sh3@gmail.com>
hypen prefix asks to qualify the import
---
haskell-tng-hsinspect.el | 55 ++++++++++++++++++++++++++------------
test/haskell-tng-hsinspect-test.el | 2 ++
2 files changed, 40 insertions(+), 17 deletions(-)
diff --git a/haskell-tng-hsinspect.el b/haskell-tng-hsinspect.el
index ace34c1..19e2f72 100644
--- a/haskell-tng-hsinspect.el
+++ b/haskell-tng-hsinspect.el
@@ -46,27 +46,46 @@ A prefix argument ensures that caches are flushes."
;;;###autoload
(defun haskell-tng-import-symbol-at-point (&optional alt)
- "Import the symbol at point"
- ;; TODO C-- prefix could mean to ask the user to provide the qualifier after
being told the module name
+ "Import the symbol at point by querying the user to select from a menu.
+
+If the symbol is qualified, the module will be imported
+qualified.
+
+If called with a `-' prefix, the module will be imported
+qualified and the user will be asked for the name.
+
+Respects the `C-u' cache invalidation convention."
;; TODO shortlist for FQN imports (no need to calc the index)
;; TODO fqn version doesn't work one after the last character and non-fqn
version doesn't work on first
(interactive "P")
;; TODO update the hsinspect-imports cache
- (when-let* ((index (haskell-tng--hsinspect-index alt))
- (sym (haskell-tng--hsinspect-symbol-at-point)))
- (message "Seaching for '%s' in %s modules" sym (length index))
- (if (string-match (rx bos (group (+ anything)) "." (group (+ (not (any
".")))) eos) sym)
- (let* ((fqn (match-string 1 sym))
- (sym (match-string 2 sym)))
- (when-let (hit (haskell-tng--hsinspect-import-popup index sym))
- (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)
- (pcase (alist-get 'class hit)
- ('tycon (haskell-tng--import-symbol (alist-get 'module hit) nil
(alist-get 'type hit)))
- ;; FIXME con
- (_ (haskell-tng--import-symbol (alist-get 'module hit) nil
(alist-get 'name hit))))))))
+ (let ((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))
+ (if (string-match (rx bos (group (+ anything)) "." (group (+ (not (any
".")))) eos) sym)
+ (let* ((fqn (match-string 1 sym))
+ (sym (match-string 2 sym)))
+ (when-let (hit (haskell-tng--hsinspect-import-popup index sym))
+ (haskell-tng--import-symbol (alist-get 'module hit) fqn)))
+ (when-let* ((hit (haskell-tng--hsinspect-import-popup index sym))
+ (module (alist-get 'module hit)))
+ ;; TODO add parens around operators (or should that be in the
utility?)
+ (if (eq '- alt)
+ ;; TODO guess the name, e.g. find the camel cases
+ (let ((fqn (read-string (concat "import qualified " module " as
"))))
+ (haskell-tng--import-symbol module fqn)
+ (save-excursion
+ (unless (looking-at (regexp-quote sym))
+ (re-search-backward
+ (rx symbol-start (+ (| word (syntax symbol))) point)
+ (line-beginning-position)
+ 'no-error))
+ (insert fqn ".")))
+ (pcase (alist-get 'class hit)
+ ('tycon (haskell-tng--import-symbol module nil (alist-get 'type
hit)))
+ ;; FIXME con
+ (_ (haskell-tng--import-symbol module 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.
@@ -182,6 +201,8 @@ When using hsinspect-0.0.8, also: class, export, flavour."
nil
flush-cache)))
+;; TODO discover the PATH from the build tool and set it when calling hsinspect
+
(defvar haskell-tng--hsinspect-which-hsinspect
"cabal build -v0 :pkg:hsinspect:exe:hsinspect && cabal exec -v0 which --
hsinspect")
(defun haskell-tng--hsinspect-which-hsinspect ()
diff --git a/test/haskell-tng-hsinspect-test.el
b/test/haskell-tng-hsinspect-test.el
index 4cf4632..8184c74 100644
--- a/test/haskell-tng-hsinspect-test.el
+++ b/test/haskell-tng-hsinspect-test.el
@@ -11,6 +11,8 @@
(require 'haskell-tng-testutils
"test/haskell-tng-testutils.el")
+;; TODO tests of the user facing functions in the golden data format
+
(ert-deftest haskell-tng-hsinspect-test-qualify-latest ()
(let ((imports
(haskell-tng--util-read
- [nongnu] elpa/haskell-tng-mode 411268e 310/385: improve hsinspect error messages, (continued)
- [nongnu] elpa/haskell-tng-mode 411268e 310/385: improve hsinspect error messages, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 766480d 290/385: fast-tags should be project specific, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode efd8093 299/385: silent formatter errors, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 26c6828 291/385: fqn imports, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 4480bb4 319/385: bump hsinspect/ghcflags versions, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 99287ef 316/385: stack projectile defaults, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode dbb2b7a 350/385: block / return-from instead of catch / throw, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode d611f0b 322/385: thots, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode a717a50 331/385: allow workflow with qualified imports as default, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 70e649b 330/385: import qualified is even smarter, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 5a064fd 328/385: hypen prefix asks to qualify the import,
ELPA Syncer <=
- [nongnu] elpa/haskell-tng-mode c42b5c5 338/385: use url-copy-path instead of shelling out, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 8405852 351/385: document bugs and ideas, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode f429326 327/385: thots, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 8bb3c34 363/385: the in-memory cache doesn't have to cache nil, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode f5977b6 339/385: bugfix for source downloading, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 9359c7b 349/385: cl-loop, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode f5d76fc 348/385: tidy docs, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 3b37524 360/385: bugfix for qualified imports when the cache was bad, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode fe2b164 372/385: fix the build, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 63225d5 374/385: use .ghc.path to find hsinspect, build tool agnostic, ELPA Syncer, 2021/10/06