Permalink
Browse files

Migrated to Sublime Text 3

  • Loading branch information...
1 parent 7809360 commit 5c0d422c1acd3883190e47e69a329e36a6a3cf42 @mvoidex mvoidex committed Mar 2, 2013
Showing with 173 additions and 69 deletions.
  1. +5 −1 autobuild.py
  2. +74 −31 autocomplete.py
  3. +10 −6 cabalbuild.py
  4. +7 −2 ghci.py
  5. +8 −3 ghcmod.py
  6. +6 −2 haskell_docs.py
  7. +6 −4 haskell_type.py
  8. +9 −8 parseoutput.py
  9. +4 −1 stylishhaskell.py
  10. +37 −9 sublime_haskell_common.py
  11. +7 −2 symbols.py
View
@@ -1,6 +1,10 @@
+import sublime
import sublime_plugin
-from sublime_haskell_common import attach_sandbox, get_cabal_project_dir_and_name_of_view, get_setting
+if int(sublime.version()) < 3000:
+ from sublime_haskell_common import attach_sandbox, get_cabal_project_dir_and_name_of_view, get_setting
+else:
+ from SublimeHaskell.sublime_haskell_common import attach_sandbox, get_cabal_project_dir_and_name_of_view, get_setting
class SublimeHaskellAutobuild(sublime_plugin.EventListener):
View
@@ -6,23 +6,31 @@
import threading
import time
-from sublime_haskell_common import *
-import symbols
-from ghci import ghci_info, ghci_info_symbol
-from haskell_docs import haskell_docs
-from ghcmod import ghcmod_browse_module
+if int(sublime.version()) < 3000:
+ from sublime_haskell_common import *
+ import symbols
+ from ghci import ghci_info, ghci_info_symbol
+ from haskell_docs import haskell_docs
+ from ghcmod import ghcmod_browse_module
+else:
+ from SublimeHaskell.sublime_haskell_common import *
+ import SublimeHaskell.symbols as symbols
+ from SublimeHaskell.ghci import ghci_info, ghci_info_symbol
+ from SublimeHaskell.haskell_docs import haskell_docs
+ from SublimeHaskell.ghcmod import ghcmod_browse_module
+
# If true, files that have not changed will not be re-inspected.
CHECK_MTIME = True
-MODULE_INSPECTOR_SOURCE_PATH = os.path.join(PACKAGE_PATH, 'ModuleInspector.hs')
-MODULE_INSPECTOR_EXE_PATH = os.path.join(PACKAGE_PATH, 'ModuleInspector')
-MODULE_INSPECTOR_OBJ_DIR = os.path.join(PACKAGE_PATH, 'obj/ModuleInspector')
-CABAL_INSPECTOR_SOURCE_PATH = os.path.join(PACKAGE_PATH, 'CabalInspector.hs')
-CABAL_INSPECTOR_EXE_PATH = os.path.join(PACKAGE_PATH, 'CabalInspector')
-CABAL_INSPECTOR_OBJ_DIR = os.path.join(PACKAGE_PATH, 'obj/CabalInspector')
+MODULE_INSPECTOR_SOURCE_PATH = None
+MODULE_INSPECTOR_EXE_PATH = None
+MODULE_INSPECTOR_OBJ_DIR = None
+CABAL_INSPECTOR_SOURCE_PATH = None
+CABAL_INSPECTOR_EXE_PATH = None
+CABAL_INSPECTOR_OBJ_DIR = None
-OUTPUT_PATH = os.path.join(PACKAGE_PATH, 'module_info.cache')
+OUTPUT_PATH = None
# ModuleInspector output
MODULE_INSPECTOR_RE = re.compile(r'ModuleInfo:(?P<result>.+)')
@@ -65,7 +73,7 @@ def get_qualified_name(s):
if len(s) == 0:
return ('', '')
quals = s.split()[-1].split('.')
- filtered = map(lambda s: filter(lambda c: c.isalpha() or c.isdigit() or c == '_', s), quals)
+ filtered = map(lambda s: list(filter(lambda c: c.isalpha() or c.isdigit() or c == '_', s)), quals)
return ('.'.join(filtered[0:len(filtered) - 1]), '.'.join(filtered))
def get_qualified_symbol(line):
@@ -268,7 +276,7 @@ def can_complete_qualified_symbol(info):
if is_import_list:
return module_name in autocompletion.get_current_module_completions()
else:
- return (filter(lambda m: m.startswith(module_name), autocompletion.get_current_module_completions()) != [])
+ return list(filter(lambda m: m.startswith(module_name), autocompletion.get_current_module_completions()) != [])
class SublimeHaskellComplete(sublime_plugin.TextCommand):
""" Shows autocompletion popup """
@@ -360,7 +368,7 @@ def is_enabled(self):
class SublimeHaskellReinspectAll(sublime_plugin.WindowCommand):
def run(self):
autocompletion.clear_inspected()
- SublimeHaskellAutocomplete.inspector.mark_all_files(self.window)
+ inspector.mark_all_files(self.window)
@@ -454,9 +462,8 @@ def show_symbol_info(self, decl):
decl.docs = decl_docs
# TODO: Move to separate command for Sublime Text 3
- edit = output_view.begin_edit()
- output_view.insert(edit, output_view.size(), decl.detailed())
- output_view.end_edit(edit)
+ output_view.run_command('sublime_haskell_output_text', {
+ 'text': decl.detailed() })
output_view.sel().clear()
output_view.set_read_only(True)
@@ -485,7 +492,7 @@ def run(self, edit):
decls = autocompletion.database.symbols[ident]
- modules_dict = symbols.flatten(symbols.declarations_modules(decls, lambda ms: filter(symbols.is_by_sources, ms)).values())
+ modules_dict = symbols.flatten(symbols.declarations_modules(decls, lambda ms: list(filter(symbols.is_by_sources, ms))).values())
with autocompletion.database.files_lock:
if current_file_name in autocompletion.database.files:
@@ -510,7 +517,7 @@ def run(self, edit):
with autocompletion.database.modules_lock:
if full_name in autocompletion.database.modules:
- modules = filter(symbols.is_by_sources, autocompletion.database.modules[full_name])
+ modules = list(filter(symbols.is_by_sources, autocompletion.database.modules[full_name]))
# Find module in this project
module_candidates.extend([m for m in modules if symbols.is_within_project(m, current_project)])
@@ -671,10 +678,12 @@ def _load_standard_module_docs(self, module_name):
log('Loading docs for in-cabal module {0} failed: {1}'.format(module_name, e))
-class InspectorAgent(threading.Thread):
- std_inspector = StandardInspectorAgent()
- std_inspector.start()
+std_inspector = None
+
+
+
+class InspectorAgent(threading.Thread):
def __init__(self):
# Call the superclass constructor:
super(InspectorAgent, self).__init__()
@@ -837,7 +846,7 @@ def _refresh_module_info(self, filename):
if 'imports' in new_info:
for mi in new_info['imports']:
if 'importName' in mi:
- InspectorAgent.std_inspector.load_module_info(mi['importName'])
+ std_inspector.load_module_info(mi['importName'])
# # Remember when this info was collected.
# new_info['inspectedAt'] = modification_time
@@ -876,7 +885,7 @@ def make_import(import_info):
autocompletion.database.add_file(filename, new_module)
for i in new_module.imports.values():
- InspectorAgent.std_inspector.load_module_info(i.module)
+ std_inspector.load_module_info(i.module)
except Exception as e:
log('Inspecting file {0} failed: {1}'.format(filename, e))
@@ -903,10 +912,12 @@ def list_files_in_dir_recursively(base_dir):
return files
-class SublimeHaskellAutocomplete(sublime_plugin.EventListener):
- inspector = InspectorAgent()
- inspector.start()
+inspector = None
+
+
+
+class SublimeHaskellAutocomplete(sublime_plugin.EventListener):
def __init__(self):
self.local_settings = {
'enable_ghc_mod': None,
@@ -937,7 +948,7 @@ def on_setting_changed(self):
if not same:
# TODO: Changed completion settings! Update autocompletion data properly
# For now at least try to load cabal modules info
- InspectorAgent.std_inspector.load_cabal_info()
+ std_inspector.load_cabal_info()
pass
def get_special_completions(self, view, prefix, locations):
@@ -1004,7 +1015,7 @@ def on_new(self, view):
self.set_cabal_status(view)
filename = view.file_name()
if filename:
- SublimeHaskellAutocomplete.inspector.mark_file_dirty(filename)
+ inspector.mark_file_dirty(filename)
def on_load(self, view):
self.set_cabal_status(view)
@@ -1015,7 +1026,7 @@ def on_activated(self, view):
def on_post_save(self, view):
filename = view.file_name()
if filename:
- SublimeHaskellAutocomplete.inspector.mark_file_dirty(filename)
+ inspector.mark_file_dirty(filename)
def on_query_context(self, view, key, operator, operand, match_all):
if key == 'auto_completion_popup':
@@ -1036,3 +1047,35 @@ def on_query_context(self, view, key, operator, operand, match_all):
return can_complete_qualified_symbol(get_qualified_symbol(preline))
else:
return False
+
+
+
+def plugin_loaded():
+ global MODULE_INSPECTOR_SOURCE_PATH
+ global MODULE_INSPECTOR_EXE_PATH
+ global MODULE_INSPECTOR_OBJ_DIR
+ global CABAL_INSPECTOR_SOURCE_PATH
+ global CABAL_INSPECTOR_EXE_PATH
+ global CABAL_INSPECTOR_OBJ_DIR
+ global OUTPUT_PATH
+
+ package_path = sublime_haskell_package_path()
+
+ MODULE_INSPECTOR_SOURCE_PATH = os.path.join(package_path, 'ModuleInspector.hs')
+ MODULE_INSPECTOR_EXE_PATH = os.path.join(package_path, 'ModuleInspector')
+ MODULE_INSPECTOR_OBJ_DIR = os.path.join(package_path, 'obj/ModuleInspector')
+ CABAL_INSPECTOR_SOURCE_PATH = os.path.join(package_path, 'CabalInspector.hs')
+ CABAL_INSPECTOR_EXE_PATH = os.path.join(package_path, 'CabalInspector')
+ CABAL_INSPECTOR_OBJ_DIR = os.path.join(package_path, 'obj/CabalInspector')
+ OUTPUT_PATH = os.path.join(package_path, 'module_info.cache')
+
+ global std_inspector
+ std_inspector = StandardInspectorAgent()
+ std_inspector.start()
+
+ global inspector
+ inspector = InspectorAgent()
+ inspector.start()
+
+if int(sublime.version()) < 3000:
+ plugin_loaded()
View
@@ -3,9 +3,14 @@
import sublime_plugin
from threading import Thread
-from sublime_haskell_common import *
-from parseoutput import run_chain_build_thread
-from autocomplete import autocompletion
+if int(sublime.version()) < 3000:
+ from sublime_haskell_common import *
+ from parseoutput import run_chain_build_thread
+ from autocomplete import autocompletion
+else:
+ from SublimeHaskell.sublime_haskell_common import *
+ from SublimeHaskell.parseoutput import run_chain_build_thread
+ from SublimeHaskell.autocomplete import autocompletion
OUTPUT_PANEL_NAME = "haskell_run_output"
@@ -301,9 +306,8 @@ def write_output(window, text, base_dir):
# Configure Sublime's error message parsing:
output_view.settings().set("result_base_dir", base_dir)
# Write to the output buffer:
- edit = output_view.begin_edit()
- output_view.insert(edit, 0, text)
- output_view.end_edit(edit)
+ output_view.run_command('sublime_haskell_output_text', {
+ 'text': text })
# Set the selection to the beginning of the view so that "next result" works:
output_view.sel().clear()
output_view.sel().add(sublime.Region(0))
View
@@ -1,9 +1,14 @@
import re
import os
+import sublime
import sublime_plugin
-from sublime_haskell_common import *
-import symbols
+if int(sublime.version()) < 3000:
+ from sublime_haskell_common import *
+ import symbols
+else:
+ from SublimeHaskell.sublime_haskell_common import *
+ import SublimeHaskell.symbols as symbols
def ghci_info(module, name):
"""
View
@@ -4,9 +4,14 @@
import sublime_plugin
from threading import Thread
-from sublime_haskell_common import log, is_enabled_haskell_command, get_haskell_command_window_view_file_project, call_ghcmod_and_wait
-from parseoutput import parse_output_messages, show_output_result_text, format_output_messages, mark_messages_in_views, hide_output, set_global_error_messages
-import symbols
+if int(sublime.version()) < 3000:
+ from sublime_haskell_common import log, is_enabled_haskell_command, get_haskell_command_window_view_file_project, call_ghcmod_and_wait
+ from parseoutput import parse_output_messages, show_output_result_text, format_output_messages, mark_messages_in_views, hide_output, set_global_error_messages
+ import symbols
+else:
+ from SublimeHaskell.sublime_haskell_common import log, is_enabled_haskell_command, get_haskell_command_window_view_file_project, call_ghcmod_and_wait
+ from SublimeHaskell.parseoutput import parse_output_messages, show_output_result_text, format_output_messages, mark_messages_in_views, hide_output, set_global_error_messages
+ import SublimeHaskell.symbols as symbols
def lint_as_hints(msgs):
View
@@ -1,8 +1,12 @@
import re
import os
+import sublime
import sublime_plugin
-from sublime_haskell_common import *
+if int(sublime.version()) < 3000:
+ from sublime_haskell_common import *
+else:
+ from SublimeHaskell.sublime_haskell_common import *
def haskell_docs(module, name):
"""
@@ -19,7 +23,7 @@ def haskell_docs(module, name):
ignoreRe = '({0})|({1})|({2})|({3})'.format(ambigousRe, continueRe, cantFindRe, packageRe)
# Remove debug messages
- result = filter(lambda l: not re.match(ignoreRe, l), stdout.splitlines())
+ result = list(filter(lambda l: not re.match(ignoreRe, l), stdout.splitlines()))
return '\n'.join(result)
except OSError as e:
if e.errno == errno.ENOENT:
View
@@ -2,7 +2,10 @@
import sublime_plugin
import re
-from sublime_haskell_common import call_ghcmod_and_wait, is_enabled_haskell_command
+if int(sublime.version()) < 3000:
+ from sublime_haskell_common import call_ghcmod_and_wait, is_enabled_haskell_command
+else:
+ from SublimeHaskell.sublime_haskell_common import call_ghcmod_and_wait, is_enabled_haskell_command
# Used to find out the module name.
MODULE_RE_STR = r'module\s+([^\s\(]*)' # "module" followed by everything that is neither " " nor "("
@@ -72,9 +75,8 @@ def write_output(self, view, text):
output_view = view.window().get_output_panel(TYPE_PANEL_NAME)
output_view.set_read_only(False)
# Write to the output buffer:
- edit = output_view.begin_edit()
- output_view.insert(edit, 0, text)
- output_view.end_edit(edit)
+ output_view.run_command('sublime_haskell_output_text', {
+ 'text': text })
# Set the selection to the beginning of the view so that "next result" works:
output_view.set_read_only(True)
# Show the results panel:
View
@@ -6,7 +6,10 @@
from threading import Thread
from collections import defaultdict
-from sublime_haskell_common import log, are_paths_equal, call_and_wait, get_setting_async, show_status_message_process, show_status_message
+if int(sublime.version()) < 3000:
+ from sublime_haskell_common import log, are_paths_equal, call_and_wait, get_setting_async, show_status_message_process, show_status_message
+else:
+ from SublimeHaskell.sublime_haskell_common import log, are_paths_equal, call_and_wait, get_setting_async, show_status_message_process, show_status_message
ERROR_PANEL_NAME = 'haskell_error_checker'
@@ -184,9 +187,9 @@ def mark_messages_in_views(errors):
# Unsaved files have no file name
if view_filename is None:
continue
- errors_in_view = filter(
+ errors_in_view = list(filter(
lambda x: are_paths_equal(view_filename, x.filename),
- errors)
+ errors))
mark_messages_in_view(errors_in_view, v)
end_time = time.clock()
log('total time to mark {0} diagnostics: {1} seconds'.format(
@@ -213,7 +216,7 @@ def mark_messages_in_views(errors):
class SublimeHaskellNextError(sublime_plugin.TextCommand):
def run(self, edit):
- print "SublimeHaskellNextError"
+ log("SublimeHaskellNextError")
v = self.view
fn = v.file_name().encode("utf-8")
line, column = v.rowcol(v.sel()[0].a)
@@ -283,10 +286,8 @@ def write_output(view, text, cabal_project_dir):
output_view.settings().set("result_file_regex", result_file_regex)
output_view.settings().set("result_base_dir", cabal_project_dir)
# Write to the output buffer:
- edit = output_view.begin_edit()
- #output_view.insert(edit, 0, text)
- output_view.insert(edit, output_view.size(), text)
- output_view.end_edit(edit)
+ output_view.run_command('sublime_haskell_output_text', {
+ 'text': text })
# Set the selection to the beginning of the view so that "next result" works:
output_view.sel().clear()
output_view.sel().add(sublime.Region(0))
View
@@ -2,7 +2,10 @@
import sublime
import sublime_plugin
-from sublime_haskell_common import is_enabled_haskell_command, call_and_wait_with_input
+if int(sublime.version()) < 3000:
+ from sublime_haskell_common import is_enabled_haskell_command, call_and_wait_with_input
+else:
+ from SublimeHaskell.sublime_haskell_common import is_enabled_haskell_command, call_and_wait_with_input
class SublimeHaskellStylish(sublime_plugin.TextCommand):
Oops, something went wrong.

0 comments on commit 5c0d422

Please sign in to comment.