Browse files

Checking if hdevtools enabled

  • Loading branch information...
1 parent 76d243e commit 3c23066ad3ac827a4b36588654fa4ba30ce128c2 @mvoidex mvoidex committed Mar 29, 2013
Showing with 28 additions and 23 deletions.
  1. +12 −5 hdevtools.py
  2. +9 −7 hdocs.py
  3. +7 −11 util.py
View
17 hdevtools.py
@@ -19,6 +19,8 @@ def call_hdevtools_and_wait(arg_list, filename = None, cabal = None):
Calls hdevtools with the given arguments.
Shows a sublime error message if hdevtools is not available.
"""
+ if not hdevtools_enabled():
+ return None
ghc_opts_args = get_ghc_opts_args(filename, cabal = cabal)
hdevtools_socket = get_setting_async('hdevtools_socket')
@@ -37,11 +39,11 @@ def call_hdevtools_and_wait(arg_list, filename = None, cabal = None):
except OSError as e:
if e.errno == errno.ENOENT:
- output_error(sublime.active_window(),
+ sublime.set_timeout(lambda: output_error(sublime.active_window(),
"SublimeHaskell: hdevtools was not found!\n"
+ "It's used for 'symbol info' and type inference\n"
+ "Try adjusting the 'add_to_PATH' setting.\n"
- + "'enable_hdevtools' automatically set to False.")
+ + "'enable_hdevtools' automatically set to False."), 0)
set_setting_async('enable_hdevtools', False)
@@ -52,6 +54,9 @@ def call_hdevtools_and_wait(arg_list, filename = None, cabal = None):
return None
def admin(cmds, wait = False, **popen_kwargs):
+ if not hdevtools_enabled():
+ return None
+
hdevtools_socket = get_setting_async('hdevtools_socket')
if hdevtools_socket:
@@ -86,7 +91,7 @@ def admin(cmds, wait = False, **popen_kwargs):
def is_running():
r = admin(['--status'], wait = True)
- if re.search(r'running', r):
+ if r and re.search(r'running', r):
return True
else:
return False
@@ -106,8 +111,7 @@ def hdevtools_check(filename, cabal = None):
"""
Uses hdevtools to check file
"""
- contents = call_hdevtools_and_wait(['check', filename], filename = filename, cabal = cabal)
- return contents
+ return call_hdevtools_and_wait(['check', filename], filename = filename, cabal = cabal)
def hdevtools_type(filename, line, column, cabal = None):
"""
@@ -122,3 +126,6 @@ def start_hdevtools():
def stop_hdevtools():
admin(["--stop-server"])
+
+def hdevtools_enabled():
+ return get_setting_async('enable_hdevtools') == True
View
16 hdocs.py
@@ -8,6 +8,9 @@
from SublimeHaskell.sublime_haskell_common import *
def call_hdocs_and_wait(args, filename = None, cabal = None):
+ if not hdocs_enabled():
+ return None
+
ghc_opts_args = get_ghc_opts_args(filename, cabal = cabal)
source_dir = get_source_dir(filename)
@@ -24,7 +27,7 @@ def call_hdocs_and_wait(args, filename = None, cabal = None):
except OSError as e:
if e.errno == errno.ENOENT:
- sublime.set_timeout(lambda: output_error(sublime.active_window(), "SublimeHaskell: hdocs was not found!\n 'enable_hdocs' is set to False"), 0)
+ sublime.set_timeout(lambda: output_error(sublime.active_window(), "SublimeHaskell: hdocs was not found!\n'enable_hdocs' is set to False"), 0)
set_setting_async('enable_hdocs', False)
return None
@@ -34,7 +37,7 @@ def call_hdocs_and_wait(args, filename = None, cabal = None):
return None
def module_docs(module_name, cabal = None):
- if not enabled():
+ if not hdocs_enabled():
return None
try:
@@ -48,14 +51,13 @@ def module_docs(module_name, cabal = None):
return None
def symbol_docs(module_name, symbol_name, cabal = None):
- if not enabled():
+ if not hdocs_enabled():
return None
- contents = call_hdocs_and_wait(['docs', module_name, symbol_name], cabal = cabal)
- return contents
+ return call_hdocs_and_wait(['docs', module_name, symbol_name], cabal = cabal)
def load_module_docs(module):
- if not enabled():
+ if not hdocs_enabled():
return False
if module.location:
@@ -73,5 +75,5 @@ def load_module_docs(module):
return False
-def enabled():
+def hdocs_enabled():
return get_setting_async('enable_hdocs') == True
View
18 util.py
@@ -15,13 +15,13 @@
import SublimeHaskell.sublime_haskell_common as common
import SublimeHaskell.symbols as symbols
-def symbol_info(filename, module_name, symbol_name, cabal = None):
+def symbol_info(filename, module_name, symbol_name, cabal = None, no_ghci = False):
result = None
- if common.get_setting_async('enable_hdevtools'):
+ if hdevtools.hdevtools_enabled():
result = hdevtools.hdevtools_info(filename, symbol_name, cabal = cabal)
- if not result:
+ if not result and common.get_setting_async('enable_ghc_mod'):
result = ghcmod.ghcmod_info(filename, module_name, symbol_name, cabal = cabal)
- if not result and filename:
+ if not result and not filename and not no_ghci:
result = ghci.ghci_info(module_name, symbol_name, cabal = cabal)
return result
@@ -32,19 +32,15 @@ def load_docs(decl):
if decl.docs is None:
decl.docs = haskell_docs.haskell_docs(decl.module.name, decl.name)
-def refine_type(decl, hdevtools_only = True):
+def refine_type(decl, no_ghci = True):
"""
Refine type for sources decl
"""
- hdevtools_enabled = common.get_setting_async('enable_hdevtools')
+ ghcmod_enabled = common.get_setting_async('enable_ghc_mod')
if decl.location:
if decl.what == 'function' and not decl.type:
- info = None
- if hdevtools_only and hdevtools_enabled:
- info = hdevtools.hdevtools_info(decl.location.filename, decl.name)
- else:
- info = symbol_info(decl.location.filename, decl.module.name, decl.name)
+ info = symbol_info(decl.location.filename, decl.module.name, decl.name, None, no_ghci = no_ghci)
if info:
decl.type = info.type

0 comments on commit 3c23066

Please sign in to comment.