Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Migrated to Sublime Text 3

  • Loading branch information...
commit 5c0d422c1acd3883190e47e69a329e36a6a3cf42 1 parent 7809360
@mvoidex mvoidex authored
View
6 autobuild.py
@@ -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
105 autocomplete.py
@@ -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
16 cabalbuild.py
@@ -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
9 ghci.py
@@ -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
11 ghcmod.py
@@ -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
8 haskell_docs.py
@@ -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
10 haskell_type.py
@@ -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
17 parseoutput.py
@@ -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
5 stylishhaskell.py
@@ -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):
View
46 sublime_haskell_common.py
@@ -2,6 +2,7 @@
import fnmatch
import os
import sublime
+import sublime_plugin
import subprocess
import threading
import time
@@ -11,7 +12,7 @@
MAX_WAIT_FOR_WINDOW = 10
# The path to where this package is installed:
-PACKAGE_PATH = os.path.join(sublime.packages_path(), 'SublimeHaskell')
+PACKAGE_PATH = None
# Panel for SublimeHaskell errors
SUBLIME_ERROR_PANEL_NAME = 'haskell_sublime_load'
@@ -79,6 +80,12 @@ def get_haskell_command_window_view_file_project(view = None):
return window, view, file_name
+def decode_bytes(s):
+ if int(sublime.version()) < 3000:
+ return s
+ return s.decode()
+
+
def call_and_wait(command, **popen_kwargs):
return call_and_wait_with_input(command, None, **popen_kwargs)
@@ -107,7 +114,7 @@ def call_and_wait_with_input(command, input_string, **popen_kwargs):
**popen_kwargs)
stdout, stderr = process.communicate(input_string)
exit_code = process.wait()
- return (exit_code, stdout, stderr)
+ return (exit_code, decode_bytes(stdout), decode_bytes(stderr))
def log(message):
@@ -223,8 +230,6 @@ def get_setting(key, default=None):
get_settings().add_on_change(key, lambda: update_setting(key))
return result
-preload_settings()
-
def update_setting(key):
"Updates setting as it was changed"
@@ -249,7 +254,6 @@ def set_setting(key, value):
sublime_haskell_settings[key] = value
get_settings().set(key, value)
-
def call_ghcmod_and_wait(arg_list, filename=None, sandbox = None):
"""
Calls ghc-mod with the given arguments.
@@ -300,14 +304,26 @@ def wait_for_window(on_appear, seconds_to_wait=MAX_WAIT_FOR_WINDOW):
sublime.set_timeout(lambda: wait_for_window_callback(on_appear, seconds_to_wait), 0)
+
+class SublimeHaskellOutputText(sublime_plugin.TextCommand):
+ """
+ Helper command to output text to any view
+ TODO: Is there any default command for this purpose?
+ """
+ def run(self, edit, text = None):
+ if not text:
+ return
+ self.view.insert(edit, self.view.size(), text)
+
+
+
def output_error(window, text):
"Write text to Sublime's output panel with important information about SublimeHaskell error during load"
output_view = window.get_output_panel(SUBLIME_ERROR_PANEL_NAME)
output_view.set_read_only(False)
- 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})
output_view.set_read_only(True)
@@ -402,7 +418,7 @@ def update_message(self):
def add_to_priorities(self):
with StatusMessage.priorities_lock:
StatusMessage.priorities.append(((self.priority, time.clock()), self))
- StatusMessage.priorities.sort(lambda l, r: cmp(r, l))
+ StatusMessage.priorities.sort(key = lambda x: (-x[0][0], x[0][1], x[1]))
def remove_from_priorities(self):
with StatusMessage.priorities_lock:
@@ -460,3 +476,15 @@ def status_message(msg, isok = True):
def status_message_process(msg, isok = True, timeout = 60, priority = 0):
return with_status_message(msg, isok, lambda m, ok = None: show_status_message_process(m, ok, timeout, priority))
+
+def sublime_haskell_package_path():
+ return os.path.join(sublime.packages_path(), 'SublimeHaskell')
+
+
+def plugin_loaded():
+ global PACKAGE_PATH
+ PACKAGE_PATH = sublime_haskell_package_path()
+ preload_settings()
+
+if int(sublime.version()) < 3000:
+ plugin_loaded()
View
9 symbols.py
@@ -1,6 +1,11 @@
import threading
+import sublime
-from sublime_haskell_common import *
+if int(sublime.version()) < 3000:
+ from sublime_haskell_common import *
+else:
+ from SublimeHaskell.sublime_haskell_common import *
+ from functools import reduce
class Location(object):
"""
@@ -363,7 +368,7 @@ def is_by_sources(module):
return module.location is not None
def flatten(lsts):
- return reduce(lambda l, r: l + r, lsts)
+ return reduce(lambda l, r: list(l) + list(r), lsts)
def get_source_modules(modules, filename = None):
"""

0 comments on commit 5c0d422

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