def GetServerEnvironment(self): env = os.environ.copy() utils.SetEnviron(env, 'RUSTC', self._rustc_binary_path) if LOGGER.isEnabledFor(logging.DEBUG): utils.SetEnviron(env, 'RUST_LOG', 'rls=trace') utils.SetEnviron(env, 'RUST_BACKTRACE', '1') return env
def GetServerEnvironment(self): env = os.environ.copy() # Force RLS to use the rustc from the toolchain in third_party/rls. # TODO: allow users to pick a custom toolchain. utils.SetEnviron(env, 'RUSTC', RUSTC_EXECUTABLE) if LOGGER.isEnabledFor(logging.DEBUG): utils.SetEnviron(env, 'RUST_LOG', 'rls=trace') utils.SetEnviron(env, 'RUST_BACKTRACE', '1') return env
def _StartServer(self): with self._server_lock: if self._ServerIsRunning(): return self._logfile = _LogFileName() tsserver_log = '-file {path} -level {level}'.format( path=self._logfile, level=_LogLevel()) # TSServer gets the configuration for the log file through the # environment variable 'TSS_LOG'. This seems to be undocumented but # looking at the source code it seems like this is the way: # https://github.com/Microsoft/TypeScript/blob/8a93b489454fdcbdf544edef05f73a913449be1d/src/server/server.ts#L136 environ = os.environ.copy() utils.SetEnviron(environ, 'TSS_LOG', tsserver_log) _logger.info('TSServer log file: {0}'.format(self._logfile)) # We need to redirect the error stream to the output one on Windows. self._tsserver_handle = utils.SafePopen(PATH_TO_TSSERVER, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=environ) self._tsserver_is_running.set()
def __init__(self, user_options): super(TypeScriptCompleter, self).__init__(user_options) # Used to prevent threads from concurrently writing to # the tsserver process' stdin self._writelock = Lock() binarypath = utils.PathToFirstExistingExecutable(['tsserver']) if not binarypath: _logger.error(BINARY_NOT_FOUND_MESSAGE) raise RuntimeError(BINARY_NOT_FOUND_MESSAGE) self._logfile = _LogFileName() tsserver_log = '-file {path} -level {level}'.format(path=self._logfile, level=_LogLevel()) # TSServer get the configuration for the log file through the environment # variable 'TSS_LOG'. This seems to be undocumented but looking at the # source code it seems like this is the way: # https://github.com/Microsoft/TypeScript/blob/8a93b489454fdcbdf544edef05f73a913449be1d/src/server/server.ts#L136 self._environ = os.environ.copy() utils.SetEnviron(self._environ, 'TSS_LOG', tsserver_log) # Each request sent to tsserver must have a sequence id. # Responses contain the id sent in the corresponding request. self._sequenceid = itertools.count() # Used to prevent threads from concurrently accessing the sequence counter self._sequenceid_lock = Lock() # TSServer ignores the fact that newlines are two characters on Windows # (\r\n) instead of one on other platforms (\n), so we use the # universal_newlines option to convert those newlines to \n. See the issue # https://github.com/Microsoft/TypeScript/issues/3403 # TODO: remove this option when the issue is fixed. # We also need to redirect the error stream to the output one on Windows. self._tsserver_handle = utils.SafePopen(binarypath, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT, env=self._environ, universal_newlines=True) # Used to map sequence id's to their corresponding DeferredResponse # objects. The reader loop uses this to hand out responses. self._pending = {} # Used to prevent threads from concurrently reading and writing to # the pending response dictionary self._pendinglock = Lock() # Start a thread to read response from TSServer. self._thread = Thread(target=self._ReaderLoop, args=()) self._thread.daemon = True self._thread.start() _logger.info('Enabling typescript completion')
def __init__(self, user_options): super(TypeScriptCompleter, self).__init__(user_options) self._tsserver_handle = None # Used to prevent threads from concurrently writing to # the tsserver process' stdin self._write_lock = threading.Lock() # TODO: if we follow the path of tern_completer we can extract a # `ShouldEnableTypescriptCompleter` and use it in hook.py self._binary_path = utils.PathToFirstExistingExecutable(['tsserver']) if not self._binary_path: _logger.error(BINARY_NOT_FOUND_MESSAGE) raise RuntimeError(BINARY_NOT_FOUND_MESSAGE) _logger.info('Found TSServer at {0}'.format(self._binary_path)) self._logfile = _LogFileName() tsserver_log = '-file {path} -level {level}'.format(path=self._logfile, level=_LogLevel()) # TSServer get the configuration for the log file through the environment # variable 'TSS_LOG'. This seems to be undocumented but looking at the # source code it seems like this is the way: # https://github.com/Microsoft/TypeScript/blob/8a93b489454fdcbdf544edef05f73a913449be1d/src/server/server.ts#L136 self._environ = os.environ.copy() utils.SetEnviron(self._environ, 'TSS_LOG', tsserver_log) _logger.info('TSServer log file: {0}'.format(self._logfile)) # Each request sent to tsserver must have a sequence id. # Responses contain the id sent in the corresponding request. self._sequenceid = itertools.count() # Used to prevent threads from concurrently accessing the sequence counter self._sequenceid_lock = threading.Lock() self._server_lock = threading.RLock() # We first start the server and then the response-reading queue, so it will # certainly find a responding TSServer. self._StartServer() # Used to map sequence id's to their corresponding DeferredResponse # objects. The reader loop uses this to hand out responses. self._pending = {} # Used to prevent threads from concurrently reading and writing to # the pending response dictionary self._pending_lock = threading.Lock() # Start a thread to read response from TSServer. self._thread = threading.Thread(target=self._ReaderLoop, args=()) self._thread.daemon = True self._thread.start() _logger.info('Enabling typescript completion')
def SetEnviron_UnicodeOnWindows_test(*args): env = {} utils.SetEnviron(env, u'key', u'value') eq_(env, {native(bytes(b'key')): native(bytes(b'value'))})
def SetEnviron_UnicodeOnUnix_test(*args): env = {} utils.SetEnviron(env, u'key', u'value') eq_(env, {u'key': u'value'})
def SetEnviron_UnicodeNotOnWindows_test(*args): env = {} utils.SetEnviron(env, u'key', u'value') eq_(env, {u'key': u'value'})