Decouple quickfix massaging from lein support

This commit is contained in:
Tim Pope 2014-04-14 00:22:43 -04:00
parent c0a4901181
commit f25003deef
2 changed files with 62 additions and 53 deletions

View File

@ -6,4 +6,4 @@ endif
let current_compiler = "lein" let current_compiler = "lein"
CompilerSet makeprg=lein CompilerSet makeprg=lein
CompilerSet errorformat=%+G,fireplace CompilerSet errorformat=%+G

View File

@ -587,34 +587,6 @@ function! fireplace#findresource(resource, ...) abort
return '' return ''
endfunction endfunction
function! s:qfmassage(line, path) abort
let entry = {'text': a:line}
let match = matchlist(a:line, '\(\S\+\)\s\=(\(\S\+\))')
if !empty(match)
let [_, class, file; __] = match
if file =~# '^NO_SOURCE_FILE:' || file !~# ':'
let entry.resource = ''
let entry.lnum = 0
else
let truncated = substitute(class, '\.[A-Za-z0-9_]\+\%([$/].*\)$', '', '')
let entry.resource = tr(truncated, '.', '/').'/'.split(file, ':')[0]
let entry.lnum = split(file, ':')[-1]
endif
let entry.filename = fireplace#findresource(entry.resource, a:path)
if empty(entry.filename)
let entry.lnum = 0
else
let entry.text = class
endif
endif
return entry
endfunction
function! fireplace#quickfix_for(stacktrace) abort
let path = fireplace#path()
return map(copy(a:stacktrace), 's:qfmassage(v:val, path)')
endfunction
function! s:output_response(response) abort function! s:output_response(response) abort
let substitution_pat = '\e\[[0-9;]*m\|\r\|\n$' let substitution_pat = '\e\[[0-9;]*m\|\r\|\n$'
if get(a:response, 'err', '') !=# '' if get(a:response, 'err', '') !=# ''
@ -761,6 +733,55 @@ function! fireplace#evalparse(expr, ...) abort
throw err throw err
endfunction endfunction
" }}}1
" Quickfix {{{1
function! s:qfmassage(line, path) abort
let entry = {'text': a:line}
let match = matchlist(a:line, '\(\S\+\)\s\=(\(\S\+\))')
if !empty(match)
let [_, class, file; __] = match
if file =~# '^NO_SOURCE_FILE:' || file !~# ':'
let entry.resource = ''
let entry.lnum = 0
else
let truncated = substitute(class, '\.[A-Za-z0-9_]\+\%([$/].*\)$', '', '')
let entry.resource = tr(truncated, '.', '/').'/'.split(file, ':')[0]
let entry.lnum = split(file, ':')[-1]
endif
let entry.filename = fireplace#findresource(entry.resource, a:path)
if empty(entry.filename)
let entry.lnum = 0
else
let entry.text = class
endif
endif
return entry
endfunction
function! fireplace#quickfix_for(stacktrace) abort
let path = fireplace#path()
return map(copy(a:stacktrace), 's:qfmassage(v:val, path)')
endfunction
function! s:massage_quickfix() abort
let p = substitute(matchstr(','.&errorformat, ',classpath\zs\%(\\.\|[^\,]\)*'), '\\\ze[\,%]', '', 'g')
if empty(p)
return
endif
let path = p[0] ==# ',' ? s:path_extract(p[1:-1]) : split(p[1:-1], p[0])
let qflist = getqflist()
for entry in qflist
call extend(entry, s:qfmassage(get(entry, 'text', ''), path))
endfor
call setqflist(qflist, 'replace')
endfunction
augroup fireplace_quickfix
autocmd!
autocmd QuickFixCmdPost make,cfile,cgetfile call s:massage_quickfix()
augroup END
" }}}1 " }}}1
" Eval {{{1 " Eval {{{1
@ -1499,7 +1520,7 @@ endfunction
function! s:leiningen_connect(auto) abort function! s:leiningen_connect(auto) abort
if !exists('b:leiningen_root') if !exists('b:leiningen_root')
return return {}
endif endif
let portfile = s:leiningen_portfile() let portfile = s:leiningen_portfile()
if a:auto && empty(portfile) && exists(':Start') ==# 2 if a:auto && empty(portfile) && exists(':Start') ==# 2
@ -1512,7 +1533,7 @@ function! s:leiningen_connect(auto) abort
\ . escape(fnamemodify(b:leiningen_root, ':t') . ' repl', ' ') \ . escape(fnamemodify(b:leiningen_root, ':t') . ' repl', ' ')
\ 'lein repl' \ 'lein repl'
if get(get(g:, 'dispatch_last_start', {}), 'handler', 'headless') ==# 'headless' if get(get(g:, 'dispatch_last_start', {}), 'handler', 'headless') ==# 'headless'
return return {}
endif endif
finally finally
execute cd fnameescape(cwd) execute cd fnameescape(cwd)
@ -1526,12 +1547,9 @@ function! s:leiningen_connect(auto) abort
endwhile endwhile
endif endif
if empty(portfile) if empty(portfile)
return return {}
endif
let conn = fireplace#register_port_file(portfile, b:leiningen_root)
if has_key(conn, 'path')
let s:leiningen_paths[b:leiningen_root] = conn.path()
endif endif
return fireplace#register_port_file(portfile, b:leiningen_root)
endfunction endfunction
function! s:leiningen_init() abort function! s:leiningen_init() abort
@ -1548,36 +1566,27 @@ function! s:leiningen_init() abort
let b:java_root = b:leiningen_root let b:java_root = b:leiningen_root
compiler lein let conn = s:leiningen_connect(0)
if has_key(conn, 'path')
let s:leiningen_paths[b:leiningen_root] = conn.path()
endif
let path = s:path_extract(&path) let path = s:path_extract(&path)
if !empty(path) if !empty(path)
let s:leiningen_paths[b:leiningen_root] = path let s:leiningen_paths[b:leiningen_root] = path
endif endif
call s:leiningen_connect(0)
endfunction
function! s:massage_quickfix() abort compiler lein
if &errorformat !~# 'fireplace$' if has_key(s:leiningen_paths, b:leiningen_root)
return let &l:errorformat .= ',' . escape('classpath,'.join(s:leiningen_paths[b:leiningen_root], ','), '\,%')
endif 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 endfunction
augroup fireplace_leiningen augroup fireplace_leiningen
autocmd! autocmd!
autocmd User FireplacePreConnect call s:leiningen_connect(1) autocmd User FireplacePreConnect call s:leiningen_connect(1)
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