Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 111 lines (87 sloc) 3.306 kb
4f839ae @mvoidex Integrate hdevtools #30
mvoidex authored
1 import os
2 import re
3 import sublime
4 import sublime_plugin
5 import subprocess
6 import threading
7
8 if int(sublime.version()) < 3000:
9 from sublime_haskell_common import *
b91dcb0 @mvoidex Added util module
mvoidex authored
10 from ghci import parse_info
4f839ae @mvoidex Integrate hdevtools #30
mvoidex authored
11 import symbols
12 else:
13 from SublimeHaskell.sublime_haskell_common import *
b91dcb0 @mvoidex Added util module
mvoidex authored
14 from SublimeHaskell.ghci import parse_info
4f839ae @mvoidex Integrate hdevtools #30
mvoidex authored
15 import SublimeHaskell.symbols as symbols
16
17 def call_hdevtools_and_wait(arg_list, filename = None, cabal = None):
18 """
19 Calls hdevtools with the given arguments.
20 Shows a sublime error message if hdevtools is not available.
21 """
22
b91dcb0 @mvoidex Added util module
mvoidex authored
23 ghc_opts_args = get_ghc_opts_args(filename)
4f839ae @mvoidex Integrate hdevtools #30
mvoidex authored
24 hdevtools_socket = get_setting_async('hdevtools_socket')
2216239 @mvoidex Fixed another typo
mvoidex authored
25 source_dir = get_source_dir(filename)
4f839ae @mvoidex Integrate hdevtools #30
mvoidex authored
26
27 if hdevtools_socket:
28 arg_list.append('--socket={0}'.format(hdevtools_socket))
29
30 try:
31 command = ['hdevtools'] + arg_list + ghc_opts_args
32
7fb3078 @mvoidex Fixed column calc
mvoidex authored
33 exit_code, out, err = call_and_wait(['hdevtools'] + arg_list + ghc_opts_args, cwd = source_dir)
4f839ae @mvoidex Integrate hdevtools #30
mvoidex authored
34
35 if exit_code != 0:
36 raise Exception("hdevtools exited with status %d and stderr: %s" % (exit_code, err))
37
38 return crlf2lf(out)
39
40 except OSError as e:
41 if e.errno == errno.ENOENT:
42 output_error(sublime.active_window(),
43 "SublimeHaskell: hdevtools was not found!\n"
44 + "It's used for 'symbol info' and type inference\n"
45 + "Try adjusting the 'add_to_PATH' setting.\n"
46 + "'enable_hdevtools' automatically set to False.")
47
48 set_setting_async('enable_hdevtools', False)
49
50 return None
51
e320cd6 @mvoidex Minor fixes
mvoidex authored
52 except Exception as e:
53 log('calling to hdevtools fails with {0}'.format(e))
54 return None
55
4f839ae @mvoidex Integrate hdevtools #30
mvoidex authored
56 def admin(cmds, wait = False, **popen_kwargs):
57 hdevtools_socket = get_setting_async('hdevtools_socket')
58
59 if hdevtools_socket:
60 cmds.append('--socket={0}'.format(hdevtools_socket))
61
62 command = ["hdevtools", "admin"] + cmds
63
64 if wait:
65 (exit_code, stdout, stderr) = call_and_wait(command, **popen_kwargs)
66 if exit_code == 0:
67 return stdout
68 return ''
69 else:
70 call_no_wait(command, **popen_kwargs)
71 return ''
72
73 def is_running():
74 r = admin(['--status'], wait = True)
75 if re.search(r'running', r):
76 return True
77 else:
78 return False
79
80 def start_server():
81 if not is_running():
82 admin(["--start-server"])
83
84 def hdevtools_info(filename, symbol_name, cabal = None):
85 """
86 Uses hdevtools info filename symbol_name to get symbol info
87 """
88 contents = call_hdevtools_and_wait(['info', filename, symbol_name], filename = filename, cabal = cabal)
4bd1189 @mvoidex Fixed minor bug
mvoidex authored
89 return parse_info(symbol_name, contents) if contents else None
4f839ae @mvoidex Integrate hdevtools #30
mvoidex authored
90
91 def hdevtools_check(filename, cabal = None):
92 """
93 Uses hdevtools to check file
94 """
95 contents = call_hdevtools_and_wait(['check', filename], filename = filename, cabal = cabal)
96 return contents
97
98 def hdevtools_type(filename, line, column, cabal = None):
99 """
100 Uses hdevtools to infer type
101 """
102 return call_hdevtools_and_wait(['type', filename, str(line), str(column)], filename = filename, cabal = cabal)
103
74c3b48 @mvoidex Changed hdevtools init one more time
mvoidex authored
104 def start_hdevtools():
4f839ae @mvoidex Integrate hdevtools #30
mvoidex authored
105 thread = threading.Thread(
106 target=start_server)
107 thread.start()
108
74c3b48 @mvoidex Changed hdevtools init one more time
mvoidex authored
109 def stop_hdevtools():
110 admin(["--stop-server"])
Something went wrong with that request. Please try again.