forked from mgiannini/sublime-fantom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fan_build.py
48 lines (39 loc) · 1.17 KB
/
fan_build.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
import sublime
import sublime_plugin
import os
class FanBuildCommand(sublime_plugin.WindowCommand):
def run(self, task='compile', **kwargs):
if task == 'run':
self.run_script()
return
self.workingDir = self._find_pod_dir()
if not self.workingDir:
sublime.status_message("Could not find build.fan")
return
if task == 'prompt':
self.window.show_input_panel("Test", "full", self._ok, None, None)
else:
self.run_build(task)
def run_script(self):
file = self.window.active_view().file_name()
execArgs = {}
execArgs["cmd"] = [file]
self.window.run_command("exec", execArgs)
def run_build(self, task):
execArgs = {}
execArgs["cmd"] = ["./build.fan", task]
execArgs["file_regex"] = "^(.*)(?:\(|:)(\\d+)(?:,(\\d+))?"
execArgs["working_dir"] = self.workingDir
self.window.run_command("exec", execArgs)
def _find_pod_dir(self):
view = self.window.active_view()
dir = os.path.normpath(os.path.dirname(view.file_name()))
while True:
if os.path.isfile(os.path.join(dir, 'build.fan')):
return dir
temp = os.path.normpath(os.path.dirname(dir))
if temp == dir:
return None
dir = temp
def _ok(self, task):
self.run_build(task)