From 7be868e1f50023d31bbc5c491d3e82dd60486181 Mon Sep 17 00:00:00 2001 From: Matthew Broussard Date: Tue, 5 Nov 2019 17:13:33 -0800 Subject: [PATCH 1/2] Add node_args, tsserver_args, tsserver_env options --- README.md | 3 +++ typescript/libs/global_vars.py | 2 +- typescript/libs/logger.py | 2 +- typescript/libs/node_client.py | 21 +++++++++++++++------ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 06e695cb..0f3748da 100644 --- a/README.md +++ b/README.md @@ -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 ------ diff --git a/typescript/libs/global_vars.py b/typescript/libs/global_vars.py index 84e45f2b..370b721d 100644 --- a/typescript/libs/global_vars.py +++ b/typescript/libs/global_vars.py @@ -47,7 +47,7 @@ def get_tsc_path(): # set logging levels LOG_FILE_LEVEL = logging.WARN -LOG_CONSOLE_LEVEL = logging.WARN +LOG_CONSOLE_LEVEL = logging.DEBUG # WARN NON_BLANK_LINE_PATTERN = re.compile("[\S]+") VALID_COMPLETION_ID_PATTERN = re.compile("[a-zA-Z_$\.][\w$\.]*\Z") diff --git a/typescript/libs/logger.py b/typescript/libs/logger.py index fcfb270b..55f1e94e 100644 --- a/typescript/libs/logger.py +++ b/typescript/libs/logger.py @@ -17,7 +17,7 @@ filePath = path.join(_pluginRoot, 'TS.log') log = logging.getLogger('TS') -log.setLevel(logging.WARN) +log.setLevel(logging.DEBUG) _logFormat = logging.Formatter('%(asctime)s: %(thread)d: %(levelname)s: %(message)s') diff --git a/typescript/libs/node_client.py b/typescript/libs/node_client.py index 7f20698a..ab979588 100644 --- a/typescript/libs/node_client.py +++ b/typescript/libs/node_client.py @@ -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) @@ -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 @@ -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()): From 498b0a1f9bb665f5246162edc163ec7ca8eeb9b0 Mon Sep 17 00:00:00 2001 From: Matthew Broussard Date: Tue, 5 Nov 2019 17:15:31 -0800 Subject: [PATCH 2/2] undo log config changes made for dev & accidentally committed --- typescript/libs/global_vars.py | 2 +- typescript/libs/logger.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/typescript/libs/global_vars.py b/typescript/libs/global_vars.py index 370b721d..84e45f2b 100644 --- a/typescript/libs/global_vars.py +++ b/typescript/libs/global_vars.py @@ -47,7 +47,7 @@ def get_tsc_path(): # set logging levels LOG_FILE_LEVEL = logging.WARN -LOG_CONSOLE_LEVEL = logging.DEBUG # WARN +LOG_CONSOLE_LEVEL = logging.WARN NON_BLANK_LINE_PATTERN = re.compile("[\S]+") VALID_COMPLETION_ID_PATTERN = re.compile("[a-zA-Z_$\.][\w$\.]*\Z") diff --git a/typescript/libs/logger.py b/typescript/libs/logger.py index 55f1e94e..fcfb270b 100644 --- a/typescript/libs/logger.py +++ b/typescript/libs/logger.py @@ -17,7 +17,7 @@ filePath = path.join(_pluginRoot, 'TS.log') log = logging.getLogger('TS') -log.setLevel(logging.DEBUG) +log.setLevel(logging.WARN) _logFormat = logging.Formatter('%(asctime)s: %(thread)d: %(levelname)s: %(message)s')