diff --git a/CHANGELOG.adoc b/CHANGELOG.adoc index 9fd48a81..0ffa8343 100644 --- a/CHANGELOG.adoc +++ b/CHANGELOG.adoc @@ -2,6 +2,18 @@ All notable changes to this project will be documented in this file. This change == Unreleased (dev) +== 3.10.1 (2022-07-29) +// {{{ +=== Changed +* Applied idiomatic namespace aliases in style guide to default values for `g:iced#ns#favorites`. +** https://github.com/bbatsov/clojure-style-guide#use-idiomatic-namespace-aliases +* Bumped iced-nrepl to 1.2.13. + +=== Fixed +* Fixed nbb connection to detect CLJS session correctly. +* https://github.com/liquidz/vim-iced/issues/423[#423]: Fixed a bug about evaluating reader conditionals. +// }}} + == 3.10.0 (2022-07-16) // {{{ === Added diff --git a/autoload/iced/nrepl.vim b/autoload/iced/nrepl.vim index 0b0ca7c8..9cde584d 100644 --- a/autoload/iced/nrepl.vim +++ b/autoload/iced/nrepl.vim @@ -439,6 +439,11 @@ function! s:is_cljs_session(timeout_msec) abort return (type(value) == v:t_string && value ==# 'true') endfunction +function! s:is_nbb_nrepl(describe_resp) abort + let vers = get(a:describe_resp, 'versions', {}) + return has_key(vers, 'nbb-nrepl') +endfunction + function! s:connected(resp, opts) abort if has_key(a:resp, 'new-session') try @@ -447,15 +452,30 @@ function! s:connected(resp, opts) abort call iced#nrepl#set_session(initial_session, session) call iced#nrepl#change_current_session(initial_session) + let describe_resp = {} try - if s:is_cljs_session(500) - call iced#nrepl#set_session('cljs', session) - call iced#nrepl#change_current_session('cljs') - endif + let describe_resp = iced#promise#sync('iced#nrepl#describe', [], 500) catch " ignore endtry + if iced#nrepl#current_session_key() ==# 'clj' + if s:is_nbb_nrepl(describe_resp) + call iced#nrepl#set_session('cljs', session) + call iced#nrepl#change_current_session('cljs') + let a:opts['with_iced_nrepl'] = v:false + else + try + if s:is_cljs_session(500) + call iced#nrepl#set_session('cljs', session) + call iced#nrepl#change_current_session('cljs') + endif + catch + " ignore + endtry + endif + endif + let s:nrepl['init_ns'] = iced#nrepl#ns#name_by_var() if get(a:opts, 'with_iced_nrepl', v:true) diff --git a/autoload/iced/nrepl/refactor.vim b/autoload/iced/nrepl/refactor.vim index efa8a860..053ad1d8 100644 --- a/autoload/iced/nrepl/refactor.vim +++ b/autoload/iced/nrepl/refactor.vim @@ -7,22 +7,36 @@ let s:L = s:V.import('Data.List') " g:iced#ns#favorites {{{ let s:default_ns_favorites = { \ 'clj': { + \ 'cheshire.core': 'json', + \ 'clj-http.client': 'http', + \ 'clj-yaml.core': 'yaml', + \ 'clojure.core.async': 'as', + \ 'clojure.core.matrix': 'mat', + \ 'clojure.data.csv': 'csv', + \ 'clojure.data.xml': 'xml', \ 'clojure.edn': 'edn', \ 'clojure.java.io': 'io', + \ 'clojure.java.shell': 'sh', + \ 'clojure.pprint': 'pp', \ 'clojure.set': 'set', - \ 'clojure.spec.alpha': 's', + \ 'clojure.spec.alpha': 'spec', \ 'clojure.spec.gen.alpha': 'sgen', \ 'clojure.spec.test.alpha': 'stest', \ 'clojure.string': 'str', \ 'clojure.tools.logging': 'log', \ 'clojure.walk': 'walk', \ 'clojure.zip': 'zip', + \ 'hugsql.core': 'sql', + \ 'java-time': 'time', \ }, \ 'cljs': { + \ 'cljs.core.async': 'as', + \ 'cljs.pprint': 'pp', \ 'cljs.reader': 'reader', - \ 'cljs.spec.alpha': 's', + \ 'cljs.spec.alpha': 'spec', \ 'cljs.spec.gen.alpha': 'sgen', \ 'cljs.spec.test.alpha': 'stest', + \ 'clojure.edn': 'edn', \ 'clojure.set': 'set', \ 'clojure.string': 'str', \ 'clojure.walk': 'walk', diff --git a/autoload/iced/paredit.vim b/autoload/iced/paredit.vim index 13ddd723..746ccb32 100644 --- a/autoload/iced/paredit.vim +++ b/autoload/iced/paredit.vim @@ -235,15 +235,6 @@ function! s:set_visual_marks(marks) abort endfunction " Return visually selected text without changing selection state and registers -function! s:get_visual_selection() abort - let reg_save = @@ - silent normal! y - let result = @@ - let @@ = reg_save - silent normal! gv - return result -endfunction - function! s:get_visual_selection_and_pos() abort let reg_save = @@ silent normal! y @@ -262,7 +253,7 @@ function! s:select_top_list(top_code) abort let current_marks = s:get_visual_marks() call sexp#docount(2, 'sexp#select_current_list', 'v', 0, 1) - let next_code = s:get_visual_selection() + let next_code = get(s:get_visual_selection_and_pos(), 'code', '') if (next_code ==# a:top_code) | break | endif endwhile @@ -273,13 +264,33 @@ function! s:select_top_list(top_code) abort endtry endfunction +function! s:select_current_top_list() abort + let current_line = line('.') + let start_line = search('^\S', 'bW') + + call search('(', 'cW') + silent normal! % + let end_pos = getcurpos() + + if start_line > current_line || current_line > end_pos[1] + return '' + endif + + call cursor(start_line, 1) + silent normal! v + call cursor(end_pos[1], end_pos[2]) +endfunction + function! iced#paredit#get_top_list_in_comment() abort let view = winsaveview() let curpos = getpos('.') - " First use vim-sexp optimized top form selector - call sexp#select_current_top_list('v', 0) - let top_code = s:get_visual_selection() + " NOTE: `sexp#select_current_top_list` cannot correctly select codes + " including reader conditionals like below + " > #?(:clj :foo + " > :cljs :bar) + call s:select_current_top_list() + let top_code = get(s:get_visual_selection_and_pos(), 'code', '') if (stridx(top_code, '(comment') == 0) " Select up one by one if the top list is a (comment ...) form diff --git a/bin/iced b/bin/iced index c3b0753b..356993ff 100755 --- a/bin/iced +++ b/bin/iced @@ -9,7 +9,7 @@ SCRIPT_DIR=$(cd $(dirname $0); pwd) PROJECT_DIR=$(cd $SCRIPT_DIR; cd ..; pwd) VERSION=$(grep 'Version: ' ${SCRIPT_DIR}/../doc/vim-iced.txt | cut -d' ' -f2) -BASE_DEPENDENCIES='nrepl/nrepl:0.9.0 refactor-nrepl/refactor-nrepl:3.5.3 cider/cider-nrepl:0.28.5 com.github.liquidz/iced-nrepl:1.2.12' +BASE_DEPENDENCIES='nrepl/nrepl:0.9.0 refactor-nrepl/refactor-nrepl:3.5.3 cider/cider-nrepl:0.28.5 com.github.liquidz/iced-nrepl:1.2.13' BASE_MIDDLEWARES='cider.nrepl/wrap-classpath cider.nrepl/wrap-clojuredocs cider.nrepl/wrap-complete cider.nrepl/wrap-debug cider.nrepl/wrap-format cider.nrepl/wrap-info cider.nrepl/wrap-macroexpand cider.nrepl/wrap-ns cider.nrepl/wrap-out cider.nrepl/wrap-refresh cider.nrepl/wrap-stacktrace cider.nrepl/wrap-spec cider.nrepl/wrap-test cider.nrepl/wrap-trace cider.nrepl/wrap-undef cider.nrepl/wrap-xref refactor-nrepl.middleware/wrap-refactor iced.nrepl/wrap-iced' CLJS_DEPENDENCIES='cider/piggieback:0.5.3' diff --git a/deps.edn b/deps.edn index 89d33e60..a858e011 100644 --- a/deps.edn +++ b/deps.edn @@ -2,7 +2,7 @@ :deps {nrepl/nrepl {:mvn/version "0.9.0"} refactor-nrepl/refactor-nrepl {:mvn/version "3.5.3"} cider/cider-nrepl {:mvn/version "0.28.5"} - com.github.liquidz/iced-nrepl {:mvn/version "1.2.12"}} + com.github.liquidz/iced-nrepl {:mvn/version "1.2.13"}} :__middlewares__ ["cider.nrepl/wrap-classpath" "cider.nrepl/wrap-clojuredocs" diff --git a/doc/vim-iced.txt b/doc/vim-iced.txt index 290aab84..27aff13e 100644 --- a/doc/vim-iced.txt +++ b/doc/vim-iced.txt @@ -1,6 +1,6 @@ *vim-iced.txt* Clojure interactive development environment for Vim8/Neovim -Version: 3.10.0 +Version: 3.10.1 Author : Masashi Iizuka License: MIT LICENSE @@ -139,7 +139,7 @@ LEININGEN~ > {:user {:dependencies [[nrepl "0.9.0"] - [com.github.liquidz/iced-nrepl "1.2.12"] + [com.github.liquidz/iced-nrepl "1.2.13"] [cider/cider-nrepl "0.28.5"]] :repl-options {:nrepl-middleware [cider.nrepl/wrap-classpath cider.nrepl/wrap-clojuredocs @@ -171,7 +171,7 @@ BOOT~ (swap! boot.repl/*default-dependencies* concat '[[refactor-nrepl "3.5.3"] [cider/cider-nrepl "0.28.5"] - [com.github.liquidz/iced-nrepl "1.2.12"]]) + [com.github.liquidz/iced-nrepl "1.2.13"]]) (swap! boot.repl/*default-middleware* concat '[cider.nrepl/wrap-classpath @@ -201,7 +201,7 @@ SHADOW-CLJS~ { :dependencies [[refactor-nrepl "3.5.3"] [cider/cider-nrepl "0.28.5"] - [com.github.liquidz/iced-nrepl "1.2.12"]] + [com.github.liquidz/iced-nrepl "1.2.13"]] } < .nrepl.edn (local config) or $HOME/.nrepl/nrepl.edn (global config) diff --git a/ftplugin/clojure.vim b/ftplugin/clojure.vim index ea1dfc67..1f7d2b52 100644 --- a/ftplugin/clojure.vim +++ b/ftplugin/clojure.vim @@ -2,7 +2,7 @@ if exists('g:loaded_vim_iced') finish endif let g:loaded_vim_iced = 1 -let g:vim_iced_version = 31000 +let g:vim_iced_version = 31001 let g:vim_iced_home = expand(':p:h:h') " NOTE: https://github.com/vim/vim/commit/162b71479bd4dcdb3a2ef9198a1444f6f99e6843 " Add functions for defining and placing signs. diff --git a/test/paredit.vim b/test/paredit.vim index 8f370fa8..5fa722bd 100644 --- a/test/paredit.vim +++ b/test/paredit.vim @@ -255,3 +255,61 @@ function! s:suite.get_current_top_something_test() abort call s:assert.equals(res['code'], "{:foo\n {:bar 123}}") call s:buf.stop_dummy() endfunction + +function! s:suite.get_top_list_in_comment_test() abort + call s:buf.start_dummy([ + \ '(foo', + \ ' (bar|))', + \ ]) + let res = iced#paredit#get_top_list_in_comment() + call s:assert.equals(res['code'], "(foo\n (bar))") + call s:buf.stop_dummy() + + " reader conditionals + call s:buf.start_dummy([ + \ '#?(:clj :foo', + \ ' :cljs :bar|)', + \ ]) + let res = iced#paredit#get_top_list_in_comment() + call s:assert.equals(res['code'], "#?(:clj :foo\n :cljs :bar)") + call s:buf.stop_dummy() + + " whole in comments + call s:buf.start_dummy([ + \ '(comment', + \ ' |(foo)', + \ ' (bar))', + \ ]) + let res = iced#paredit#get_top_list_in_comment() + call s:assert.equals(res['code'], "(comment\n (foo)\n (bar))") + call s:buf.stop_dummy() + + " a part of comments + call s:buf.start_dummy([ + \ '(comment', + \ ' (|foo)', + \ ' (bar))', + \ ]) + let res = iced#paredit#get_top_list_in_comment() + call s:assert.equals(res['code'], '(foo)') + call s:buf.stop_dummy() + + " not a top list + call s:buf.start_dummy([ + \ '(foo)', + \ ' (bar|)', + \ ]) + let res = iced#paredit#get_top_list_in_comment() + call s:assert.equals(res['code'], '') + call s:buf.stop_dummy() + + call s:buf.start_dummy([ + \ '(foo)', + \ '|', + \ ]) + let res = iced#paredit#get_top_list_in_comment() + call s:assert.equals(res['code'], '') + call s:buf.stop_dummy() + +endfunction +