Skip to content

Commit fabb8d5

Browse files
committed
More refactor on naming
1 parent 3e275bb commit fabb8d5

File tree

5 files changed

+45
-34
lines changed

5 files changed

+45
-34
lines changed

commands/quick_info.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
class TypescriptQuickInfo(TypeScriptBaseTextCommand):
77
"""Command currently called only from event handlers"""
8+
89
def handle_quick_info(self, quick_info_resp_dict):
910
if quick_info_resp_dict["success"]:
1011
info_str = quick_info_resp_dict["body"]["displayString"]
@@ -29,28 +30,29 @@ class TypescriptQuickInfoDoc(TypeScriptBaseTextCommand):
2930
Command to show the doc string associated with quick info;
3031
re-runs quick info in case info has changed
3132
"""
33+
3234
def handle_quick_info(self, quick_info_resp_dict):
3335
if quick_info_resp_dict["success"]:
3436
info_str = quick_info_resp_dict["body"]["displayString"]
35-
# The finfoStr depends on the if result
36-
finfoStr = info_str
37+
status_info_str = info_str
3738
doc_str = quick_info_resp_dict["body"]["documentation"]
3839
if len(doc_str) > 0:
3940
if not TOOLTIP_SUPPORT:
40-
docPanel = sublime.active_window().get_output_panel("doc")
41-
docPanel.run_command('typescript_show_doc',
42-
{'infoStr': info_str,
43-
'docStr': doc_str})
44-
docPanel.settings().set('color_scheme', "Packages/Color Scheme - Default/Blackboard.tmTheme")
41+
doc_panel = sublime.active_window().get_output_panel("doc")
42+
doc_panel.run_command(
43+
'typescript_show_doc',
44+
{'infoStr': info_str, 'docStr': doc_str}
45+
)
46+
doc_panel.settings().set('color_scheme', "Packages/Color Scheme - Default/Blackboard.tmTheme")
4547
sublime.active_window().run_command('show_panel', {'panel': 'output.doc'})
46-
finfoStr = info_str + " (^T^Q for more)"
47-
self.view.set_status("typescript_info", finfoStr)
48+
status_info_str = info_str + " (^T^Q for more)"
49+
self.view.set_status("typescript_info", status_info_str)
4850
if TOOLTIP_SUPPORT:
49-
hinfoStr = escape_html(info_str)
50-
hdocStr = escape_html(doc_str)
51-
html = "<div>" + hinfoStr + "</div>"
51+
html_info_str = escape_html(info_str)
52+
html_doc_str = escape_html(doc_str)
53+
html = "<div>" + html_info_str + "</div>"
5254
if len(doc_str) > 0:
53-
html += "<div>" + hdocStr + "</div>"
55+
html += "<div>" + html_doc_str + "</div>"
5456
self.view.show_popup(html, location=-1, max_width=800)
5557
else:
5658
self.view.erase_status("typescript_info")

commands/rename.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def run(self, text, args_json=""):
5959
start_line, start_offset = extract_line_offset(inner_location["start"])
6060
end_line, end_offset = extract_line_offset(inner_location["end"])
6161
apply_edit(text, self.view, start_line, start_offset, end_line,
62-
end_offset, ntext=new_name)
62+
end_offset, new_text=new_name)
6363

6464

6565
class TypescriptDelayedRenameFile(TypeScriptBaseTextCommand):
@@ -72,4 +72,4 @@ def run(self, text, locs_name=None):
7272
start_line, start_offset = extract_line_offset(inner_location['start'])
7373
end_line, end_offset = extract_line_offset(inner_location['end'])
7474
apply_edit(text, self.view, start_line, start_offset, end_line,
75-
end_offset, ntext=name)
75+
end_offset, new_text=name)

libs/texthelpers.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
from .globalvars import *
44

5+
56
class Location:
6-
"""Object containing line and offset (one-based) of file location"""
7+
"""Object containing line and offset (one-based) of file location
8+
9+
Location is a server protocol. Both line and offset are 1-based.
10+
"""
711

812
def __init__(self, line, offset):
913
self.line = line
@@ -82,6 +86,7 @@ def extract_line_offset(line_offset):
8286
offset = line_offset.offset - 1
8387
return line, offset
8488

89+
8590
def escape_html(raw_string):
8691
"""Escape html content
8792
@@ -90,12 +95,12 @@ def escape_html(raw_string):
9095
return raw_string.replace('&', '&amp;').replace('<', '&lt;').replace('>', "&gt;")
9196

