aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuchen Pei <hi@ypei.me>2022-09-28 14:28:20 +1000
committerYuchen Pei <hi@ypei.me>2022-09-28 14:35:19 +1000
commitabb88a89b50b241a4492114c6fbce364af56f48e (patch)
treeba93f9cf2872f0fb8c7e2f04be90f516fb845b2d
parentf85beb8c1b8ac06a02ffc4d2fc6f80f18dc65523 (diff)
do not try to go to haddorg if the identifier is not exported
-rw-r--r--hcel-haddorg.el38
1 files changed, 22 insertions, 16 deletions
diff --git a/hcel-haddorg.el b/hcel-haddorg.el
index f757e24..90b0ce6 100644
--- a/hcel-haddorg.el
+++ b/hcel-haddorg.el
@@ -19,6 +19,7 @@
(require 'hcel-source)
(require 'hcel-client)
(require 'hcel-utils)
+(require 'json)
(require 'org)
(defcustom hcel-haddorg-dir "~/Projects/sedoc/haddock/org-output"
@@ -56,22 +57,27 @@ is in ghc-8.10.1, hcel will attempt to look up in ghc-9.2.2.org.")
(defun hcel-identifier-at-point-to-haddorg ()
(interactive)
(when-let* ((identifier (hcel-text-property-near-point 'identifier))
- (external-id (alist-get 'externalId
- (alist-get (intern identifier)
- hcel-identifiers))))
- (let* ((splitted (split-string external-id "|"))
- (package-id (car splitted))
- (module-name (cadr splitted))
- (entity (cond ((equal (caddr splitted) "Typ") "t")
- ((equal (caddr splitted) "Val") "v")
- (t nil)))
- (name (cadddr splitted))
- (file-name (hcel-haddorg-fuzzy-version-match package-id))
- (custom-id (concat module-name "/" entity "/" name)))
- (unless file-name
- (error "Cannot find org file for %s" package-id))
- (org-link-open-from-string
- (format "[[file:%s::#%s]]" file-name custom-id)))))
+ (id (alist-get (intern identifier) hcel-identifiers))
+ (exported (alist-get 'isExported id))
+ (external-id (alist-get 'externalId id)))
+ (if (and (eq exported json-false)
+ ;; FIXME: Hacky. ExactLocation implies identifier is declared in
+ ;; the current module.
+ (equal (alist-get 'tag (alist-get 'locationInfo id)) "ExactLocation"))
+ (message "%s is not exported." (hcel-occ-symbol-at-point))
+ (let* ((splitted (split-string external-id "|"))
+ (package-id (car splitted))
+ (module-name (cadr splitted))
+ (entity (cond ((equal (caddr splitted) "Typ") "t")
+ ((equal (caddr splitted) "Val") "v")
+ (t nil)))
+ (name (cadddr splitted))
+ (file-name (hcel-haddorg-fuzzy-version-match package-id))
+ (custom-id (concat module-name "/" entity "/" name)))
+ (if file-name
+ (org-link-open-from-string
+ (format "[[file:%s::#%s]]" file-name custom-id))
+ (message "Cannot find org file for %s" package-id))))))
(defun hcel-haddorg-fuzzy-version-match (package-id)
(let ((exact-match