[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/haskell-tng-mode 494aef4 302/385: cache the results of hsi
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/haskell-tng-mode 494aef4 302/385: cache the results of hsinspect imports |
Date: |
Tue, 5 Oct 2021 23:59:52 -0400 (EDT) |
branch: elpa/haskell-tng-mode
commit 494aef464470d3603713f062349a3195d897f6e9
Author: Tseen She <ts33n.sh3@gmail.com>
Commit: Tseen She <ts33n.sh3@gmail.com>
cache the results of hsinspect imports
---
haskell-tng-extra-company.el | 2 +-
haskell-tng-hsinspect.el | 59 +++++++++++++++++++++++++++++++++++---------
2 files changed, 48 insertions(+), 13 deletions(-)
diff --git a/haskell-tng-extra-company.el b/haskell-tng-extra-company.el
index 2c8cf62..8dc1f7d 100644
--- a/haskell-tng-extra-company.el
+++ b/haskell-tng-extra-company.el
@@ -54,7 +54,7 @@
;;(message "TNG asked with %S" arg)
(seq-mapcat
(lambda (names) (all-completions arg (seq-map #'cdr names)))
- (haskell-tng--hsinspect-imports 'lookup-only)))
+ (haskell-tng--hsinspect-imports nil nil)))
('sorted t)
('duplicates t)
;; TODO 'meta return the FQN
diff --git a/haskell-tng-hsinspect.el b/haskell-tng-hsinspect.el
index 522f43e..2b2ef76 100644
--- a/haskell-tng-hsinspect.el
+++ b/haskell-tng-hsinspect.el
@@ -15,6 +15,7 @@
;; with pre-canned data.
(require 'subr-x)
+(require 'xdg)
;; Popups are not supported in stock Emacs so an extension is necessary:
;; https://emacs.stackexchange.com/questions/53373
@@ -27,14 +28,16 @@
(require 'haskell-tng-util)
;;;###autoload
-(defun haskell-tng-fqn-at-point ()
+(defun haskell-tng-fqn-at-point (&optional alt)
"Consult the imports in scope and display the fully qualified
-name of the symbol at point in the minibuffer."
- (interactive) ;; TODO prefix should copy to kill ring
+name of the symbol at point in the minibuffer.
+
+A prefix argument ensures that caches are flushes."
+ (interactive "P")
(if-let* ((sym (haskell-tng--hsinspect-symbol-at-point))
(found (seq-find
(lambda (names) (member sym (seq-map #'cdr names)))
- (haskell-tng--hsinspect-imports))))
+ (haskell-tng--hsinspect-imports 'allow-work alt))))
;; TODO multiple hits
;; TODO feedback when hsinspect is broken
(popup-tip (format "%s" (cdar (last found))))
@@ -116,18 +119,50 @@ name of the symbol at point in the minibuffer."
(buffer-substring-no-properties (point-min) (point-max))))
(user-error "could not find `.ghc.flags'.")))
+;; FIXME abstract caching to a common macro / function
;; TODO invalidate cache when imports section has changed
-;; FIXME cache per file (timestamp based, for optimal browsing)
(defvar-local haskell-tng--hsinspect-imports nil
"Cache for the last `imports' call for this buffer.
t means the process failed.")
-(defun haskell-tng--hsinspect-imports (&optional lookup-only)
- (if (or lookup-only haskell-tng--hsinspect-imports)
- (unless (eq t haskell-tng--hsinspect-imports)
- haskell-tng--hsinspect-imports)
- (setq haskell-tng--hsinspect-imports t) ;; avoid races
- (setq haskell-tng--hsinspect-imports
- (haskell-tng--hsinspect "imports" buffer-file-name))))
+(defun haskell-tng--hsinspect-imports (allow-work flush-cache)
+ (when flush-cache
+ (setq haskell-tng--hsinspect-imports nil))
+ (when (not haskell-tng--hsinspect-imports)
+ (let ((cache-file-name
+ (concat
+ (xdg-cache-home) "/"
+ "hsinspect-0.0.7"
+ buffer-file-name "."
+ "imports")))
+ ;; user is responsible for flushing caches.
+ (when (and flush-cache (file-exists-p cache-file-name))
+ (delete-file cache-file-name))
+ (if (file-exists-p cache-file-name)
+ (setq
+ haskell-tng--hsinspect-imports
+ (progn
+ (when (time-less-p
+ (file-attribute-modification-time (file-attributes
cache-file-name))
+ (file-attribute-modification-time (file-attributes
buffer-file-name)))
+ (message "Loading a stale cache for hsinspect imports"))
+ (with-temp-buffer
+ (insert-file-contents cache-file-name)
+ (goto-char (point-min))
+ (ignore-errors (read (current-buffer))))))
+ (unless (or (not allow-work)
+ (eq t haskell-tng--hsinspect-imports))
+ (setq haskell-tng--hsinspect-imports t)
+ (setq
+ haskell-tng--hsinspect-imports
+ (haskell-tng--hsinspect "imports" buffer-file-name))
+ (unless (eq t haskell-tng--hsinspect-imports)
+ (let ((cache haskell-tng--hsinspect-imports))
+ (with-temp-file cache-file-name
+ (make-directory (file-name-directory cache-file-name) t)
+ (prin1 cache (current-buffer)))))))))
+
+ (when (not (eq t haskell-tng--hsinspect-imports))
+ haskell-tng--hsinspect-imports))
;; FIXME this can be more efficiently cached alongside the .ghc.flags file,
not per source file
;; (it's also fast to load so maybe persist it in a cache dir and check
timestamps)
- [nongnu] elpa/haskell-tng-mode 56ee2aa 231/385: completions alpha, (continued)
- [nongnu] elpa/haskell-tng-mode 56ee2aa 231/385: completions alpha, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 6e938d0 230/385: workaround cabal bug, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 444664d 257/385: special case indentation of visual line breaks, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 487989b 241/385: skeleton for contrib-stack, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode cea8b23 240/385: proof of concept getting the ghcflags from cabal, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 6699829 277/385: cleaner fqns, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 0abe075 246/385: only create ghcflags for relative dirs, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 2cfae9e 276/385: bump hsinspect, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 949f857 242/385: support component directories, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 7ae3f46 244/385: more workarounds for hsinspect setup, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 494aef4 302/385: cache the results of hsinspect imports,
ELPA Syncer <=
- [nongnu] elpa/haskell-tng-mode 598b372 288/385: typo, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode e0fd8f4 303/385: abstract the hsinspect caching logic, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 4dc6f76 313/385: fix hsinspect discoverability, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode eb4591f 287/385: document popup dependency, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 48729c8 308/385: more cache cleanups, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 6299e6d 317/385: amazeballs idea, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode aa9cdbb 226/385: hacky file-specific language extensions, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode a4f06f5 237/385: an idea, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 0113f37 273/385: hsinspect should work on symbols with FQNs, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 06e4e76 245/385: support running scripts on nix, ELPA Syncer, 2021/10/06