9297

93-
def left_expand_empty_region(regions):
98+
def left_expand_empty_region(regions, number=1):
9499
"""Expand region list one to left for backspace change info"""
95100
result = []
96101
for region in regions:
97102
if region.empty():
98-
result.append(sublime.Region(region.begin() - 1, region.end()))
103+
result.append(sublime.Region(region.begin() - number, region.end()))
99104
else:
100105
result.append(region)
101106
return result
@@ -111,6 +116,7 @@ def right_expand_empty_region(regions):
111116
result.append(region)
112117
return result
113118

119+
114120
def build_replace_regions(empty_regions_a, empty_regions_b):
115121
"""
116122
Given two list of cursor locations, connect each pair of locations for form

libs/viewhelpers.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -232,29 +232,27 @@ def send_replace_changes_for_regions(view, regions, insert_string):
232232
cli.service.change(view.file_name(), location, end_location, insert_string)
233233

234234

235-
def apply_edit(text, view, startl, startc, endl, endc, ntext=""):
235+
def apply_edit(text, view, start_line, start_offset, end_line, end_offset, new_text=""):
236236
"""Apply a single edit specification to a view"""
237-
begin = view.text_point(startl, startc)
238-
end = view.text_point(endl, endc)
237+
begin = view.text_point(start_line, start_offset)
238+
end = view.text_point(end_line, end_offset)
239239
region = sublime.Region(begin, end)
240-
send_replace_changes_for_regions(view, [region], ntext)
240+
send_replace_changes_for_regions(view, [region], new_text)
241241
# break replace into two parts to avoid selection changes
242242
if region.size() > 0:
243243
view.erase(text, region)
244-
if (len(ntext) > 0):
245-
view.insert(text, begin, ntext)
244+
if len(new_text) > 0:
245+
view.insert(text, begin, new_text)
246246

247247

248248
def apply_formatting_changes(text, view, code_edits):
249249
"""Apply a set of edits to a view"""
250250
if code_edits:
251251
for code_edit in code_edits[::-1]:
252-
startlc = code_edit["start"]
253-
(startl, startc) = extract_line_offset(startlc)
254-
endlc = code_edit["end"]
255-
(endl, endc) = extract_line_offset(endlc)
256-
newText = code_edit["newText"]
257-
apply_edit(text, view, startl, startc, endl, endc, ntext=newText)
252+
start_line, start_offset = extract_line_offset(code_edit["start"])
253+
end_line, end_offset = extract_line_offset(code_edit["end"])
254+
new_text = code_edit["newText"]
255+
apply_edit(text, view, start_line, start_offset, end_line, end_offset, new_text=new_text)
258256

259257

260258
def insert_text(view, edit, loc, text):
@@ -268,7 +266,7 @@ def insert_text(view, edit, loc, text):
268266

269267
def format_range(text, view, begin, end):
270268
"""Format a range of locations in the view"""
271-
if (not is_typescript(view)):
269+
if not is_typescript(view):
272270
print("To run this command, please first assign a file name to the view")
273271
return
274272
check_update_view(view)
@@ -307,4 +305,9 @@ def change_count(view):
307305
if IS_ST2:
308306
return info.modify_count
309307
else:
310-
return view.change_count()
308+
return view.change_count()
309+
310+
311+
# def get_delete_indent_space_number(view, pos):
312+
# line, offset =
313+
# tab_size = view.settings().get("tab_size", 1)

listeners/idle.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ def show_error_msgs(self, diagno_event_body, syntactic):
8282
for diagno in diagnos:
8383
start_location = diagno["start"]
8484
end_location = diagno["end"]
85-
(line, offset) = extract_line_offset(start_location)
86-
(end_line, end_offset) = extract_line_offset(end_location)
85+
line, offset = extract_line_offset(start_location)
86+
end_line, end_offset = extract_line_offset(end_location)
8787
text = diagno["text"]
8888
start = view.text_point(line, offset)
8989
end = view.text_point(end_line, end_offset)

0 commit comments

Comments
 (0)