Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mvoidex committed Sep 7, 2015
1 parent 03e04e6 commit 4558000
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 10 deletions.
9 changes: 9 additions & 0 deletions autobuild.py
Expand Up @@ -22,6 +22,9 @@ def on_post_save(self, view):
auto_lint_enabled = get_setting('enable_auto_lint')
cabal_project_dir, cabal_project_name = get_cabal_project_dir_and_name_of_view(view)

# don't flycheck
self.fly_agent.nofly()

# auto build enabled and file within a cabal project
if auto_build_enabled and cabal_project_dir is not None:
view.window().run_command('sublime_haskell_build_auto')
Expand Down Expand Up @@ -55,6 +58,11 @@ def fly(self, view):
v[:] = [view]
self.event.set()

def nofly(self):
with self.view as v:
v[:] = []
self.event.set()

def run(self):
while True:
self.event.wait()
Expand All @@ -69,6 +77,7 @@ def run(self):
continue
auto_check_enabled = get_setting_async('enable_auto_check')
auto_lint_enabled = get_setting_async('enable_auto_lint')
sublime.set_timeout(lambda: view_.window().run_command('sublime_haskell_scan_contents'), 0)
if auto_check_enabled and auto_lint_enabled:
sublime.set_timeout(lambda: view_.window().run_command('sublime_haskell_check_and_lint', {'fly': True}), 0)
elif auto_check_enabled:
Expand Down
18 changes: 18 additions & 0 deletions autocomplete.py
Expand Up @@ -861,6 +861,24 @@ def run(self):
else:
show_status_message("inspector not connected", is_ok=False)

class SublimeHaskellScanContents(SublimeHaskellTextCommand):
"""
Scan module contents
"""
def run(self, edit, filename = None):
self.current_file_name = filename or self.view.file_name()
self.status_msg = status_message_process("Scanning {0}".format(self.current_file_name), priority = 3)
self.status_msg.start()

def on_resp(r):
self.status_msg.stop()

def on_err(r):
self.status_msg.fail()
self.status_msg.stop()

hsdev_client.scan(contents = {self.current_file_name: self.view.substr(sublime.Region(0, self.view.size()))}, on_response = on_resp, on_error = on_err)

class SublimeHaskellInferDocs(SublimeHaskellTextCommand):
"""
Infer types and scan docs for current module
Expand Down
28 changes: 18 additions & 10 deletions hsdev.py
Expand Up @@ -477,7 +477,7 @@ def __init__(self, port = 4567):
self.listener = None
self.hsdev_address = None
self.autoconnect = True
self.map = {}
self.map = LockedObject({})
self.id = 1

self.connect_fun = None
Expand Down Expand Up @@ -640,7 +640,8 @@ def set_connected(self):
log('HsDev.set_connected called while not in connecting state', log_debug)

def on_receive(self, id, command, on_response = None, on_notify = None, on_error = None):
self.map[id] = HsDevCallbacks(id, command, on_response, on_notify, on_error)
with self.map as m:
m[id] = HsDevCallbacks(id, command, on_response, on_notify, on_error)

def verify_connected(self):
if self.is_connected():
Expand All @@ -659,10 +660,11 @@ def connection_lost(self, fn, e):
call_callback(self.on_disconnected, name = 'HsDev.on_disconnected')

# send error to callbacks
for on_msg in self.map.values():
on_msg.on_error('connection lost')
with self.map as m:
for on_msg in m.values():
on_msg.on_error('connection lost')
m.clear()

self.map = {}
self.id = 1
self.part = ''

Expand Down Expand Up @@ -723,16 +725,21 @@ def listen(self):
try:
resp = json.loads(self.get_response())
if 'id' in resp:
if resp['id'] in self.map:
callbacks = self.map[resp['id']]
callbacks = None
with self.map as m:
if resp['id'] in m:
callbacks = m[resp['id']]
if callbacks:
if 'notify' in resp:
callbacks.call_notify(resp['notify'])
if 'error' in resp:
callbacks.call_error(resp['error'], resp.get('details'))
self.map.pop(resp['id'])
with self.map as m:
m.pop(resp['id'])
if 'result' in resp:
callbacks.call_response(resp['result'])
self.map.pop(resp['id'])
with self.map as m:
m.pop(resp['id'])
except Exception as e:
self.connection_lost('listen', e)
return
Expand All @@ -755,12 +762,13 @@ def ping(self):
return cmd('ping', [], {}, lambda r: r and ('message' in r) and (r['message'] == 'pong'))

@async_command
def scan(self, cabal = None, sandboxes = [], projects = [], files = [], paths = [], ghc = [], docs = False, infer = False):
def scan(self, cabal = None, sandboxes = [], projects = [], files = [], paths = [], ghc = [], contents = {}, docs = False, infer = False):
opts = concat_opts([
(cabal, {'cabal': None}),
(sandboxes, {'sandbox': sandboxes}),
(projects, {'project': projects}),
(files, {'file': files}),
(contents, {'data': json.dumps(contents)}),
(paths, {'path': paths}),
(ghc, {'ghc': ghc}),
(docs, {'docs': None}),
Expand Down

0 comments on commit 4558000

Please sign in to comment.