This repository has been archived by the owner on Sep 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
elixir_sense_client
executable file
·84 lines (72 loc) · 3.09 KB
/
elixir_sense_client
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python
from __future__ import print_function
import os, sys, getopt
from elixir_sense import ElixirSenseClient
debug = False
read_stdin = vars(__builtins__).get('raw_input',input)
def alchemist_help():
return """Usage: alchemist_client -c <command> -t <command_type> -d <working_directory> -a <alchemist_script>
a client that talks to alchemist_server through network socket
Options:
-c, --command="" Command that is going to be sent to alchemist server if nothing is provided read a line from STDIN
-t, --command-type="" Command type, if it's not provided, extract it from command
-d, --directory= Directory that alchemist server should process code from
-a, --alchemist-server="" Path to alchemist server `run.exs`, if it's not provided load it from alchemist-server/run.exs
-s, --source="" Path to source code for Erlang and Elixir. It's used to find the path in DEFLX command
-o, --elixir-otp-src="" Path to source code for Erlang and Elixir. It's used to find the path in DEFLX command
--colors=true Enable/Disable ansi
"""
def main(argv):
request = ""
line = 0
column = 0
cwd = ""
alchemist_script = ""
ansi = True
elixir_otp_src = ""
source = ""
try:
opts, args = getopt.getopt(argv,"hr:l:c:d:o:",["request=","line=", "column=", "directory=", "alchemist-server=", "colors=", "elixir-otp-src="])
except getopt.GetoptError:
print(alchemist_help())
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print(alchemist_help())
sys.exit()
elif opt in ("-r", "--request"):
request = arg
elif opt in ("-l", "--line"):
line = arg
elif opt in ("-c", "--column"):
column = arg
elif opt in ("-d", "--directory"):
cwd = arg
elif opt in ("-a", "--alchemist-server"):
alchemist_script = arg
elif opt in ("-o", "--elixir-otp-src"):
elixir_otp_src = arg
elif opt in ("--colors"):
if arg == "false":
ansi = False
if os.path.exists(cwd.strip()) == False:
raise Exception("working directory [%s] doesn't exist" % cwd)
cwd = os.path.abspath(cwd)
source = sys.stdin.read()
if alchemist_script == "":
alchemist_script = "%s/elixir_sense/run.exs" % where_am_i()
if "" in [request, alchemist_script, request, line, column]:
print("Invalid command, alchemist_script or working directory")
print(alchemist_help())
sys.exit(2)
sense = ElixirSenseClient(debug=debug, cwd=cwd, ansi=ansi, elixir_sense_script=alchemist_script, elixir_otp_src=elixir_otp_src)
response = sense.process_command(request, source, line ,column)
sense._log("response:\n%s" % response)
if sys.version_info.major == 2:
print("%s" % response.encode('utf-8'), end="")
else:
sys.stdout.buffer.write(response.encode('utf-8'))
def where_am_i():
return os.path.dirname(os.path.realpath(__file__))
if __name__ == "__main__":
main(sys.argv[1:])