Skip to content

Commit

Permalink
more issue fixes
Browse files Browse the repository at this point in the history
- Output window after a build completes now reappears.
- Removed maximum hsdev version number. It didn't really make much
  sense, when I thought about it for a while.
- Patch hsdev command line arguments (and add a new setting) to support
  simple-log's simplified "--log-level".
  • Loading branch information
B. Scott Michel committed Apr 28, 2017
1 parent a9fa16d commit f4f56a7
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 30 deletions.
14 changes: 11 additions & 3 deletions Settings/SublimeHaskell.sublime-settings
Expand Up @@ -161,7 +161,15 @@
// Log level, 0 — no log, 1 — errors, 2 — warnings, 3 — info messages, 4 — debug, 5 — trace
"log": 1,

// hsdev's logging: 'use default' (somewhat verbose, informational), 'use silent' (quiet)
// This is a somewhat magic setting that comes from the Haskell 'simple-log' documentation.
"hsdev_log_config": "use silent"
// hsdev logging output:
//
// !!!PAY ATTENTION TO YOUR HSDEV VERSION!!!
//
// hsdev version 0.2.2.0 and below: The "hsdev_log_config" preference controls hsdev's logging. It has several interesting
// values: 'use default' (somewhat verbose, informational), 'use silent' (quiet)
//
// hsdev version 0.2.3.0 and higher: The "hsdev_log_level" preference controls hsdev's logging. Valid values are
// 'trace', 'debug', 'info', 'warning', 'error' and 'fatal'.
"hsdev_log_config": "use silent",
"hsdev_log_level": "warning"
}
59 changes: 38 additions & 21 deletions hsdev/agent.py
Expand Up @@ -22,7 +22,6 @@

HSDEV_DEFAULT_PORT = 4567
HSDEV_MIN_VER = [0, 2, 0, 0] # minimum hsdev version
HSDEV_MAX_VER = [0, 2, 3, 0] # maximum hsdev version

def hsdev_version():
retval = None
Expand All @@ -47,8 +46,12 @@ def show_version(ver):
return '.'.join(map(str, ver))


def check_version(ver, minimal, maximal):
return ver is not None and ver >= minimal and (not maximal or ver < maximal)
def check_version(ver, minimal):
return ver is not None and ver >= minimal


def patch_simple_log(ver):
return ver >= [0, 2, 3, 1]


