[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/haskell-tng-mode 9904e72 366/385: jump-to-definition works
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/haskell-tng-mode 9904e72 366/385: jump-to-definition works inside the project |
Date: |
Wed, 6 Oct 2021 00:00:05 -0400 (EDT) |
branch: elpa/haskell-tng-mode
commit 9904e72e74c8faa5b5fe3ef50adc08fb136684b5
Author: Tseen She <ts33n.sh3@gmail.com>
Commit: Tseen She <ts33n.sh3@gmail.com>
jump-to-definition works inside the project
---
README.md | 2 +-
haskell-tng-hsinspect.el | 46 ++++++++++++++++++++++++++++++----------------
2 files changed, 31 insertions(+), 17 deletions(-)
diff --git a/README.md b/README.md
index 80ec953..49fa1e8 100644
--- a/README.md
+++ b/README.md
@@ -108,7 +108,7 @@ Third party Haskell tools must be installed separately
(e.g. via `cabal v2-insta
- [`ormolu`](https://github.com/tweag/ormolu)
- `C-c p R` invoke
[`fast-tags`](https://hackage.haskell.org/package/fast-tags) via
[`projectile`](https://github.com/bbatsov/projectile)
-Note that to jump to definition inside the project, use
`projectile-regenerate-tags` and `projectile-find-tag`.
+Note that to jump to definition inside the project can also be achieved with
`projectile-regenerate-tags` and `projectile-find-tag`.
## Contributing
diff --git a/haskell-tng-hsinspect.el b/haskell-tng-hsinspect.el
index 7231c59..bd34283 100644
--- a/haskell-tng-hsinspect.el
+++ b/haskell-tng-hsinspect.el
@@ -18,6 +18,7 @@
(require 'cl))
(require 'array)
+(require 'dired)
(require 'subr-x)
(require 'tar-mode)
(require 'timer)
@@ -67,16 +68,26 @@ definition of the symbol in the build tool's source
archive."
(`(,pkg-entry ,module-entry ,internal-srcid ,internal-module)
(haskell-tng--hsinspect-follow index nil imported name)))
(if (or (null pkg-entry) (alist-get 'inplace pkg-entry))
- ;; TODO support local / git packages by consulting `plan.json'. Note
- ;; this will only work properly if hsinspect includes all the
- ;; unexported modules for inplace packages. It's starting to
- ;; sound like a very complex feature... and perhaps not worth
- ;; implementing given that TAGS work just great.
- ;;
- ;; FIXME or implement this by constructing the expected path/filename
- ;; from the module name and then just find files having that
name
- ;; and pick the first one. Should work 99% of the time.
- (error "%s is defined in a local package" qualified)
+ (progn
+ ;; simpler alternative to parsing build tool specific data
+ (if-let (package-dir (or
+ (haskell-tng--util-locate-dominating-file
+ haskell-tng--compile-dominating-project)
+ (haskell-tng--util-locate-dominating-file
+ haskell-tng--compile-dominating-package)))
+ (pcase-let ((`(,dir . ,file) (haskell-tng--string-split-last
imported ".")))
+ (let ((find (string-trim
+ (shell-command-to-string
+ (format "find %s -path \"*/%s/*\" -name
\"%s.hs\""
+ package-dir
+ (haskell-tng--string-replace dir "."
"/")
+ file)))))
+ (if (file-readable-p find)
+ (progn
+ (find-file find)
+ (haskell-tng--hsinspect-goto-symbol name))
+ (error "did not find %s.hs in %s" file dir))))
+ (error "%s is defined in a local package and the project root is
unknown" qualified)))
(when-let* ((srcid (or internal-srcid (alist-get 'srcid pkg-entry)))
(module (or internal-module (alist-get 'module
module-entry)))
(file (concat (haskell-tng--string-replace module "." "/")
".hs"))
@@ -106,12 +117,15 @@ definition of the symbol in the build tool's source
archive."
(tar-extract)
(kill-buffer archive)
(read-only-mode 1)
- (goto-char (point-min))
- ;; TODO re-use the imenu top-level parser, this is a massive hack
- (re-search-forward (rx line-start "import" word-end) nil t)
- (or
- (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))))))))))
+ (haskell-tng--hsinspect-goto-symbol name)))))))
+
+;; TODO re-use the imenu top-level parser, this is a massive hack
+(defun haskell-tng--hsinspect-goto-symbol (name)
+ (goto-char (point-min))
+ (re-search-forward (rx line-start "import" word-end) nil t)
+ (or
+ (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-replace (str from to)
(mapconcat 'identity (split-string str (regexp-quote from)) to))
- [nongnu] elpa/haskell-tng-mode bc93c3d 224/385: very alpha hsinspect support, (continued)
- [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, 2021/10/06
- [nongnu] elpa/haskell-tng-mode 9904e72 366/385: jump-to-definition works inside the project,
ELPA Syncer <=
- [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
- [nongnu] elpa/haskell-tng-mode c0b1b6b 301/385: change the compile-always-ask default, ELPA Syncer, 2021/10/06