Skip to content

Commit 913aefc

Browse files
author
Orta
authored
Merge pull request #730 from mattbroussard/node-args
Add node_args, tsserver_args, tsserver_env options
2 parents 37609cd + 498b0a1 commit 913aefc

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ These settings can be overridden in `Packages/User/TypeScript.sublime-settings`,
102102
- `error_icon`: specifies a gutter icon, defaults to nothing can be set to `"dot"`, `"circle"`, `"bookmark"` or any other value accepted by Sublime Text
103103
- `error_outlined`: will draw type errors with a solid outline instead of the default which is a squiggly line underneath
104104
- `quick_info_popup_max_width`: the max width of the quick info popup, default 1024
105+
- `node_args`: array of command line arguments sent to the tsserver Node.js process before the tsserver script path (useful for e.g. changing max heap size or attaching debugger to the tsserver process)
106+
- `tsserver_args`: array of command line arguments sent to tsserver Node.js process after the tsserver script path (useful for e.g. overriding tsserver error message locale)
107+
- `tsserver_env`: environment variables to set for the tsserver Node.js process (useful for e.g. setting `TSS_LOG`). These variables are merged with the environment variables available to Sublime.
105108

106109
Project System
107110
------

typescript/libs/node_client.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ def __init__(self, script_path):
240240
# start node process
241241
pref_settings = sublime.load_settings('Preferences.sublime-settings')
242242
node_path = pref_settings.get('node_path')
243+
node_args = pref_settings.get('node_args', [])
244+
tsserver_args = pref_settings.get('tsserver_args', [])
245+
tsserver_env = dict(os.environ, **pref_settings.get('tsserver_env', {}))
243246
if node_path:
244247
print("Path of node executable is configured as: " + node_path)
245248
configured_node_path = os.path.expandvars(node_path)
@@ -262,17 +265,18 @@ def __init__(self, script_path):
262265
global_vars._node_path = node_path
263266
print("Trying to spawn node executable from: " + node_path)
264267
try:
268+
node_process_cmd = [node_path] + node_args + [script_path, "--disableAutomaticTypingAcquisition"] + tsserver_args
265269
if os.name == "nt":
266270
# linux subprocess module does not have STARTUPINFO
267271
# so only use it if on Windows
268272
si = subprocess.STARTUPINFO()
269273
si.dwFlags |= subprocess.SW_HIDE | subprocess.STARTF_USESHOWWINDOW
270-
self.server_proc = subprocess.Popen([node_path, script_path, "--disableAutomaticTypingAcquisition"],
271-
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, startupinfo=si, bufsize=-1)
274+
self.server_proc = subprocess.Popen(node_process_cmd,
275+
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, env=tsserver_env, startupinfo=si, bufsize=-1)
272276
else:
273277
log.debug("opening " + node_path + " " + script_path)
274-
self.server_proc = subprocess.Popen([node_path, script_path, "--disableAutomaticTypingAcquisition"],
275-
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, bufsize=-1)
278+
self.server_proc = subprocess.Popen(node_process_cmd,
279+
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, env=tsserver_env, bufsize=-1)
276280
except:
277281
self.server_proc = None
278282
# start reader thread
@@ -303,15 +307,20 @@ def start(self):
303307
WorkerClient.stop_worker = False
304308

305309
node_path = global_vars.get_node_path()
310+
node_args = pref_settings.get('node_args', [])
311+
tsserver_args = pref_settings.get('tsserver_args', [])
312+
tsserver_env = dict(os.environ, **pref_settings.get('tsserver_env', {}))
313+
node_process_cmd = [node_path] + node_args + [self.script_path, "--disableAutomaticTypingAcquisition"] + tsserver_args
314+
306315
if os.name == "nt":
307316
si = subprocess.STARTUPINFO()
308317
si.dwFlags |= subprocess.SW_HIDE | subprocess.STARTF_USESHOWWINDOW
309318
self.server_proc = subprocess.Popen(
310-
[node_path, self.script_path, "--disableAutomaticTypingAcquisition"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, startupinfo=si, bufsize=-1
319+
node_process_cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, env=tsserver_env, startupinfo=si, bufsize=-1
311320
)
312321
else:
313322
self.server_proc = subprocess.Popen(
314-
[node_path, self.script_path, "--disableAutomaticTypingAcquisition"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, bufsize=-1)
323+
node_process_cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, env=tsserver_env, bufsize=-1)
315324

316325
# start reader thread
317326
if self.server_proc and (not self.server_proc.poll()):

0 commit comments

Comments
 (0)