Skip to content

Instantly share code, notes, and snippets.

@RedBeard0531
Created January 10, 2018 22:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RedBeard0531/6e29dc5e5b40d666bfdfaee2d5270a81 to your computer and use it in GitHub Desktop.
Save RedBeard0531/6e29dc5e5b40d666bfdfaee2d5270a81 to your computer and use it in GitHub Desktop.
Terrible implementation of nimsuggest integration with zah/nim.vim
" :source this file in your "main" nim file to activate.
" You can run :source again to switch main file or when nimsuggest crashes.
" You can also :call nimsuggest#run('use') to see all uses of the thing your
" cursor is on.
"call system("killall nimsuggest")
let nimsuggest_job = job_start(["nimsuggest", "--stdin", "--v2", "--debug", "--log", expand("%")], {
\ "in_mode" : "nl",
\ "out_mode" : "nl",
\ "err_io": "out",
\})
let nimsuggest_ch = job_getchannel(nimsuggest_job)
function! nimsuggest#run(cmd)
let tmp = tempname() . ".nim"
call writefile(getline(0, '$'), tmp)
try
call ch_sendraw(g:nimsuggest_ch, join([a:cmd, expand("%").';'.tmp, line('.'), col('.') - 1])."\n")
let lines = []
while 1
let line = ch_read(g:nimsuggest_ch)
if line == ""
break
endif
call add(lines, split(line, '\t'))
endwhile
finally
call delete(tmp)
endtry
return lines
endfunction
function! nimsuggest#def()
let res = nimsuggest#run('def')
if empty(res)
return
endif
let res = res[0]
let file = res[4]
let line = res[5]
let col = res[6] + 1
let mybuf = bufnr(file, 1)
exec 'b ' . mybuf
setlocal buflisted
"PP mybuf
call setpos('.', [mybuf, line, col, 0])
endfunction
function! nimsuggest#suggest()
let res = nimsuggest#run('sug')
for row in res
let row[2] = split(row[2], '\.')[-1]
endfor
return res
endfunction
function! nimsuggest#setup()
nnoremap <silent><buffer> gd :call nimsuggest#def()<cr>
let b:nim_caas_enabled = 1
endfunction
call nimsuggest#setup()
augroup nimsuggest
autocmd!
autocmd! FileType nim call nimsuggest#setup()
augroup END
diff --git a/autoload/nim.vim b/autoload/nim.vim
index 0bfb1f7..8543e5e 100644
--- a/autoload/nim.vim
+++ b/autoload/nim.vim
@@ -143,9 +143,7 @@ fun! NimComplete(findstart, base)
return col('.')
else
let result = []
- let sugOut = NimExec("--suggest")
- for line in split(sugOut, '\n')
- let lineData = split(line, '\t')
+ for lineData in nimsuggest#suggest()
if len(lineData) > 0 && lineData[0] == "sug"
let kind = get(g:nim_symbol_types, lineData[1], '')
let c = { 'word': lineData[2], 'kind': kind, 'menu': lineData[3], 'dup': 1 }
diff --git a/autoload/nim_vim.py b/autoload/nim_vim.py
index dde6e9f..164d23d 100644
--- a/autoload/nim_vim.py
+++ b/autoload/nim_vim.py
@@ -61,7 +61,7 @@ def nimVimEscape(expr):
class NimVimThread(NimThread):
def asyncOpComplete(self, msg, result):
- cmd = "/usr/local/bin/mvim --remote-expr 'NimAsyncCmdComplete(1, \"" + nimVimEscape(result) + "\")'"
+ cmd = "/bin/vim --remote-expr 'NimAsyncCmdComplete(1, \"" + nimVimEscape(result) + "\")'"
os.system (cmd)
NimProjects = {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment