Parse stacktraces from :make with lein

This commit is contained in:
Tim Pope 2014-01-30 23:13:35 -05:00
parent 7bc3ee4c1a
commit eb27299bd9
3 changed files with 60 additions and 31 deletions

9
compiler/lein.vim Normal file
View File

@ -0,0 +1,9 @@
" Vim compiler file
if exists("current_compiler")
finish
endif
let current_compiler = "lein"
CompilerSet makeprg=lein
CompilerSet errorformat=%+G,fireplace

View File

@ -45,9 +45,9 @@ middleware is loaded. https://github.com/cemerick/piggieback
LEININGEN *fireplace-leiningen* LEININGEN *fireplace-leiningen*
In addition to automatic repl connection, Clojure buffers in a Leiningen In addition to automatic repl connection, Clojure buffers in a Leiningen
project will automatically have their 'makeprg' set to lein. This has the project will automatically have their 'makeprg' set to lein and 'efm' set to
nominal value of letting you call, for example, |:make| deps rather than "%+G,fireplace". This combination enables `:make test` to run `lein test` and
:!lein deps. parse the stacktraces in the results.
DOCUMENTATION *fireplace-documentation* DOCUMENTATION *fireplace-documentation*

View File

@ -511,34 +511,32 @@ function! fireplace#findresource(resource, ...) abort
return '' return ''
endfunction endfunction
function! fireplace#quickfix_for(stacktrace) abort function! s:qfmassage(line, path) abort
let qflist = [] let entry = {'text': a:line}
for line in a:stacktrace let match = matchlist(a:line, '\(\S\+\)\s\=(\(\S\+\))')
let entry = {'text': line}
let match = matchlist(line, '\(.*\)(\(.*\))')
if !empty(match) if !empty(match)
let [_, class, file; __] = match let [_, class, file; __] = match
if file =~# '^NO_SOURCE_FILE:' || file !~# ':' if file =~# '^NO_SOURCE_FILE:' || file !~# ':'
let entry.resource = '' let entry.resource = ''
let entry.lnum = 0 let entry.lnum = 0
else else
let truncated = substitute(class, '\.[A-Za-z0-9_]\+\%($.*\)$', '', '') let truncated = substitute(class, '\.[A-Za-z0-9_]\+\%([$/].*\)$', '', '')
let entry.resource = tr(truncated, '.', '/').'/'.split(file, ':')[0] let entry.resource = tr(truncated, '.', '/').'/'.split(file, ':')[0]
let entry.lnum = split(file, ':')[-1] let entry.lnum = split(file, ':')[-1]
endif endif
let qflist += [entry] let entry.filename = fireplace#findresource(entry.resource, a:path)
endif if empty(entry.filename)
endfor let entry.lnum = 0
let paths = map(copy(qflist), 'fireplace#findresource(v:val.resource)')
let i = 0
for i in range(len(qflist))
if !empty(paths[i])
let qflist[i].filename = paths[i]
else else
call remove(qflist[i], 'lnum') let entry.text = class
endif endif
endfor endif
return qflist return entry
endfunction
function! fireplace#quickfix_for(stacktrace) abort
let path = fireplace#path()
return map(copy(a:stacktrace), 's:qfmassage(v:val, path)')
endfunction endfunction
function! s:output_response(response) abort function! s:output_response(response) abort
@ -1285,8 +1283,9 @@ function! s:hunt(start, anchor, pattern) abort
return '' return ''
endfunction endfunction
if !exists('s:leiningen_repl_ports') if !exists('s:leiningen_repls')
let s:leiningen_repls = {} let s:leiningen_repls = {}
let s:leiningen_paths = {}
endif endif
function! s:portfile() abort function! s:portfile() abort
@ -1326,6 +1325,7 @@ function! s:leiningen_connect() abort
let conn = nrepl#fireplace_connection#open(port) let conn = nrepl#fireplace_connection#open(port)
let s:leiningen_repls[b:leiningen_root].connection = conn let s:leiningen_repls[b:leiningen_root].connection = conn
call s:register_connection(conn, b:leiningen_root) call s:register_connection(conn, b:leiningen_root)
let s:leiningen_paths[b:leiningen_root] = conn.path()
catch /^nREPL Connection Error:/ catch /^nREPL Connection Error:/
if &verbose if &verbose
echohl WarningMSG echohl WarningMSG
@ -1350,15 +1350,35 @@ function! s:leiningen_init() abort
let b:java_root = b:leiningen_root let b:java_root = b:leiningen_root
setlocal makeprg=lein efm=%+G compiler lein
if exists('classpath#from_vim')
let s:leiningen_paths[b:leiningen_root] = classpath#from_vim(&path)
endif
call s:leiningen_connect() call s:leiningen_connect()
endfunction endfunction
function! s:massage_quickfix() abort
if &errorformat !~# 'fireplace$'
return
endif
if has_key(s:leiningen_paths, getcwd())
let path = s:leiningen_paths[getcwd()]
else
return
endif
let qflist = getqflist()
for entry in qflist
call extend(entry, s:qfmassage(get(entry, 'text', ''), path))
endfor
call setqflist(qflist, 'replace')
endfunction
augroup fireplace_leiningen augroup fireplace_leiningen
autocmd! autocmd!
autocmd User FireplacePreConnect call s:leiningen_connect() autocmd User FireplacePreConnect call s:leiningen_connect()
autocmd FileType clojure call s:leiningen_init() autocmd FileType clojure call s:leiningen_init()
autocmd QuickFixCmdPost make,cfile,cgetfile call s:massage_quickfix()
augroup END augroup END
" }}}1 " }}}1