Skip to content

Commit cb42fdb

Browse files
committed
Merge pull request #217 from zhengbli/asyncQuickInfo
Change quick info request to async for ST3
2 parents 7233d1a + 1fc85db commit cb42fdb

File tree

4 files changed

+26
-17
lines changed

4 files changed

+26
-17
lines changed

typescript/libs/node_client.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ def getEvent(self): pass
2121

2222
def postCmd(self, cmd): pass
2323

24-
def sendCmd(self, cb, cmd): pass
24+
def sendCmd(self, cmd, cb): pass
2525

2626
def sendCmdSync(self, cmd): pass
2727

28-
def sendCmdAsync(self, cmd): pass
28+
def sendCmdAsync(self, cmd, cb): pass
2929

3030

3131
class NodeCommClient(CommClient):
@@ -111,7 +111,7 @@ def makeTimeoutMsg(self, cmd, seq):
111111
}
112112
return timeoutMsg
113113

114-
def sendCmd(self, cb, cmd, seq):
114+
def sendCmd(self, cmd, cb, seq):
115115
"""
116116
send single-line command string; no sequence number; wait for response
117117
this assumes stdin/stdout; for TCP, need to add correlation with sequence numbers
@@ -133,7 +133,7 @@ def sendCmd(self, cb, cmd, seq):
133133
if (cb):
134134
cb(self.makeTimeoutMsg(cmd, seq))
135135

136-
def sendCmdAsync(self, cmd, seq, cb):
136+
def sendCmdAsync(self, cmd, cb, seq):
137137
"""
138138
Sends the command and registers a callback
139139
"""

typescript/libs/service_proxy.py

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import collections
22

33
from . import json_helpers
4+
from .global_vars import IS_ST2
45
from .node_client import CommClient
56
from .text_helpers import Location
67

@@ -45,32 +46,32 @@ def completions(self, path, location=Location(1, 1), prefix="", on_completed=Non
4546
req_dict = self.create_req_dict("completions", args)
4647
json_str = json_helpers.encode(req_dict)
4748
self.__comm.sendCmd(
48-
lambda json_dict: None if on_completed is None else on_completed(json_dict),
4949
json_str,
50+
lambda response_dict: None if on_completed is None else on_completed(response_dict),
5051
req_dict["seq"]
5152
)
5253

5354
def async_completions(self, path, location=Location(1, 1), prefix="", on_completed=None):
5455
args = {"file": path, "line": location.line, "offset": location.offset, "prefix": prefix}
5556
req_dict = self.create_req_dict("completions", args)
5657
json_str = json_helpers.encode(req_dict)
57-
self.__comm.sendCmdAsync(json_str, req_dict["seq"], on_completed)
58+
self.__comm.sendCmdAsync(json_str, on_completed, req_dict["seq"])
5859

5960
def signature_help(self, path, location=Location(1, 1), prefix="", on_completed=None):
6061
args = {"file": path, "line": location.line, "offset": location.offset, "prefix": prefix}
6162
req_dict = self.create_req_dict("signatureHelp", args)
6263
json_str = json_helpers.encode(req_dict)
6364
self.__comm.sendCmd(
64-
lambda response_dict: None if on_completed is None else on_completed(response_dict),
6565
json_str,
66+
lambda response_dict: None if on_completed is None else on_completed(response_dict),
6667
req_dict["seq"]
6768
)
6869

6970
def async_signature_help(self, path, location=Location(1, 1), prefix="", on_completed=None):
7071
args = {"file": path, "line": location.line, "offset": location.offset, "prefix": prefix}
7172
req_dict = self.create_req_dict("signatureHelp", args)
7273
json_str = json_helpers.encode(req_dict)
73-
self.__comm.sendCmdAsync(json_str, req_dict["seq"], on_completed)
74+
self.__comm.sendCmdAsync(json_str, on_completed, req_dict["seq"])
7475

7576
def definition(self, path, location=Location(1, 1)):
7677
args = {"file": path, "line": location.line, "offset": location.offset}
@@ -129,7 +130,7 @@ def reload_async(self, path, alternate_path, on_completed):
129130
args = {"file": path, "tmpfile": alternate_path}
130131
req_dict = self.create_req_dict("reload", args)
131132
json_str = json_helpers.encode(req_dict)
132-
self.__comm.sendCmdAsync(json_str, req_dict["seq"], on_completed)
133+
self.__comm.sendCmdAsync(json_str, on_completed, req_dict["seq"])
133134

134135
def rename(self, path, location=Location(1, 1)):
135136
args = {"file": path, "line": location.line, "offset": location.offset}
@@ -151,15 +152,23 @@ def type(self, path, location=Location(1, 1)):
151152
response_dict = self.__comm.sendCmdSync(json_str, req_dict["seq"])
152153
return response_dict
153154

154-
def quick_info(self, path, location=Location(1, 1), onCompleted=None):
155+
def quick_info(self, path, location=Location(1, 1), on_completed=None):
155156
args = {"file": path, "line": location.line, "offset": location.offset}
156157
req_dict = self.create_req_dict("quickinfo", args)
157158
json_str = json_helpers.encode(req_dict)
158-
self.__comm.sendCmd(
159-
lambda json_dict: None if onCompleted is None else onCompleted(json_dict),
160-
json_str,
161-
req_dict["seq"]
162-
)
159+
callback = on_completed or (lambda: None)
160+
if not IS_ST2:
161+
self.__comm.sendCmdAsync(
162+
json_str,
163+
callback,
164+
req_dict["seq"]
165+
)
166+
else:
167+
self.__comm.sendCmd(
168+
json_str,
169+
callback,
170+
req_dict["seq"]
171+
)
163172

164173
def get_event(self):
165174
event_json_str = self.__comm.getEvent()

typescript/libs/view_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def is_special_view(view):
106106
in that they cannot be the active_view of their windows, therefore their ids
107107
shouldn't be equal to the current view id.
108108
"""
109-
return view.window() and view.id() != view.window().active_view().id()
109+
return view is not None and view.window() and view.id() != view.window().active_view().id()
110110

111111

112112
def get_location_from_view(view):

typescript/listeners/rename.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def on_load(self, view):
99
if client_info and client_info.rename_on_load:
1010
view.run_command(
1111
'typescript_delayed_rename_file',
12-
{"locs_name": client_info.renameOnLoad}
12+
{"locs_name": client_info.rename_on_load}
1313
)
1414
client_info.rename_on_load = None
1515

0 commit comments

Comments
 (0)