-
-
Notifications
You must be signed in to change notification settings - Fork 139
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 support for spec middleware (form, example) #335
Changes from 10 commits
c37b5ab
75511e9
da93d74
f976bfb
a275e68
fbf5a49
d05b7cc
00f00bb
a5d1234
06e9520
a10cdce
1d3b8ae
812a4f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,18 @@ function! s:map(mode, lhs, rhs, ...) abort | |
endif | ||
endfunction | ||
|
||
function! s:pr(obj) abort | ||
if type(a:obj) == v:t_string | ||
return a:obj | ||
elseif type(a:obj) == v:t_list | ||
return '(' . join(map(copy(a:obj), 's:pr(v:val)'), ' ') . ')' | ||
elseif type(a:obj) == v:t_dict | ||
return '{' . join(map(keys(a:obj), 's:pr(v:val) . " " . s:pr(a:obj[v:val])'), ', ') . '}' | ||
else | ||
return string(a:obj) | ||
endif | ||
endfunction | ||
|
||
" Section: Escaping | ||
|
||
function! s:str(string) abort | ||
|
@@ -1666,6 +1678,53 @@ augroup fireplace_go_to_file | |
autocmd FileType clojure call s:set_up_go_to_file() | ||
augroup END | ||
|
||
" Section: Spec | ||
|
||
function! fireplace#qualify_keyword(kw) abort | ||
if a:kw =~# '^::.\+/' | ||
let kw = ':' . fireplace#resolve_alias(matchstr(a:kw, '^::\zs[^/]\+')) . matchstr(a:kw, '/.*') | ||
elseif a:kw =~# '^::' | ||
let kw = ':' . fireplace#ns() . '/' . strpart(a:kw, 2) | ||
else | ||
let kw = a:kw | ||
endif | ||
return kw | ||
endfunction | ||
|
||
function! s:SpecForm(kw) abort | ||
let op = "spec-form" | ||
if fireplace#op_available(op) | ||
let symbol = fireplace#qualify_keyword(a:kw) | ||
let response = fireplace#message({'op': op, 'spec-name': symbol})[0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the new |
||
if !empty(get(response, op)) | ||
echo s:pr(get(response, op)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An unknown op error includes the original op, so this should be adequate for error handling: elseif has_key(response, 'op')
return 'echoerr ' . string('Fireplace: no nREPL op available for ' . op) Use this same |
||
endif | ||
endif | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Drop the conditional and wrap everything in a try block to handle the case when we're not connected: try
...
catch /^Fireplace:/
return 'echoerr ' . v:exception
endtry |
||
return '' | ||
endfunction | ||
|
||
function! s:SpecExample(kw) abort | ||
let op = "spec-example" | ||
if fireplace#op_available(op) | ||
let symbol = fireplace#qualify_keyword(a:kw) | ||
let response = fireplace#message({'op': op, 'spec-name': symbol})[0] | ||
if !empty(get(response, op)) | ||
echo get(response, op) | ||
endif | ||
endif | ||
return '' | ||
endfunction | ||
|
||
function! s:set_up_fireplace_spec() abort | ||
command! -buffer -bar -nargs=1 -complete=customlist,fireplace#eval_complete SpecForm :exe s:SpecForm(<q-args>) | ||
command! -buffer -bar -nargs=1 -complete=customlist,fireplace#eval_complete SpecExample :exe s:SpecExample(<q-args>) | ||
endfunction | ||
|
||
augroup fireplace_spec | ||
autocmd! | ||
autocmd FileType clojure call s:set_up_fireplace_spec() | ||
augroup END | ||
|
||
" Section: Formatting | ||
|
||
function! fireplace#format(lnum, count, char) abort | ||
|
@@ -1772,6 +1831,8 @@ function! s:K() abort | |
let java_candidate = matchstr(word, '^\%(\w\+\.\)*\u\l[[:alnum:]$]*\ze\%(\.\|\/\w\+\)\=$') | ||
if java_candidate !=# '' | ||
return 'Javadoc '.java_candidate | ||
elseif word =~# '^:' | ||
return 'SpecForm '.word | ||
else | ||
return 'Doc '.word | ||
endif | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:SpecForm {keyword}
, and the wording needs tweaking but I'm not sure to what. Do these roughly correspond toclojure.spec
functions? If so, it might make sense to reference that like we do for:FindDoc
. I worry that just saying "spec" is confusing to those not familiar (it was for me).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use some codified version like
(spec/form)
- they are at least all named the same for now in all three versions of spec, that are in the wild.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used
spec/form
andgen/generate
- the later is the alias used in the main docs https://clojure.org/guides/spec#_sampling_generators; the first is a bit more clear than justs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we go all in and use the full namespaces? That should make it easier to look up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with the namespace would be to name all two currently (and soon three) supported by orchard/cider (spec "0", spec alpha, spec alpha 2) - which is a problem on it's on (see answer to "error handling" comment below)