[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/haskell-tng-mode e0fd8f4 303/385: abstract the hsinspect c
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/haskell-tng-mode e0fd8f4 303/385: abstract the hsinspect caching logic |
Date: |
Tue, 5 Oct 2021 23:59:53 -0400 (EDT) |
branch: elpa/haskell-tng-mode
commit e0fd8f42d4663dc08979998aff0bf15e2f708775
Author: Tseen She <ts33n.sh3@gmail.com>
Commit: Tseen She <ts33n.sh3@gmail.com>
abstract the hsinspect caching logic
---
haskell-tng-hsinspect.el | 54 ++++++++++++++++++++++++++++--------------------
1 file changed, 32 insertions(+), 22 deletions(-)
diff --git a/haskell-tng-hsinspect.el b/haskell-tng-hsinspect.el
index 2b2ef76..fb59fed 100644
--- a/haskell-tng-hsinspect.el
+++ b/haskell-tng-hsinspect.el
@@ -119,50 +119,60 @@ A prefix argument ensures that caches are flushes."
(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
(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 (allow-work flush-cache)
+ (haskell-tng--hsinspect-cached-cmd
+ 'haskell-tng--hsinspect-imports
+ (concat buffer-file-name "." "imports")
+ `("imports" ,buffer-file-name)
+ allow-work
+ flush-cache))
+
+(defun haskell-tng--hsinspect-cached-cmd (buffer-local-cache
+ disk-cache
+ args
+ allow-work flush-cache)
(when flush-cache
- (setq haskell-tng--hsinspect-imports nil))
- (when (not haskell-tng--hsinspect-imports)
+ (set buffer-local-cache nil))
+ (when (not (symbol-value buffer-local-cache))
(let ((cache-file-name
(concat
(xdg-cache-home) "/"
- "hsinspect-0.0.7"
- buffer-file-name "."
- "imports")))
+ "hsinspect-0.0.7/"
+ disk-cache)))
;; 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
+ (set
+ buffer-local-cache
(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"))
+ ;; TODO decide if we want to keep this check, it's mostly for
debugging
+ (if (or
+ (buffer-modified-p)
+ (time-less-p
+ (file-attribute-modification-time (file-attributes
cache-file-name))
+ (file-attribute-modification-time (file-attributes
buffer-file-name))))
+ (message "loading hsinspect cache older than the current
buffer")
+ (message "loading hsinspect cache"))
(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))
+ (eq t (symbol-value buffer-local-cache)))
+ (set buffer-local-cache t)
+ (set buffer-local-cache (apply #'haskell-tng--hsinspect args))
+ (let ((cache (symbol-value buffer-local-cache)))
+ (unless (eq t cache)
(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))
+ (when (not (eq t (symbol-value buffer-local-cache)))
+ (symbol-value buffer-local-cache)))
;; 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 444664d 257/385: special case indentation of visual line breaks, (continued)
- [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, 2021/10/06
- [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 <=
- [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
- [nongnu] elpa/haskell-tng-mode 3179294 267/385: rename ormolu command, ELPA Syncer, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 388df13 282/385: refactor calls to hsinspect to allow for more callers, ELPA Syncer, 2021/10/06