From ecc3d1f633da87cdf619ecc7e91729d33ad86d7b Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Fri, 9 Nov 2012 18:51:59 +0200 Subject: [PATCH] fixed the "cannot reload GotoDefinition while executing" error errors are redirected to a log buffer now instead of echoerr --- autoload/nimrod.vim | 132 ++++++++++++++++++++++++++++++++++++++++++++ ftplugin/nimrod.vim | 111 +------------------------------------ 2 files changed, 133 insertions(+), 110 deletions(-) create mode 100644 autoload/nimrod.vim diff --git a/autoload/nimrod.vim b/autoload/nimrod.vim new file mode 100644 index 0000000..8d7074b --- /dev/null +++ b/autoload/nimrod.vim @@ -0,0 +1,132 @@ +fun! nimrod#init() +endf + +let g:nim_log = [] + +fun! s:UpdateNimLog() + setlocal buftype=nofile + setlocal bufhidden=hide + setlocal noswapfile + + for entry in g:nim_log + call append(line('$'), split(entry, "\n")) + endfor + + let g:nim_log = [] + + match Search /^nimrod.*/ +endf + +augroup NimLog + au! + au BufEnter log://nimrod call s:UpdateNimLog() +augroup END + +fun! CurrentNimrodFile() + let save_cur = getpos('.') + call cursor(0, 0, 0) + + let PATTERN = "\\v^\\#\\s*included from \\zs.*\\ze" + let l = search(PATTERN, "n") + + if l != 0 + let f = matchstr(getline(l), PATTERN) + let l:to_check = expand('%:h') . "/" . f + else + let l:to_check = expand("%") + endif + + call setpos('.', save_cur) + return l:to_check +endf + +let g:nimrod_symbol_types = { + \ 'skParam': 'v', + \ 'skVar': 'v', + \ 'skLet': 'v', + \ 'skTemp': 'v', + \ 'skForVar': 'v', + \ 'skConst': 'v', + \ 'skResult': 'v', + \ 'skGenericParam': 't', + \ 'skType': 't', + \ 'skField': 'm', + \ 'skProc': 'f', + \ 'skMethod': 'f', + \ 'skIterator': 'f', + \ 'skConverter': 'f', + \ 'skMacro': 'f', + \ 'skTemplate': 'f', + \ 'skEnumField': 'v', + \ } + +fun! NimExec(op) + let cmd = printf("nimrod idetools %s --track:\"%s,%d,%d\" \"%s\"", + \ a:op, expand('%:p'), line('.'), col('.'), CurrentNimrodFile()) + + call add(g:nim_log, cmd) + let output = system(cmd) + call add(g:nim_log, output) + return output +endf + +fun! NimComplete(findstart, base) + if a:findstart + if synIDattr(synIDtrans(synID(line("."),col("."),1)), "name") == 'Comment' + return -1 + endif + return col('.') + else + let result = [] + let sugOut = NimExec("--suggest") + for line in split(sugOut, '\n') + let lineData = split(line, '\t') + if lineData[0] == "sug" + let kind = get(g:nimrod_symbol_types, lineData[1], '') + let c = { 'word': lineData[2], 'kind': kind, 'menu': lineData[3], 'dup': 1 } + call add(result, c) + endif + endfor + return result + endif +endf + +if !exists("g:neocomplcache_omni_patterns") + let g:neocomplcache_omni_patterns = {} +endif + +let g:neocomplcache_omni_patterns['nimrod'] = '[^. *\t]\.\w*' + +fun! GotoDefinition_nimrod() + let defOut = NimExec("--def") + if v:shell_error + echo "nimrod was unable to locate the definition. exit code: " . v:shell_error + " echoerr defOut + return 0 + endif + + let rawDef = matchstr(defOut, 'def\t\([^\n]*\)') + if rawDef == "" + echo "the current cursor position does not match any definitions" + return 0 + endif + + let defBits = split(rawDef, '\t') + let file = defBits[4] + let line = defBits[5] + exe printf("silent! e +%d %s", line, file) + return 1 +endf + +fun! FindReferences_nimrod() + setloclist() +endf + +" Syntastic syntax checking +fun! SyntaxCheckers_nimrod_GetLocList() + let makeprg = 'nimrod check ' . CurrentNimrodFile() + let errorformat = &errorformat + + return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) +endf + diff --git a/ftplugin/nimrod.vim b/ftplugin/nimrod.vim index b03e83d..e5ee894 100644 --- a/ftplugin/nimrod.vim +++ b/ftplugin/nimrod.vim @@ -7,116 +7,7 @@ let b:nimrod_loaded = 1 let s:cpo_save = &cpo set cpo&vim -if executable('nimrod') - let nimrod_paths = split(system('nimrod dump'),'\n') - let &l:tags = &g:tags - - for path in nimrod_paths - if finddir(path) == path - let &l:tags = path . "/tags," . &l:tags - endif - endfor -endif - -fun! CurrentNimrodFile() - let save_cur = getpos('.') - call cursor(0, 0, 0) - - let PATTERN = "\\v^\\#\\s*included from \\zs.*\\ze" - let l = search(PATTERN, "n") - - if l != 0 - let f = matchstr(getline(l), PATTERN) - let l:to_check = expand('%:h') . "/" . f - else - let l:to_check = expand("%") - endif - - call setpos('.', save_cur) - return l:to_check -endf - -let g:nimrod_symbol_types = { - \ 'skParam': 'v', - \ 'skVar': 'v', - \ 'skLet': 'v', - \ 'skTemp': 'v', - \ 'skForVar': 'v', - \ 'skConst': 'v', - \ 'skResult': 'v', - \ 'skGenericParam': 't', - \ 'skType': 't', - \ 'skField': 'm', - \ 'skProc': 'f', - \ 'skMethod': 'f', - \ 'skIterator': 'f', - \ 'skConverter': 'f', - \ 'skMacro': 'f', - \ 'skTemplate': 'f', - \ 'skEnumField': 'v', - \ } - -fun! NimComplete(findstart, base) - if a:findstart - if synIDattr(synIDtrans(synID(line("."),col("."),1)), "name") == 'Comment' - return -1 - endif - return col('.') - else - let result = [] - let cmd = printf("nimrod idetools --suggest --track:\"%s,%d,%d\" \"%s\"", - \ expand('%:p'), line('.'), col('.'), CurrentNimrodFile()) - - let sugOut = system(cmd) - for line in split(sugOut, '\n') - let lineData = split(line, '\t') - if lineData[0] == "sug" - let kind = get(g:nimrod_symbol_types, lineData[1], '') - let c = { 'word': lineData[2], 'kind': kind, 'menu': lineData[3], 'dup': 1 } - call add(result, c) - endif - endfor - return result - endif -endf - -if !exists("g:neocomplcache_omni_patterns") - let g:neocomplcache_omni_patterns = {} -endif - -let g:neocomplcache_omni_patterns['nimrod'] = '[^. *\t]\.\w*' - -fun! GotoDefinition_nimrod() - let cmd = printf("nimrod idetools --def --track:\"%s,%d,%d\" \"%s\"", - \ expand('%:p'), line('.'), col('.'), CurrentNimrodFile()) - - let defOut = system(cmd) - if v:shell_error - echoerr "error executing nimrod. exit code: " . v:shell_error - echoerr defOut - return 0 - endif - - let rawDef = matchstr(defOut, 'def\t\([^\n]*\)') - if rawDef == "" - echo "nimrod was unable to locate the definition" - return 0 - endif - - let defBits = split(rawDef, '\t') - let file = defBits[4] - let line = defBits[5] - exe printf("e +%d %s", line, file) - return 1 -endf - -" Syntastic syntax checking -fun! SyntaxCheckers_nimrod_GetLocList() - let makeprg = 'nimrod check ' . CurrentNimrodFile() - let errorformat = &errorformat - - return SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) -endf +call nimrod#init() setlocal formatoptions-=t formatoptions+=croql setlocal comments=:#