Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ElinOpenJavadoc command for vim #6

Merged
merged 4 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev/analysis.edn

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions doc/elin-mapping.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ ElinShowClojureDocs
Calls `elin.handler.lookup/show-clojuredocs` handler.
Key is mapped to |<Plug>(elin_show_clojuredocs)|.

*ElinOpenJavadoc*
ElinOpenJavadoc
Calls `elin.handler.lookup/open-javadoc` handler.
Key is mapped to |<Plug>(elin_open_javadoc)|.

*ElinTestUnderCursor*
ElinTestUnderCursor
Calls `elin.handler.test/run-test-under-cursor` handler.
Expand Down Expand Up @@ -305,6 +310,10 @@ MAPPINGS *elin-mappings*
<Plug>(elin_show_clojuredocs)
Same as |ElinShowClojureDocs|.

*<Plug>(elin_open_javadoc)*
<Plug>(elin_open_javadoc)
Same as |ElinOpenJavadoc|.

*<Plug>(elin_test_under_cursor)*
<Plug>(elin_test_under_cursor)
Same as |ElinTestUnderCursor|.
Expand Down Expand Up @@ -369,6 +378,7 @@ n <Leader>blr <Plug>(elin_local_references)
n K <Plug>(elin_lookup)
n <Leader>hs <Plug>(elin_show_source)
n <Leader>hc <Plug>(elin_show_clojuredocs)
n <Leader>hj <Plug>(elin_open_javadoc)
n <Leader>tt <Plug>(elin_test_under_cursor)
n <Leader>tf <Plug>(elin_test_focused_current_testing)
n <Leader>tn <Plug>(elin_test_in_ns)
Expand Down
3 changes: 3 additions & 0 deletions plugin/elin.vim
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ command! ElinLocalReferences call elin#notify('elin.handler.navigate/local-refer
command! ElinLookup call elin#notify('elin.handler.lookup/lookup', [])
command! ElinShowSource call elin#notify('elin.handler.lookup/show-source', [])
command! ElinShowClojureDocs call elin#notify('elin.handler.lookup/show-clojuredocs', [])
command! ElinOpenJavadoc call elin#notify('elin.handler.lookup/open-javadoc', [])

" Testing
command! ElinTestUnderCursor call elin#notify('elin.handler.test/run-test-under-cursor', [])
Expand Down Expand Up @@ -179,6 +180,7 @@ nnoremap <silent> <Plug>(elin_local_references) <Cmd>ElinLocalReferences<CR>
nnoremap <silent> <Plug>(elin_lookup) <Cmd>ElinLookup<CR>
nnoremap <silent> <Plug>(elin_show_source) <Cmd>ElinShowSource<CR>
nnoremap <silent> <Plug>(elin_show_clojuredocs) <Cmd>ElinShowClojureDocs<CR>
nnoremap <silent> <Plug>(elin_open_javadoc) <Cmd>ElinOpenJavadoc<CR>

" Testing
nnoremap <silent> <Plug>(elin_test_under_cursor) <Cmd>ElinTestUnderCursor<CR>
Expand Down Expand Up @@ -258,6 +260,7 @@ function! s:default_key_mappings() abort
call s:define_mapping('nmap', 'K', '<Plug>(elin_lookup)')
call s:define_mapping('nmap', '<Leader>hs', '<Plug>(elin_show_source)')
call s:define_mapping('nmap', '<Leader>hc', '<Plug>(elin_show_clojuredocs)')
call s:define_mapping('nmap', '<Leader>hj', '<Plug>(elin_open_javadoc)')

" Testing
call s:define_mapping('nmap', '<Leader>tt', '<Plug>(elin_test_under_cursor)')
Expand Down
1 change: 1 addition & 0 deletions resources/config.edn
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
elin.handler.lookup/show-clojuredocs {:export-edn-url "https://github.com/clojure-emacs/clojuredocs-export-edn/raw/master/exports/export.compact.edn"
:format #resource "template/clojuredocs.mustache"
:interceptor {:uses [elin.interceptor.handler/append-result-to-info-buffer {:show-temporarily? true}]}}
elin.handler.lookup/open-javadoc {}
elin.handler.namespace/add-libspec {:favorites #include "favorite_aliases.edn"
:java-classes #include "java_classes.edn"
:interceptor {:includes [elin.interceptor.handler.namespace/show-result
Expand Down
9 changes: 1 addition & 8 deletions src/elin/function/evaluate.clj
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,7 @@
([elin code]
(evaluate-code elin code {}))
([{:component/keys [nrepl]} code options]
(eval!! nrepl code options)
#_(eval!! nrepl code (merge options
{:line 0
:column 0
:cursor-line 0
:cursor-column 0
:ns nil
:file nil}))))
(eval!! nrepl code options)))

(defn evaluate-current-top-list
([elin]
Expand Down
11 changes: 11 additions & 0 deletions src/elin/handler/lookup.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[clojure.core.async :as async]
[clojure.string :as str]
[elin.error :as e]
[elin.function.evaluate :as e.f.evaluate]
[elin.function.lookup :as e.f.lookup]
[elin.function.sexpr :as e.f.sexpr]
[elin.protocol.host :as e.p.host]
Expand Down Expand Up @@ -65,3 +66,13 @@
resp (e.f.lookup/clojuredocs-lookup elin export-edn-url)]
(generate-doc {:clojuredocs (:format config)}
(e.f.lookup/get-clojuredocs-rendering-data resp))))

(defn open-javadoc
"Open a browser window displaying the javadoc for a symbol a t cursor position."
[{:as elin :component/keys [host]}]
(e/let [{:keys [lnum col]} (async/<!! (e.p.host/get-cursor-position! host))
ns-str (e/error-or (e.f.sexpr/get-namespace elin))
{:keys [code]} (e.f.sexpr/get-expr elin lnum col)
code (str `((requiring-resolve 'clojure.java.javadoc/javadoc) ~(symbol code)))]
(e.f.evaluate/evaluate-code elin code (when ns-str
{:ns ns-str}))))