Skip to content

Commit 313ac70

Browse files
committed
Merge pull request #210 from zhengbli/addBuildModule
Add build module
2 parents ed39511 + 1ede13b commit 313ac70

File tree

9 files changed

+44042
-6225
lines changed

9 files changed

+44042
-6225
lines changed

TypeScript.sublime-build

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"target": "typescript_build",
3+
"selector": "source.ts"
4+
}

tsserver/tsc.js

Lines changed: 31041 additions & 0 deletions
Large diffs are not rendered by default.

tsserver/tsserver.js

Lines changed: 12938 additions & 6223 deletions
Large diffs are not rendered by default.

typescript/commands/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
TypescriptFinishRenameCommand,
2828
TypescriptRenameCommand
2929
)
30+
from .build import TypescriptBuildCommand
3031

3132
__all__ = [
3233
"TypescriptAutoIndentOnEnterBetweenCurlyBrackets",
@@ -54,5 +55,6 @@
5455
"TypescriptSave",
5556
"TypescriptShowDoc",
5657
"TypescriptSignaturePanel",
57-
"TypescriptSignaturePopup"
58+
"TypescriptSignaturePopup",
59+
"TypescriptBuildCommand"
5860
]

typescript/commands/build.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import sublime_plugin
2+
3+
from ..libs.global_vars import *
4+
from ..libs import cli
5+
6+
7+
class TypescriptBuildCommand(sublime_plugin.WindowCommand):
8+
def run(self):
9+
if get_node_path() is None:
10+
print("Cannot find node. Build cancelled.")
11+
return
12+
13+
file_name = self.window.active_view().file_name()
14+
project_info = cli.service.project_info(file_name)
15+
if project_info["success"]:
16+
if "configFileName" in project_info["body"]:
17+
tsconfig_dir = dirname(project_info["body"]["configFileName"])
18+
self.window.run_command("exec", {
19+
"cmd": [get_node_path(), TSC_PATH, "-p", tsconfig_dir],
20+
# regex to capture build result for displaying in the output panel
21+
"file_regex": "^(.+?)\\((\\d+),(\\d+)\\): (.+)$"
22+
})
23+
else:
24+
sublime.active_window().show_input_panel(
25+
"Build parameters: ",
26+
"", # initial text
27+
lambda params: self.compile_inferred_project(file_name, params),
28+
None, # on change
29+
None # on cancel
30+
)
31+
32+
def compile_inferred_project(self, file_name, params=""):
33+
cmd = [get_node_path(), TSC_PATH, file_name]
34+
print(cmd)
35+
if params != "":
36+
cmd.extend(params.split(' '))
37+
self.window.run_command("exec", {
38+
"cmd": cmd,
39+
"file_regex": "^(.+?)\\((\\d+),(\\d+)\\): (.+)$"
40+
})

typescript/libs/editor_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def get_ref_info(self):
109109

110110
def get_or_add_file(self, filename):
111111
"""Get or add per-file information that must be globally accessible """
112-
if (os.name == "nt") and filename:
112+
if os.name == "nt" and filename:
113113
filename = filename.replace('/', '\\')
114114
if filename not in self.file_map:
115115
client_info = ClientFileInfo(filename)

typescript/libs/global_vars.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@
2929
PLUGIN_DIR = dirname(dirname(dirname(os.path.abspath(__file__))))
3030
PLUGIN_NAME = os.path.basename(PLUGIN_DIR)
3131

32+
# The node path will be initialized in the node_client.py module
33+
_node_path = None
34+
def get_node_path():
35+
return _node_path
36+
37+
TSC_PATH = os.path.join(PLUGIN_DIR, "tsserver", "tsc.js")
38+
3239
# only Sublime Text 3 build after 3072 support tooltip
3340
TOOLTIP_SUPPORT = int(sublime.version()) >= 3072
3441

typescript/libs/node_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from .logger import log
1010
from . import json_helpers
11+
from . import global_vars
1112

1213
# queue module name changed from Python 2 to 3
1314
if int(sublime.version()) < 3000:
@@ -60,6 +61,7 @@ def __init__(self, scriptPath):
6061
print("To specify the node executable file name, use the 'node_path' setting")
6162
self.__serverProc = None
6263
else:
64+
global_vars._node_path = node_path
6365
print("Found node executable at " + node_path)
6466
try:
6567
if os.name == "nt":

typescript/libs/service_proxy.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ def nav_to(self, search_text, file_name):
187187
response_dict = self.__comm.sendCmdSync(json_str, req_dict["seq"])
188188
return response_dict
189189

190+
def project_info(self, file_name, need_file_name_list=False):
191+
args = {"file": file_name, "needFileNameList": need_file_name_list}
192+
req_dict = self.create_req_dict("projectInfo", args)
193+
json_str = json_helpers.encode(req_dict)
194+
return self.__comm.sendCmdSync(json_str, req_dict["seq"])
195+
190196
def create_req_dict(self, command_name, args=None):
191197
req_dict = {
192198
"command": command_name,

0 commit comments

Comments
 (0)