def format_error_details(details):
Expand Down Expand Up @@ -99,7 +102,7 @@ class HsDevProcess(threading.Thread):
`stderr` file objects -- `hsdev` can be quite chatty, which leads to deadlock when `hsdev` has filled the pipe
between SublimeText and itself.
"""
def __init__(self, port=HSDEV_DEFAULT_PORT, cache=None, log_file=None, log_config=None):
def __init__(self, port, version, cache=None, log_file=None, log_config=None):
super().__init__()
self.process = None
self.drain_stdout = None
Expand All @@ -112,13 +115,17 @@ def __init__(self, port=HSDEV_DEFAULT_PORT, cache=None, log_file=None, log_confi
self.cache = cache
self.log_file = log_file
self.log_config = log_config
self.version = version

def run(self):
new_simple_log = patch_simple_log(self.version)

cmd = concat_args([(True, ["hsdev", "run"]),
(self.port, ["--port", str(self.port)]),
(self.cache, ["--cache", self.cache]),
(self.log_file, ["--log", self.log_file]),
(self.log_config, ["--log-config", self.log_config])])
(not new_simple_log and self.log_config, ["--log-config", self.log_config]),
(new_simple_log and self.log_config, ["--log-level", self.log_config])])

Logging.log('hsdev command: {0}'.format(cmd), Logging.LOG_DEBUG)

Expand All @@ -130,7 +137,7 @@ def run(self):
hsdev_proc = ProcHelper.ProcHelper(cmd)
if hsdev_proc.process is None:
Logging.log('Failed to create hsdev process', Logging.LOG_ERROR)
return None
return

# Use TextIOWrapper here because it combines decoding with newline handling,
# which means less to maintain.
Expand All @@ -139,11 +146,15 @@ def run(self):

while True:
srvout = hsdev_proc.process.stdout.readline().strip()
Logging.log('hsdev initial output: {0}'.format(srvout), Logging.LOG_DEBUG)
start_confirm = re.match(r'^.*?hsdev> Server started at port (?P<port>\d+)$', srvout)
if start_confirm:
Logging.log('hsdev server started at port {0}'.format(start_confirm.group('port')))
break
if srvout != '':
Logging.log('hsdev initial output: {0}'.format(srvout), Logging.LOG_DEBUG)
start_confirm = re.match(r'[Ss]erver started at port (?P<port>\d+)$', srvout)
if start_confirm:
Logging.log('hsdev server started at port {0}'.format(start_confirm.group('port')))
break
else:
Logging.log('hsdev initial output: Got EOF. Server not started successfully.')
return

self.process = hsdev_proc.process
self.drain_stdout = OutputCollector.DescriptorDrain('hsdev stdout', self.process.stdout)
Expand All @@ -157,6 +168,7 @@ def run(self):
self.drain_stdout.stop()
self.drain_stderr.stop()
HsCallback.call_callback(self.on_exit, name='HsDevProcess.on_exit')

self.stop_event.clear()

def active(self):
Expand Down Expand Up @@ -475,17 +487,12 @@ class HsDevLocalAgent(HsDevAgent):

def __init__(self, port):
super().__init__("localhost", port)
self.hsdev_process = HsDevProcess(cache=os.path.join(Common.sublime_haskell_cache_path(), 'hsdev'),
log_file=os.path.join(Common.sublime_haskell_cache_path(), 'hsdev', 'hsdev.log'),
log_config=Settings.PLUGIN.hsdev_log_config)


def do_start_hsdev(self):
hsdev_ver = hsdev_version()
if hsdev_ver is None:
Common.output_error_async(sublime.active_window(), "\n".join(HsDevLocalAgent.hsdev_not_found))
return False
elif not check_version(hsdev_ver, HSDEV_MIN_VER, HSDEV_MAX_VER):
elif not check_version(hsdev_ver, HSDEV_MIN_VER):
Common.output_error_async(sublime.active_window(), "\n".join(HsDevLocalAgent.hsdev_wrong_version(hsdev_ver)))
return False
else:
Expand All @@ -502,12 +509,22 @@ def connected_():
self.client.link()

self.client.set_on_connected(connected_)

hsdev_log_settings = Settings.PLUGIN.hsdev_log_config
if patch_simple_log(hsdev_ver):
hsdev_log_settings = Settings.PLUGIN.hsdev_log_level

self.hsdev_process = HsDevProcess(port, hsdev_ver,
cache=os.path.join(Common.sublime_haskell_cache_path(), 'hsdev'),
log_file=os.path.join(Common.sublime_haskell_cache_path(), 'hsdev', 'hsdev.log'),
log_config=hsdev_log_settings)
self.hsdev_process.on_start = start_
self.hsdev_process.on_exit = exit_

self.hsdev_process.start()
self.hsdev_process.create()
return True
def do_start_hsdev(self):
self.hsdev_process.start()
self.hsdev_process.create()
return True


def do_stop_hsdev(self):
Expand All @@ -519,7 +536,7 @@ def do_stop_hsdev(self):
@staticmethod
def hsdev_wrong_version(version_str):
return ["SublimeHaskell: hsdev version is incorrect: {0}".format(show_version(version_str)),
"Required version: >= {0} and < {1}".format(show_version(HSDEV_MIN_VER), show_version(HSDEV_MAX_VER)),
"Required version: >= {0}".format(show_version(HSDEV_MIN_VER)),
"Update it by running 'cabal update' and 'cabal install hsdev'",
"",
"To supress this message and disable hsdev set 'enable_hsdev' to false"
Expand Down
6 changes: 5 additions & 1 deletion internals/output_collector.py
Expand Up @@ -106,7 +106,11 @@ def run(self):
if isinstance(line, bytearray):
line = Utils.decode_bytes(line)
line = line.rstrip()
print('<{0}> {1}'.format(self.label, line))
if line != '':
print('<{0}> {1}'.format(self.label, line))
else:
# Got EOF. Stop.
self.stop()

def stop(self):
self.stop_me.set()
2 changes: 2 additions & 0 deletions internals/settings.py
Expand Up @@ -58,6 +58,7 @@ class SetttingsContainer(object):
'hsdev_host': ('hsdev_host', 'localhost'),
'hsdev_local_process': ('hsdev_local_process', True),
'hsdev_log_config': ('hsdev_log_config', 'use silent'),
'hsdev_log_level': ('hsdev_log_level', 'warning'),
'hsdev_port': ('hsdev_port', 4567),
'inhibit_completions': ('inhibit_completions', False),
'inspect_modules': ('inspect_modules', True),
Expand Down Expand Up @@ -93,6 +94,7 @@ def __init__(self):
self.hsdev_host = None
self.hsdev_local_process = None
self.hsdev_log_config = None
self.hsdev_log_level = None
self.hsdev_port = None
self.inhibit_completions = None
self.inspect_modules = None
Expand Down
9 changes: 4 additions & 5 deletions parseoutput.py
Expand Up @@ -182,9 +182,8 @@ def show_output_result_text(view, msg, text, exit_code, base_dir):

Common.show_status_message_process(msg, success)
# Show panel if there is any text to show (without the part that we add)
if text:
if Settings.PLUGIN.show_error_window:
sublime.set_timeout(lambda: write_output(view, output, base_dir), 0)
if text and Settings.PLUGIN.show_error_window:
sublime.set_timeout(lambda: write_output(view, output, base_dir), 0)


def parse_output_messages_and_show(view, msg, base_dir, exit_code, stderr):
Expand Down Expand Up @@ -364,13 +363,13 @@ def mark_messages_in_view(messages, view):
sublime.HIDDEN)


def write_output(view, text, cabal_project_dir, panel_display=False):
def write_output(view, text, cabal_project_dir, panel_out=True):
"Write text to Sublime's output panel."
global ERROR_VIEW
ERROR_VIEW = Common.output_panel(view.window(), text,
panel_name=OUTPUT_PANEL_NAME,
syntax='HaskellOutputPanel',
panel_display=panel_display)
panel_display=panel_out)
ERROR_VIEW.settings().set("RESULT_FILE_REGEX", RESULT_FILE_REGEX)
ERROR_VIEW.settings().set("result_base_dir", cabal_project_dir)

Expand Down

0 comments on commit f4f56a7

Please sign in to comment.