-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcounsel-tide-nav.el
73 lines (59 loc) · 2.21 KB
/
counsel-tide-nav.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
(defun counsel-tide-nav (&optional initial-input)
(interactive)
(ivy-read "Tide project symbol: "
#'counsel-tide-nav--fn
:initial-input initial-input
:dynamic-collection t
:history 'counsel-tide-nav-history
:require-match t
:action (lambda (x) (tide-jump-to-filespan (counsel-tide-nav--get-value x)))
:caller 'counsel-tide-nav))
(defun counsel-tide-nav--make-data (name value)
(let ((my-hash (make-hash-table :test 'equal)))
(puthash "name" name my-hash)
(puthash "value" value my-hash)
my-hash))
(defun counsel-tide-nav--get-name (data)
(gethash "name" data))
(defun counsel-tide-nav--get-value (data)
(gethash "value" data))
(ivy-configure 'counsel-tide-nav
:display-transformer-fn
#'counsel-tide-nav--get-name)
(defun counsel-tide-nav--fn (str)
(let ((response (tide-command:navto str)))
(tide-on-response-success response
(when-let ((navto-items (plist-get response :body))
(cutoff (length (tide-project-root))))
(setq navto-items (funcall tide-navto-item-filter navto-items))
(seq-map (lambda (navto-item)
(counsel-tide-nav--make-data
(format "%s: %s"
(substring (plist-get navto-item :file) cutoff)
(plist-get navto-item :name))
navto-item))
navto-items)))))
(defun counsel-foo ()
(interactive)
(ivy-read "Foo: "
(counsel-foo-fn "x")
:action (lambda (x) (message "I got %s" x))))
(defun counsel-foo-dynamic ()
(interactive)
(ivy-read "Foo dyn: "
#'counsel-foo-fn
:dynamic-collection t
:action (lambda (x) (message "I got %s" x))
:caller 'counsel-foo-dynamic))
(ivy-configure 'counsel-foo-dynamic
:display-transformer-fn
(lambda (elt) (gethash "val" elt)))
(setq myhash (make-hash-table :test 'equal))
(puthash "1" "one" myhash)
(puthash "2" "two" myhash)
(puthash "display" "1" myhash)
(puthash "val" "2" myhash)
;; (defun counsel-foo-fn (&rest args)
;; '(("1" . "one") ("2" . "two")))
(defun counsel-foo-fn (&rest args)
(list myhash myhash))