-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFlow.py
45 lines (36 loc) · 1.19 KB
/
Flow.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sublime
import sublime_plugin
import re
import os
EXEC_FLOW = 'flow'
SETTINGS_FILE = 'Flow.sublime-settings'
# Sublime internally maps 'flow' to this FlowCommand class
# Invoked via Build, Tools, ctrl-f, etc.
class FlowCommand(sublime_plugin.WindowCommand):
def run(self, files=[]):
# Flow operates on directories and will use the path prefix
files = files or [self.window.active_view().file_name()]
settings = sublime.load_settings(SETTINGS_FILE)
if os.name == "posix":
path = "/usr/local/bin:" + os.environ['PATH']
else:
path = os.environ['PATH']
self.window.run_command('exec', {
'cmd':
settings.get('flow_command', ['flow', 'check']) +
settings.get('flow_options', []) +
files,
'path': path,
'file_regex': settings.get('file_regex', '(\\/.*\\.js):(\\d+):(\\d+),.*$')
})
class FlowOnSave(sublime_plugin.EventListener):
def on_post_save(self, view):
settings = sublime.load_settings(SETTINGS_FILE)
if settings.get('run_on_save', False) == False:
return
if re.search(settings.get('filename_filter'), view.file_name()):
view.window().run_command(EXEC_FLOW, {
'files': [view.file_name()]
})