-
Notifications
You must be signed in to change notification settings - Fork 9
/
plugin.py
81 lines (58 loc) · 2.47 KB
/
plugin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import sublime
from package_control import events
from .src.logging import initialize_logger
from .src.paths import PACKAGE_PATH
from .src.settings import get_settings
from .src.configurations import get_configurations
from .src.commands.build_syntaxes import BuildJsCustomSyntaxesCommand, BuildJsCustomSyntaxCommand
from .src.commands.build_tests import BuildJsCustomTestsCommand
from .src.commands.clear_user_data import ClearJsCustomUserDataCommand
from .src.commands.reassign_syntaxes import ReassignSyntaxesCommand
from .src.commands.jsx_close_tag import JsxCloseTagCommand
from .src.commands.js_custom_rebase import JsCustomRebaseCommand
from .src.commands.report_syntax_issue import JsCustomReportSyntaxIssue
from .src.listeners.jsx_close_tag import JsxCloseTagListener
import logging
logger = logging.getLogger(__name__)
__all__ = [
'plugin_loaded', 'plugin_unloaded',
'BuildJsCustomSyntaxesCommand',
'BuildJsCustomSyntaxCommand',
'BuildJsCustomTestsCommand',
'ClearJsCustomUserDataCommand',
'ReassignSyntaxesCommand',
'JsxCloseTagCommand',
'JsCustomRebaseCommand',
'JsCustomReportSyntaxIssue',
'JsxCloseTagListener',
]
PACKAGE_NAME = PACKAGE_PATH.package
UNSUBSCRIBE = None
def plugin_loaded() -> None:
initialize_logger()
# logger.info("plugin_loaded")
global UNSUBSCRIBE
UNSUBSCRIBE = get_settings().subscribe(get_configurations, auto_build)
if events.install(PACKAGE_NAME):
logger.info('New installation. Building all syntaxes.')
sublime.active_window().run_command('build_js_custom_syntaxes')
elif events.post_upgrade(PACKAGE_NAME):
logger.info('Installation upgraded. Building all syntaxes.')
sublime.active_window().run_command('build_js_custom_syntaxes')
def plugin_unloaded() -> None:
if UNSUBSCRIBE:
UNSUBSCRIBE()
if events.remove(PACKAGE_NAME):
logger.info('Uninstalling. Removing all syntaxes.')
sublime.run_command('clear_js_custom_user_data')
def auto_build(new_configurations: dict, old_configurations: dict) -> None:
if not get_settings().get('auto_build', False):
return
changed = [
name
for name in set(old_configurations) | set(new_configurations)
if old_configurations.get(name, None) != new_configurations.get(name, None)
]
if changed:
logger.info('Configuration changed. Rebuilding some syntaxes.')
sublime.active_window().run_command('build_js_custom_syntaxes', {'versions': changed})