Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.

Commit

Permalink
Alternative approach: calling mix directly
Browse files Browse the repository at this point in the history
Instead of having a modified version of the xref mix task, we can just
call `mix` and parse the results
  • Loading branch information
carloslima committed Nov 15, 2016
1 parent 94a02da commit 967ab84
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
21 changes: 21 additions & 0 deletions after/plugin/alchemist.vim
Expand Up @@ -191,6 +191,24 @@ function! alchemist#exdoc(...)
call s:open_doc_window(query, "new", "split")
endfunction

function! alchemist#exref(...)
let query = ''
if empty(a:000)
let query = alchemist#lookup_name_under_cursor()
else
let query = a:000[0]
endif
let result = alchemist#alchemist_client('XREF ' . query)

let errorformat = &errorformat
try
let &errorformat = '%A%f:%l: %m'
cex result
finally
let &errorformat = errorformat
endtry
endfunction

function! alchemist#exdef(...)
let query = ''
if empty(a:000)
Expand Down Expand Up @@ -439,6 +457,9 @@ command! -nargs=? -complete=customlist,elixircomplete#ExDocComplete ExDoc
command! -nargs=? -complete=customlist,elixircomplete#ExDocComplete ExDef
\ call alchemist#exdef(<f-args>)

command! -nargs=? -complete=customlist,elixircomplete#ExDocComplete ExRef
\ call alchemist#exref(<f-args>)

if !exists(':Mix')
command! -bar -nargs=? -complete=custom,alchemist#mix_complete Mix
\ call alchemist#mix(<q-args>)
Expand Down
26 changes: 17 additions & 9 deletions alchemist.py
Expand Up @@ -30,6 +30,22 @@ def __init__(self, **kw):
def process_command(self, cmd, cmd_type=None):
if cmd_type == None:
cmd_type = cmd.split(" ")[0]

if cmd_type == 'XREF':
x = shlex.split('mix xref callers '+cmd.split(" ")[1])
return subprocess.check_output(x, cwd=self._cwd, universal_newlines=True)

sock = self._sock()
if cmd_type == 'COMPX':
result = self._send_compx(sock, cmd)
elif cmd_type == 'DEFLX':
result = self._send_deflx(sock, cmd)
else:
result = self._send_command(sock, cmd_type, cmd)

return result

def _sock(self):
server_log = self._get_running_server_log()
if server_log == None:
server_log = self._create_server_log()
Expand All @@ -45,15 +61,7 @@ def process_command(self, cmd, cmd_type=None):
self._run_alchemist_server(server_log)
connection = self._extract_connection_settings(server_log)
sock = self._connect(connection)

if cmd_type == 'COMPX':
result = self._send_compx(sock, cmd)
elif cmd_type == 'DEFLX':
result = self._send_deflx(sock, cmd)
else:
result = self._send_command(sock, cmd_type, cmd)

return result
return sock

def _log(self, text):
if self._debug == False:
Expand Down

0 comments on commit 967ab84

Please sign in to comment.