Guest User

Untitled

a guest
Jan 20th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.76 KB | None | 0 0
  1. " :source this file in your "main" nim file to activate.
  2. " You can run :source again to switch main file or when nimsuggest crashes.
  3. " You can also :call nimsuggest#run('use') to see all uses of the thing your
  4. " cursor is on.
  5.  
  6. "call system("killall nimsuggest")
  7. let nimsuggest_job = job_start(["nimsuggest", "--stdin", "--v2", "--debug", "--log", expand("%")], {
  8. \ "in_mode" : "nl",
  9. \ "out_mode" : "nl",
  10. \ "err_io": "out",
  11. \})
  12. let nimsuggest_ch = job_getchannel(nimsuggest_job)
  13.  
  14. function! nimsuggest#run(cmd)
  15. let tmp = tempname() . ".nim"
  16. call writefile(getline(0, '$'), tmp)
  17. try
  18. call ch_sendraw(g:nimsuggest_ch, join([a:cmd, expand("%").';'.tmp, line('.'), col('.') - 1])."\n")
  19. let lines = []
  20. while 1
  21. let line = ch_read(g:nimsuggest_ch)
  22. if line == ""
  23. break
  24. endif
  25.  
  26. call add(lines, split(line, '\t'))
  27. endwhile
  28. finally
  29. call delete(tmp)
  30. endtry
  31. return lines
  32. endfunction
  33.  
  34. function! nimsuggest#def()
  35. let res = nimsuggest#run('def')
  36. if empty(res)
  37. return
  38. endif
  39. let res = res[0]
  40. let file = res[4]
  41. let line = res[5]
  42. let col = res[6] + 1
  43. let mybuf = bufnr(file, 1)
  44. exec 'b ' . mybuf
  45. setlocal buflisted
  46. "PP mybuf
  47. call setpos('.', [mybuf, line, col, 0])
  48. endfunction
  49.  
  50. function! nimsuggest#suggest()
  51. let res = nimsuggest#run('sug')
  52. for row in res
  53. let row[2] = split(row[2], '\.')[-1]
  54. endfor
  55. return res
  56. endfunction
  57.  
  58. function! nimsuggest#setup()
  59. nnoremap <silent><buffer> gd :call nimsuggest#def()<cr>
  60. let b:nim_caas_enabled = 1
  61. endfunction
  62.  
  63. call nimsuggest#setup()
  64.  
  65. augroup nimsuggest
  66. autocmd!
  67. autocmd! FileType nim call nimsuggest#setup()
  68. augroup END
Add Comment
Please, Sign In to add comment