Skip to content

Commit 1fd65fd

Browse files
committed
temp save
1 parent 81b6263 commit 1fd65fd

File tree

7 files changed

+80
-35
lines changed

7 files changed

+80
-35
lines changed

typescript/commands/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from .error_info import TypescriptErrorInfo, TypescriptProjectErrorList
1+
from .error_info import TypescriptErrorInfo
2+
from .error_list import TypescriptProjectErrorList
23
from .go_to_definition import TypescriptGoToDefinitionCommand
34
from .go_to_type import TypescriptGoToTypeCommand
45
from .nav_to import TypescriptNavToCommand

typescript/commands/error_info.py

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

3-
from ..libs.view_helpers import cli
4-
from .base_command import TypeScriptBaseTextCommand, TypeScriptBaseWindowCommand
3+
from ..libs.view_helpers import *
4+
from .base_command import TypeScriptBaseTextCommand
55

66

77
class TypescriptErrorInfo(TypeScriptBaseTextCommand):
@@ -24,21 +24,4 @@ def run(self, text):
2424
if len(error_text) > 0:
2525
self.view.set_status("typescript_error", error_text)
2626
else:
27-
self.view.erase_status("typescript_error")
28-
29-
30-
class TypescriptProjectErrorList(TypeScriptBaseWindowCommand):
31-
32-
error_list_panel = None
33-
34-
def run(self):
35-
if not self.is_panel_active():
36-
TypescriptProjectErrorList.error_list_panel = self.window.create_output_panel("errorList")
37-
cli.node_client.startWorker()
38-
self.window.run_command("show_panel", {"panel": "output.errorList"})
39-
40-
def is_panel_active(self):
41-
view = TypescriptProjectErrorList.error_list_panel
42-
return view is not None and is_view_visible(view)
43-
44-
27+
self.view.erase_status("typescript_error")

typescript/commands/error_list.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from ..libs import global_vars
2+
from .base_command import TypeScriptBaseWindowCommand
3+
4+
class TypescriptProjectErrorList(TypeScriptBaseWindowCommand):
5+
6+
error_list_panel = None
7+
8+
def run(self):
9+
if not TypescriptProjectErrorList.error_list_panel:
10+
TypescriptProjectErrorList.error_list_panel = self.window.create_output_panel("errorList")
11+
12+
if not cli.node_client.workerStarted():
13+
view = active_view()
14+
# start worker process
15+
cli.node_client.startWorker()
16+
# load the active project
17+
get_info(view)
18+
# send the first error request
19+
cli.service.request_get_err_for_project(0, view.file_name())
20+
21+
global_vars._is_worker_active = True
22+
self.window.run_command("show_panel", {"panel": "output.errorList"})
23+
24+
@staticmethod
25+
def is_worker_active():
26+
panel = TypescriptProjectErrorList.error_list_panel
27+
return panel is not None and is_view_visible(panel)

typescript/libs/global_vars.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ def get_node_path():
3636

3737
TSC_PATH = os.path.join(PLUGIN_DIR, "tsserver", "tsc.js")
3838

39-
_project_error_list_started = False
40-
def is_project_error_list_started():
41-
return _project_error_list_started
42-
4339
# only Sublime Text 3 build after 3072 support tooltip
4440
TOOLTIP_SUPPORT = int(sublime.version()) >= 3072
4541

@@ -55,3 +51,8 @@ def is_project_error_list_started():
5551

5652
# idle time length in millisecond
5753
IDLE_TIME_LENGTH = 200
54+
55+
# if the worker process for error list is running
56+
_is_worker_active = False
57+
def is_worker_active():
58+
return _is_worker_active

typescript/libs/service_proxy.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,13 @@ def open(self, path):
120120
if self.__comm.workerStarted():
121121
self.__comm.postCmdToWorker(json_str)
122122

