Permalink
Browse files

Lint: PEP8 and pyflakes warnings (using SublimeLinter)

  • Loading branch information...
1 parent b21640c commit bd11efb2e0b07d3e21e91dff845c8d24e31edc85 @nh2 nh2 committed Jan 12, 2013
Showing with 133 additions and 54 deletions.
  1. +3 −3 autobuild.py
  2. +27 −19 autocomplete.py
  3. +41 −18 cabalbuild.py
  4. +12 −6 ghcmod.py
  5. +2 −1 haskell_type.py
  6. +15 −0 parseoutput.py
  7. +2 −1 stylishhaskell.py
  8. +31 −6 sublime_haskell_common.py
View
@@ -1,8 +1,7 @@
-import os
-import sublime
import sublime_plugin
-from sublime_haskell_common import attach_sandbox, get_cabal_project_dir_and_name_of_view, call_and_wait, log, get_setting
+from sublime_haskell_common import attach_sandbox, get_cabal_project_dir_and_name_of_view, get_setting
+
class SublimeHaskellAutobuild(sublime_plugin.EventListener):
def on_post_save(self, view):
@@ -22,6 +21,7 @@ def on_post_save(self, view):
elif auto_lint_enabled:
view.window().run_command('sublime_haskell_ghc_mod_lint')
+
def current_cabal_build():
"""Current cabal build command"""
args = []
View
@@ -3,11 +3,10 @@
import re
import sublime
import sublime_plugin
-import subprocess
import threading
import time
-from sublime_haskell_common import PACKAGE_PATH, get_setting, get_setting_async, get_cabal_project_dir_of_file, get_cabal_project_dir_of_view, call_and_wait, call_ghcmod_and_wait, log, wait_for_window, output_error, get_settings, attach_sandbox, is_enabled_haskell_command, get_cabal_in_dir
+from sublime_haskell_common import PACKAGE_PATH, get_setting, get_cabal_project_dir_of_file, call_and_wait, call_ghcmod_and_wait, log, wait_for_window, output_error, get_settings, is_enabled_haskell_command, get_cabal_in_dir
# Completion text longer than this is ellipsized:
MAX_COMPLETION_LENGTH = 37
@@ -46,12 +45,14 @@ def get_line_contents(view, location):
"""
return view.substr(sublime.Region(view.line(location).a, location))
+
def get_line_contents_before_region(view, region):
"""
Returns the of the line before the given region (including it).
"""
return view.substr(sublime.Region(view.line(region).a, region.b))
+
def get_qualified_name(s):
"""
'bla bla bla Data.List.fo' -> ('Data.List', 'Data.List.fo')
@@ -62,6 +63,7 @@ def get_qualified_name(s):
filtered = map(lambda s: filter(lambda c: c.isalpha() or c.isdigit() or c == '_', s), quals)
return ('.'.join(filtered[0:len(filtered) - 1]), '.'.join(filtered))
+
# Autocompletion data
class AutoCompletion(object):
"""Information for completion"""
@@ -152,7 +154,7 @@ def get_completions(self, view, prefix, locations):
if file_info['moduleName'] in moduleImports:
for d in file_info['declarations']:
identifier = d['identifier']
- declaration_info = d['info']
+ #declaration_info = d['info']
# TODO: Show the declaration info somewhere.
completions.append((identifier[:MAX_COMPLETION_LENGTH], identifier))
@@ -180,7 +182,7 @@ def get_import_completions(self, view, prefix, locations):
# TODO handle multiple selections
match_language = LANGUAGE_RE.match(line_contents)
if match_language:
- return [ (unicode(c),) * 2 for c in self.language_completions ]
+ return [(unicode(c),) * 2 for c in self.language_completions]
# Autocompletion for import statements
if get_setting('auto_complete_imports'):
@@ -224,11 +226,12 @@ def module_next_name(mname):
pref = Control.Con, mname = Control.Concurrent.MVar, result = Concurrent
"""
return mname.split('.')[len(qualified_prefix.split('.')) - 1]
- return list(set([ (unicode(module_next_name(m)),) * 2 for m in self.module_completions if m.startswith(qualified_prefix) ]))
+ return list(set((unicode(module_next_name(m)),) * 2 for m in self.module_completions if m.startswith(qualified_prefix)))
autocompletion = AutoCompletion()
+
class SublimeHaskellBrowseDeclarations(sublime_plugin.WindowCommand):
def run(self):
self.names = []
@@ -237,7 +240,7 @@ def run(self):
if 'declarations' in v:
for d in v['declarations']:
self.names.append(d['identifier'])
- self.declarations.append(v['moduleName'] + ': ' + d['identifier'] + ' ' + d['info'])
+ self.declarations.append(v['moduleName'] + ': ' + d['identifier'] + ' ' + d['info'])
for m, decls in autocompletion.std_info.items():
for decl in decls:
self.names.append(decl)
@@ -259,6 +262,7 @@ def on_done(self, idx):
def is_enabled(self):
return is_enabled_haskell_command(False)
+
class SublimeHaskellGoToAnyDeclaration(sublime_plugin.WindowCommand):
def run(self):
self.files = []
@@ -278,11 +282,13 @@ def on_done(self, idx):
def is_enabled(self):
return is_enabled_haskell_command(False)
+
class SublimeHaskellReinspectAll(sublime_plugin.WindowCommand):
def run(self):
autocompletion.clear_inspected()
SublimeHaskellAutocomplete.inspector.mark_all_files(self.window)
+
class SublimeHaskellGoToDeclaration(sublime_plugin.TextCommand):
def run(self, edit):
word_region = self.view.word(self.view.sel()[0])
@@ -292,12 +298,12 @@ def run(self, edit):
modules = []
- if not no_module: # Get modules by alias
+ if not no_module: # Get modules by alias
modules = [module_word]
modules.extend(autocompletion.unalias_module_name(self.view, module_word))
ident = self.view.substr(word_region)
- full_qualified_name = ident if no_module else '.'.join([module_word, ident]) # goto module
+ full_qualified_name = ident if no_module else '.'.join([module_word, ident]) # goto module
self.module_files = []
module_candidates = []
@@ -344,6 +350,7 @@ def on_done(self, idx):
def is_enabled(self):
return is_enabled_haskell_command(False)
+
class InspectorAgent(threading.Thread):
def __init__(self):
# Call the superclass constructor:
@@ -462,7 +469,8 @@ def _refresh_project_info(self, cabal_dir, project_name, cabal_file):
autocompletion.projects[project_name] = {
'dir': cabal_dir,
'cabal': os.path.basename(cabal_file),
- 'executables': new_info['executables'] }
+ 'executables': new_info['executables'],
+ }
def _refresh_module_info(self, filename):
"Rebuild module information for the specified file."
@@ -516,6 +524,7 @@ def _get_inspection_time_of_file(self, filename):
except KeyError:
return 0.0
+
def list_files_in_dir_recursively(base_dir):
"""Return a list of a all files in a directory, recursively.
The files will be specified by full paths."""
@@ -525,6 +534,7 @@ def list_files_in_dir_recursively(base_dir):
files.append(os.path.join(base_dir, dirname, filename))
return files
+
class SublimeHaskellAutocomplete(sublime_plugin.EventListener):
inspector = InspectorAgent()
inspector.start()
@@ -534,9 +544,10 @@ def __init__(self):
autocompletion.module_completions = []
self.local_settings = {
- 'enable_ghc_mod' : None,
- 'use_cabal_dev' : None,
- 'cabal_dev_sandbox' : None }
+ 'enable_ghc_mod': None,
+ 'use_cabal_dev': None,
+ 'cabal_dev_sandbox': None,
+ }
for s in self.local_settings.keys():
self.local_settings[s] = get_setting(s)
@@ -582,13 +593,13 @@ def get_special_completions(self, view, prefix, locations):
# TODO handle multiple selections
match_language = LANGUAGE_RE.match(line_contents)
if match_language:
- return [ (unicode(c),) * 2 for c in autocompletion.language_completions ]
+ return [(unicode(c),) * 2 for c in autocompletion.language_completions]
# Autocompletion for import statements
if get_setting('auto_complete_imports'):
match_import = IMPORT_RE.match(line_contents)
if match_import:
- import_completions = [ (unicode(c),) * 2 for c in autocompletion.module_completions ]
+ import_completions = [(unicode(c),) * 2 for c in autocompletion.module_completions]
# Right after "import "? Propose "qualified" as well!
qualified_match = IMPORT_QUALIFIED_POSSIBLE_RE.match(line_contents)
@@ -606,9 +617,6 @@ def on_query_completions(self, view, prefix, locations):
# Only suggest symbols if the current file is part of a Cabal project.
# TODO: Only suggest symbols from within this project.
- cabal_dir = get_cabal_project_dir_of_view(view)
- # if cabal_dir is not None:
-
completions = autocompletion.get_import_completions(view, prefix, locations)
if not completions:
@@ -620,12 +628,12 @@ def on_query_completions(self, view, prefix, locations):
# into completion because that wipes all default Sublime completions:
# See http://www.sublimetext.com/forum/viewtopic.php?t=8659
# TODO: work around this
- return [ c for c in completions if NO_SPECIAL_CHARS_RE.match(c[0]) ]
+ return [c for c in completions if NO_SPECIAL_CHARS_RE.match(c[0])]
return []
def on_new(self, view):
- filename = view.file_name();
+ filename = view.file_name()
if filename:
SublimeHaskellAutocomplete.inspector.mark_file_dirty(filename)
Oops, something went wrong.

0 comments on commit bd11efb

Please sign in to comment.