Skip to content

Commit f7bf78c

Browse files
author
Kenichi Hoshi
committed
refactoring
1 parent 45d0355 commit f7bf78c

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

urobosql_formatter.py

+20-18
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111

1212

1313
class UroborosqlFormatCommand(sublime_plugin.TextCommand):
14-
"""SQL Format Command class"""
14+
15+
"""SQL format command class"""
1516

1617
def run(self, edit):
1718
view = self.view
19+
view.window().status_message('formatting...')
1820
self.settings = view.settings()
1921
self.user_settings = sublime.load_settings(
2022
'sublime-uroborosql-formatter.sublime-settings')
21-
regions = view.sel()
2223
# set syntax
2324
if self.settings.get('syntax') == \
2425
"Packages/Text/Plain text.tmLanguage":
@@ -30,13 +31,13 @@ def run(self, edit):
3031

3132
config = LocalConfig()
3233
config.set_uppercase(self.getval("uf_uppercase"))
33-
uroborosqlfmt.config.glb.escape_sequence_u005c = self.getval("uf_escapesequence_u005c")
34+
uroborosqlfmt.config.glb.escape_sequence_u005c = self.getval(
35+
"uf_escapesequence_u005c")
3436
if str(self.getval("uf_comment_syntax")).upper() == "DOMA2":
3537
config.set_commentsyntax(Doma2CommentSyntax())
3638

3739
raw_text = ""
38-
region = None
39-
40+
regions = view.sel()
4041
# format selection
4142
if len(regions) > 1 or not regions[0].empty():
4243
for region in view.sel():
@@ -46,26 +47,27 @@ def run(self, edit):
4647
region = sublime.Region(0, view.size())
4748
raw_text = view.substr(region)
4849

49-
threading.Thread(target=self.run_format, args=(edit, raw_text, region, config, )).start()
50+
threading.Thread(target=self.run_format, args=(
51+
edit, raw_text, config, region.a, region.b)).start()
5052

51-
def run_format(self, edit, raw_text, region, config):
53+
def run_format(self, edit, raw_text, config, region_a, region_b):
5254
formatted_text = uroborosqlfmt.format_sql(raw_text, config)
53-
self.view.run_command("uroborosql_format_view", {"formatted_text": formatted_text})
55+
self.view.run_command("uroborosql_format_replace", {
56+
"region_a": region_a,
57+
"region_b": region_b,
58+
"formatted_text": formatted_text
59+
})
5460

5561
def getval(self, key):
5662
val = self.user_settings.get(key)
5763
return val if val != None else self.settings.get(key)
5864

5965

60-
class UroborosqlFormatViewCommand(sublime_plugin.TextCommand):
61-
def run(self, edit, **args):
62-
regions = self.view.sel()
63-
# format selection
64-
if len(regions) > 1 or not regions[0].empty():
65-
for region in self.view.sel():
66-
if not region.empty():
67-
break
68-
else: # format all
69-
region = sublime.Region(0, self.view.size())
66+
class UroborosqlFormatReplaceCommand(sublime_plugin.TextCommand):
7067

68+
"""SQL format replace command class"""
69+
70+
def run(self, edit, **args):
71+
region = sublime.Region(args["region_a"], args["region_b"])
7172
self.view.replace(edit, region, args["formatted_text"])
73+
self.view.window().status_message('formatting... complete!!')

0 commit comments

Comments
 (0)