Skip to content

Commit

Permalink
Merge pull request #730 from mattbroussard/node-args
Browse files Browse the repository at this point in the history
Add node_args, tsserver_args, tsserver_env options
  • Loading branch information
Orta authored Jan 15, 2020
2 parents 37609cd + 498b0a1 commit 913aefc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ These settings can be overridden in `Packages/User/TypeScript.sublime-settings`,
- `error_icon`: specifies a gutter icon, defaults to nothing can be set to `"dot"`, `"circle"`, `"bookmark"` or any other value accepted by Sublime Text
- `error_outlined`: will draw type errors with a solid outline instead of the default which is a squiggly line underneath
- `quick_info_popup_max_width`: the max width of the quick info popup, default 1024
- `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)
- `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)
- `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.

Project System
------
Expand Down
21 changes: 15 additions & 6 deletions typescript/libs/node_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ def __init__(self, script_path):
# start node process
pref_settings = sublime.load_settings('Preferences.sublime-settings')
node_path = pref_settings.get('node_path')
node_args = pref_settings.get('node_args', [])
tsserver_args = pref_settings.get('tsserver_args', [])
tsserver_env = dict(os.environ, **pref_settings.get('tsserver_env', {}))
if node_path:
print("Path of node executable is configured as: " + node_path)
configured_node_path = os.path.expandvars(node_path)
Expand All @@ -262,17 +265,18 @@ def __init__(self, script_path):
global_vars._node_path = node_path
print("Trying to spawn node executable from: " + node_path)
try:
node_process_cmd = [node_path] + node_args + [script_path, "--disableAutomaticTypingAcquisition"] + tsserver_args
if os.name == "nt":
# linux subprocess module does not have STARTUPINFO
# so only use it if on Windows
si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.SW_HIDE | subprocess.STARTF_USESHOWWINDOW
self.server_proc = subprocess.Popen([node_path, script_path, "--disableAutomaticTypingAcquisition"],
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, startupinfo=si, bufsize=-1)
self.server_proc = subprocess.Popen(node_process_cmd,
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, env=tsserver_env, startupinfo=si, bufsize=-1)
else:
log.debug("opening " + node_path + " " + script_path)
self.server_proc = subprocess.Popen([node_path, script_path, "--disableAutomaticTypingAcquisition"],
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, bufsize=-1)
self.server_proc = subprocess.Popen(node_process_cmd,
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, env=tsserver_env, bufsize=-1)
except:
self.server_proc = None
# start reader thread
Expand Down Expand Up @@ -303,15 +307,20 @@ def start(self):
WorkerClient.stop_worker = False

node_path = global_vars.get_node_path()
node_args = pref_settings.get('node_args', [])
tsserver_args = pref_settings.get('tsserver_args', [])
tsserver_env = dict(os.environ, **pref_settings.get('tsserver_env', {}))
node_process_cmd = [node_path] + node_args + [self.script_path, "--disableAutomaticTypingAcquisition"] + tsserver_args

if os.name == "nt":
si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.SW_HIDE | subprocess.STARTF_USESHOWWINDOW
self.server_proc = subprocess.Popen(
[node_path, self.script_path, "--disableAutomaticTypingAcquisition"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, startupinfo=si, bufsize=-1
node_process_cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, env=tsserver_env, startupinfo=si, bufsize=-1
)
else:
self.server_proc = subprocess.Popen(
[node_path, self.script_path, "--disableAutomaticTypingAcquisition"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, bufsize=-1)
node_process_cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, env=tsserver_env, bufsize=-1)

# start reader thread
if self.server_proc and (not self.server_proc.poll()):
Expand Down

0 comments on commit 913aefc

Please sign in to comment.