123+
def open_on_worker(self, path):
124+
args = {"file": path}
125+
req_dict = self.create_req_dict("open", args)
126+
json_str = json_helpers.encode(req_dict)
127+
if self.__comm.workerStarted():
128+
self.__comm.postCmdToWorker(json_str)
129+
123130
def close(self, path):
124131
args = {"file": path}
125132
req_dict = self.create_req_dict("close", args)

typescript/libs/view_helpers.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import codecs
1+
import codecs
22

33
from .global_vars import *
44
from .editor_client import cli
@@ -32,6 +32,7 @@ def __init__(self, filename, cc):
3232

3333

3434
_file_map = dict()
35+
_file_map_on_worker = dict()
3536

3637

3738
def get_info(view):
@@ -57,9 +58,17 @@ def get_info(view):
5758
reload_buffer(view, info.client_info)
5859
else:
5960
info.client_info.pending_changes = True
60-
# if info in most_recent_used_file_list:
61-
# most_recent_used_file_list.remove(info)
62-
# most_recent_used_file_list.append(info)
61+
62+
if is_worker_active():
63+
info_on_worker = _file_map_on_worker.get(file_name)
64+
if not info_on_worker:
65+
_file_map_on_worker[file_name] = info
66+
open_file_on_worker(view)
67+
if view.is_dirty():
68+
if not view.is_loading():
69+
reload_buffer_on_worker(view)
70+
else:
71+
_file_map_on_worker.clear()
6372
return info
6473

6574

@@ -133,6 +142,9 @@ def open_file(view):
133142
"""Open the file on the server"""
134143
cli.service.open(view.file_name())
135144

145+
def open_file_on_worker(view):
146+
"""Open the file on the worker process"""
147+
cli.service.open_on_worker(view.file_name())
136148

137149
def reconfig_file(view):
138150
host_info = "Sublime Text version " + str(sublime.version())
@@ -213,6 +225,22 @@ def reload_buffer(view, client_info=None):
213225
client_info.change_count = info.modify_count
214226
client_info.pending_changes = False
215227

228+
def reload_buffer_on_worker(view):
229+
"""Reload the buffer content on the worker process
230+
231+
Note: the worker process won't change the client_info object to avoid synchronization issues
232+
"""
233+
if not view.is_loading():
234+
tmpfile_name = get_tempfile_name()
235+
tmpfile = codecs.open(tmpfile_name, "w", "utf-8")
236+
text = view.substr(sublime.Region(0, view.size()))
237+
tmpfile.write(text)
238+
tmpfile.flush()
239+
if not IS_ST2:
240+
cli.service.reload_async(view.file_name(), tmpfile_name, recv_reload_response)
241+
else:
242+
reload_response = cli.service.reload(view.file_name(), tmpfile_name)
243+
recv_reload_response(reload_response)
216244

217245
def reload_required(view):
218246
client_info = cli.get_or_add_file(view.file_name())

typescript/listeners/project_error_list.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def __init__(self):
1515

1616
def on_activated_with_info(self, view, info):
1717
# Ask server for initial error diagnostics
18-
if is_project_error_list_started():
18+
if is_worker_active():
1919
self.request_errors(view, info, 200)
2020
self.set_on_idle_timer(IDLE_TIME_LENGTH)
2121
self.just_changed_focus = True
@@ -37,18 +37,16 @@ def handle_time_out(self):
3737
self.on_idle()
3838

3939
def on_idle(self):
40-
if cli.project_error_list_enabled:
41-
self.update_project_error_list()
40+
self.update_project_error_list()
4241

43-
view = active_view()
44-
info = get_info(view)
42+
info = get_info(active_view())
4543
if info:
4644
log.debug("asking for project errors")
4745
# request errors
4846
self.request_errors(view, info, 500)
4947

5048
def request_errors(self, view, info, error_delay):
51-
if info and cli.project_error_list_enabled and (
49+
if info and (
5250
self.just_changed_focus or
5351
info.change_count_when_last_err_req_sent < change_count(view)
5452
):

0 commit comments

Comments
 (0)