interactive go to def with autocomplete
This commit is contained in:
parent
f199a9238d
commit
1673c7322e
|
@ -8,7 +8,7 @@
|
|||
(let [ldoc core.active_view.doc
|
||||
(aline acol bline bcol) (ldoc:get_selection)]
|
||||
(if (and (= aline bline) (= acol bcol))
|
||||
(ldoc:get_text aline 1 aline 10000000)
|
||||
(ldoc:get_text aline 1 aline math.huge)
|
||||
(ldoc:get_text aline acol bline bcol))))
|
||||
|
||||
(fn find-closest [s pattern i-target]
|
||||
|
@ -16,7 +16,7 @@
|
|||
(set (start end) (s:find pattern))
|
||||
(while (and start (< end (- i-target 1)))
|
||||
(set (start end) (s:find pattern (+ end 1))))
|
||||
(if (<= start i-target) (values start end)
|
||||
(if (and start (<= start i-target)) (values start end)
|
||||
(values 1 0)))
|
||||
|
||||
(local symbol-pattern "[a-zA-Z%!%@%#%$%%%^%&%*%<%>%?%/%~%-%_%=%+][a-zA-Z%!%@%#%$%%%^%&%*%<%>%?%/%~%-%_%=%+0-9%.%:]*")
|
||||
|
@ -24,7 +24,7 @@
|
|||
(let [ldoc core.active_view.doc
|
||||
(aline acol bline bcol) (ldoc:get_selection)]
|
||||
(if (and (= aline bline) (= acol bcol))
|
||||
(let [line (ldoc:get_text aline 1 aline 10000000)
|
||||
(let [line (ldoc:get_text aline 1 aline math.huge)
|
||||
(start end) (find-closest line symbol-pattern acol)]
|
||||
(ldoc:get_text aline start aline (+ end 1)))
|
||||
(ldoc:get_text aline acol bline bcol))))
|
||||
|
@ -54,23 +54,36 @@
|
|||
filename (or filename "")
|
||||
filename (if (filename:find "^%.%.%.") "" (or (filename:match "^%./(.*)") filename))
|
||||
line (tonumber (or line 0))
|
||||
doc (when (> (length filename) 0) (core.open_doc filename))]
|
||||
(when doc
|
||||
(core.root_view:open_doc doc)
|
||||
(doc:set_selection line 1 line 1)
|
||||
ldoc (when (> (length filename) 0) (core.open_doc filename))]
|
||||
(when ldoc
|
||||
(core.root_view:open_doc ldoc)
|
||||
(ldoc:set_selection line 1 line 1)
|
||||
true))))
|
||||
(core.log (.. "Unable to find symbol " symbol))))
|
||||
(: (replsession.session) :submit (.. ",find " symbol) jump-to-find-result))
|
||||
|
||||
(fn autocomplete-results [text]
|
||||
(var result [])
|
||||
(: (replsession.session) :submit (.. ",complete " text) #(set result (or $1.vals [])))
|
||||
result)
|
||||
|
||||
(fn autocomplete-symbol [callback ?starting-text]
|
||||
(fn fixup-result [text]
|
||||
(let [[completed-result] (autocomplete-results text)]
|
||||
(callback (or completed-result text))))
|
||||
(core.command_view:enter "Symbol" fixup-result autocomplete-results)
|
||||
(when ?starting-text (core.command_view:set_text ?starting-text)))
|
||||
|
||||
(command.add :core.docview {
|
||||
"repl:eval" #(submit nil (selected-form))
|
||||
"repl:go-to-definition" #(go-to-definition (selected-symbol))
|
||||
"fennel:eval" #(submit nil (selected-form))
|
||||
"fennel:go-to-definition-under-cursor" #(go-to-definition (selected-symbol))
|
||||
"fennel:go-to-definition" #(autocomplete-symbol #(go-to-definition $1) (selected-symbol))
|
||||
})
|
||||
|
||||
(keymap.add {
|
||||
:return "repl:submit"
|
||||
"alt+e" "repl:eval"
|
||||
"alt+d" "repl:go-to-definition"
|
||||
"alt+e" "fennel:eval"
|
||||
"alt+d" "fennel:go-to-definition-under-cursor"
|
||||
})
|
||||
|
||||
{: inline-eval : symbol-pattern}
|
||||
|
|
Loading…
Reference in a new issue