Skip to content
Browse files

Fixed browse module for module in sources, catching OSError in hdevto…

…ols.admin, fixed 'symbol info' behaviour on unknown symbol
  • Loading branch information...
1 parent 870cf1a commit a31e3a43f9887cc9029620b9bcaf34b34d2341d5 @mvoidex mvoidex committed
Showing with 51 additions and 17 deletions.
  1. +21 −7 autocomplete.py
  2. +2 −2 ghci.py
  3. +4 −0 ghcmod.py
  4. +24 −8 hdevtools.py
View
28 autocomplete.py
@@ -415,7 +415,7 @@ def run(self, edit, filename = None, module_name = None, decl = None):
if decl in m.declarations:
self.show_symbol_info(m.declarations[decl])
else:
- show_status_message('Symbol {0} not found in {1}'.format(decl, ))
+ show_status_message('Symbol {0} not found in {1}'.format(decl, filename))
else:
show_status_message('No info about module {0}'.format(module_name))
return
@@ -494,7 +494,9 @@ def run(self, edit, filename = None, module_name = None, decl = None):
elif import_list:
# Allow user to select module
self.candidates = [(m, ident) for m in import_list]
- self.view.window().show_quick_panel(['{0}.{1}'.format(m, ident) for m in import_list], self.on_candidate_selected)
+ self.view.window().show_quick_panel([
+ ['Select imported module', 'from where {0} may be imported'.format(ident)],
+ ['No, thanks']], self.on_import_selected)
return
show_status_message('Symbol {0} not found'.format(ident), False)
@@ -516,12 +518,16 @@ def on_done(self, idx):
return
self.show_symbol_info(self.candidates[idx])
+ def on_import_selected(self, idx):
+ if idx == 0: # Yes, select imported module
+ self.view.window().show_quick_panel(['{0}.{1}'.format(i[0], i[1]) for i in self.candidates], self.on_candidate_selected)
+
def on_candidate_selected(self, idx):
if idx == -1:
return
(module_name, ident_name) = self.candidates[idx]
- info = util.symbol_info(module_name, ident_name)
+ info = util.symbol_info(self.view.file_name(), module_name, ident_name)
if info:
self.show_symbol_info(info)
else:
@@ -607,9 +613,16 @@ def on_symbol_selected(self, idx):
if idx == -1:
return
- self.window.active_view().run_command('sublime_haskell_symbol_info', {
- 'module_name': self.candidates[idx].module.name,
- 'decl': self.candidates[idx].name })
+ candidate = self.candidates[idx]
+
+ if candidate.module.location:
+ self.window.active_view().run_command('sublime_haskell_symbol_info', {
+ 'filename': candidate.module.location.filename,
+ 'decl': candidate.name })
+ else:
+ self.window.active_view().run_command('sublime_haskell_symbol_info', {
+ 'module_name': candidate.module.name,
+ 'decl': candidate.name })
class SublimeHaskellGoToDeclaration(sublime_plugin.TextCommand):
def run(self, edit):
@@ -828,7 +841,8 @@ def _load_standard_module(self, module_name, cabal = None):
if module_name not in autocompletion.database.get_cabal_modules(cabal):
try:
m = util.browse_module(module_name, cabal = cabal)
- autocompletion.database.add_module(m)
+ if m:
+ autocompletion.database.add_module(m)
except Exception as e:
log('Inspecting in-cabal module {0} failed: {1}'.format(module_name, e))
View
4 ghci.py
@@ -48,7 +48,7 @@ def parse_info(name, contents):
return None
-def ghci_info(module, name):
+def ghci_info(module, name, cabal = None):
"""
Returns info for name as symbol
"""
@@ -58,7 +58,7 @@ def ghci_info(module, name):
":q"]
ghc_opts = get_setting_async('ghc_opts')
- (exit_code, stdout, stderr) = call_and_wait_with_input(ghci_append_package_db(['ghci'] + ghc_opts), "\n".join(ghci_cmd))
+ (exit_code, stdout, stderr) = call_and_wait_with_input(ghci_append_package_db(['ghci'] + ghc_opts, cabal = cabal), "\n".join(ghci_cmd))
stdout = crlf2lf(stdout)
if exit_code == 0:
return parse_info(name, stdout)
View
4 ghcmod.py
@@ -149,6 +149,10 @@ def ghcmod_browse_module(module_name, cabal = None):
Returns symbols.Module with all declarations
"""
contents = call_ghcmod_and_wait(['browse', '-d', module_name], cabal = cabal).splitlines()
+
+ if not contents:
+ return None
+
m = symbols.Module(module_name, cabal = cabal)
functionRegex = r'(?P<name>\w+)\s+::\s+(?P<type>.*)'
View
32 hdevtools.py
@@ -59,14 +59,30 @@ def admin(cmds, wait = False, **popen_kwargs):
command = ["hdevtools", "admin"] + cmds
- if wait:
- (exit_code, stdout, stderr) = call_and_wait(command, **popen_kwargs)
- if exit_code == 0:
- return stdout
- return ''
- else:
- call_no_wait(command, **popen_kwargs)
- return ''
+ try:
+ if wait:
+ (exit_code, stdout, stderr) = call_and_wait(command, **popen_kwargs)
+ if exit_code == 0:
+ return stdout
+ return ''
+ else:
+ call_no_wait(command, **popen_kwargs)
+ return ''
+
+ except OSError as e:
+ if e.errno == errno.ENOENT:
+ 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.")
+
+ set_setting_async('enable_hdevtools', False)
+
+ return None
+ except Exception as e:
+ log('calling to hdevtools fails with {0}'.format(e))
+ return None
def is_running():
r = admin(['--status'], wait = True)

0 comments on commit a31e3a4

Please sign in to comment.
Something went wrong with that request. Please try again.