def main(args=None, after_bind=lambda server: None, language_server_class=None): original_args = args if args is not None else sys.argv[1:] try: import robotframework_ls except ImportError: # Automatically add it to the path if __main__ is being executed. sys.path.append( os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import robotframework_ls # @UnusedImport robotframework_ls.import_robocorp_ls_core() from robotframework_ls.options import Setup, Options from robocorp_ls_core.robotframework_log import ( configure_logger, log_args_and_python, get_logger, ) from robocorp_ls_core.python_ls import ( start_io_lang_server, start_tcp_lang_server, binary_stdio, ) if language_server_class is None: from robotframework_ls.robotframework_ls_impl import ( RobotFrameworkLanguageServer, ) language_server_class = RobotFrameworkLanguageServer parser = argparse.ArgumentParser() add_arguments(parser) args = parser.parse_args(args=original_args) if args.version: sys.stdout.write(robotframework_ls.__version__) sys.stdout.flush() return Setup.options = Options(args) verbose = args.verbose log_file = args.log_file or "" configure_logger("lsp", verbose, log_file) log = get_logger("robotframework_ls.__main__") log_args_and_python(log, original_args, robotframework_ls.__version__) if args.tcp: start_tcp_lang_server(args.host, args.port, language_server_class, after_bind=after_bind) else: stdin, stdout = binary_stdio() start_io_lang_server(stdin, stdout, language_server_class)
def main(args=None, language_server_class=None): original_args = args if args is not None else sys.argv[1:] parser = argparse.ArgumentParser() add_arguments(parser) args = parser.parse_args(args=original_args) verbose = args.verbose log_file = args.log_file or "" try: try: import robotframework_interactive except ImportError: # Automatically add it to the path if __main__ is being executed. sys.path.append( os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import robotframework_interactive # @UnusedImport robotframework_interactive.import_robocorp_ls_core() from robocorp_ls_core.robotframework_log import ( configure_logger, log_args_and_python, get_logger, ) except: # Failed before having setup the logger (but after reading args). log_file = os.path.expanduser(log_file) log_file = os.path.realpath(os.path.abspath(log_file)) dirname = os.path.dirname(log_file) basename = os.path.basename(log_file) try: os.makedirs(dirname) except: pass # Ignore error if it already exists. name, ext = os.path.splitext(basename) postfix = "rf_interactive.init" log_file = os.path.join( dirname, name + "." + postfix + "." + str(os.getpid()) + ext) with open(log_file, "a+") as stream: traceback.print_exc(file=stream) raise if args.version: sys.stdout.write(robotframework_interactive.__version__) sys.stdout.flush() return configure_logger("rfinteractive", verbose, log_file) log = get_logger("robotframework_interactive.__main__") log_args_and_python(log, original_args, robotframework_interactive) try: from robotframework_interactive.server.options import Setup, Options Setup.options = Options(args) # Ok, now that we have our options, let's connect back. from robocorp_ls_core.python_ls import ( start_io_lang_server, start_tcp_lang_client, binary_stdio, ) if args.tcp: start_tcp_lang_client(args.host, args.port, language_server_class) else: stdin, stdout = binary_stdio() start_io_lang_server(stdin, stdout, language_server_class) except: log.exception("Error initializing") raise
def main(): """ Starts the debug adapter (creates a thread to read from stdin and another to write to stdout as expected by the vscode debug protocol). We pass the command processor to the reader thread as the idea is that the reader thread will read a message, convert it to an instance of the message in the schema and then forward it to the command processor which will interpret and act on it, posting the results to the writer queue. """ log = None try: import sys if sys.version_info[0] <= 2: raise AssertionError( "Python 3+ is required for the RobotFramework Debug Adapter.\nCurrent executable: " + sys.executable) try: import robotframework_debug_adapter import robotframework_ls except ImportError: # Automatically add it to the path if __main__ is being executed. sys.path.append( os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import robotframework_debug_adapter # @UnusedImport import robotframework_ls robotframework_ls.import_robocorp_ls_core() from robocorp_ls_core.debug_adapter_core.debug_adapter_threads import ( STOP_WRITER_THREAD, ) from robocorp_ls_core.robotframework_log import ( get_logger, configure_logger, log_args_and_python, ) from robotframework_debug_adapter.constants import LOG_FILENAME from robotframework_debug_adapter.constants import LOG_LEVEL configure_logger("dap", LOG_LEVEL, LOG_FILENAME) log = get_logger("robotframework_debug_adapter.__main__") log_args_and_python(log, sys.argv, robotframework_ls.__version__) from robocorp_ls_core.debug_adapter_core.debug_adapter_threads import ( reader_thread, ) from robocorp_ls_core.debug_adapter_core.debug_adapter_threads import ( writer_thread, ) from robotframework_debug_adapter.debug_adapter_comm import DebugAdapterComm try: from queue import Queue except ImportError: from Queue import Queue to_client_queue = Queue() comm = DebugAdapterComm(to_client_queue) write_to = sys.stdout read_from = sys.stdin if sys.version_info[0] <= 2: if sys.platform == "win32": # must read streams as binary on windows import msvcrt msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) else: # Py3 write_to = sys.stdout.buffer read_from = sys.stdin.buffer writer = threading.Thread( target=writer_thread, args=(write_to, to_client_queue, "write to client"), name="Write to client (dap __main__)", ) reader = threading.Thread( target=reader_thread, args=(read_from, comm.from_client, to_client_queue, b"read from client"), name="Read from client (dap __main__)", ) reader.start() writer.start() reader.join() log.debug("Exited reader.\n") to_client_queue.put(STOP_WRITER_THREAD) writer.join() log.debug("Exited writer.\n") except: if log is not None: log.exception("Error") # Critical error (the logging may not be set up properly). # Print to file and stderr. with open(_critical_error_log_file, "a+") as stream: traceback.print_exc(file=stream) traceback.print_exc() finally: if log is not None: log.debug("Exited main.\n")
def main(args=None, after_bind=lambda server: None, language_server_class=None): original_args = args if args is not None else sys.argv[1:] try: import robotframework_ls except ImportError: # Automatically add it to the path if __main__ is being executed. sys.path.append( os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import robotframework_ls # @UnusedImport robotframework_ls.import_robocorp_ls_core() from robotframework_ls.options import Setup, Options from robocorp_ls_core.robotframework_log import ( configure_logger, log_args_and_python, get_logger, ) from robocorp_ls_core.python_ls import ( start_io_lang_server, start_tcp_lang_server, binary_stdio, ) if language_server_class is None: from robotframework_ls.robotframework_ls_impl import ( RobotFrameworkLanguageServer, ) language_server_class = RobotFrameworkLanguageServer parser = argparse.ArgumentParser() add_arguments(parser) args = parser.parse_args(args=original_args) if args.version: sys.stdout.write(robotframework_ls.__version__) sys.stdout.flush() return Setup.options = Options(args) verbose = args.verbose log_file = args.log_file or "" if not log_file: # If not specified in args, also check the environment variables. log_file = os.environ.get("ROBOTFRAMEWORK_LS_LOG_FILE", "") if log_file: # If the log file comes from the environment, make sure the log-level # also comes from it (with a log-level==2 by default). Setup.options.log_file = log_file try: verbose = int( os.environ.get("ROBOTFRAMEWORK_LS_LOG_LEVEL", "2")) except: verbose = 2 Setup.options.verbose = verbose configure_logger("lsp", verbose, log_file) log = get_logger("robotframework_ls.__main__") log_args_and_python(log, original_args, robotframework_ls) if args.tcp: start_tcp_lang_server(args.host, args.port, language_server_class, after_bind=after_bind) else: stdin, stdout = binary_stdio() start_io_lang_server(stdin, stdout, language_server_class)
def main(): src_folder = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) try: import robotframework_ls except ImportError: # Automatically add it to the path if __main__ is being executed. assert os.path.exists(src_folder), "Expected: %s to exist" % (src_folder,) sys.path.append(src_folder) import robotframework_ls # @UnusedImport robotframework_ls.import_robocorp_ls_core() from robocorp_ls_core.robotframework_log import ( configure_logger, log_args_and_python, ) from robotframework_debug_adapter.constants import LOG_FILENAME from robotframework_debug_adapter.constants import LOG_LEVEL configure_logger("robot", LOG_LEVEL, LOG_FILENAME) log = get_log() log_args_and_python(log, sys.argv, robotframework_ls.__version__) from robotframework_ls.options import DEFAULT_TIMEOUT args = sys.argv[1:] assert args[0] == "--port" port = args[1] debug = True if args[2] == "--debug" else False robot_args = args[3:] if debug: robot_args = [ "--listener=robotframework_debug_adapter.listeners.DebugListener", "--listener=robotframework_debug_adapter.listeners.DebugListenerV2", ] + robot_args s = connect(int(port)) processor = _RobotTargetComm(s, debug=debug) processor.start_communication_threads() if not processor.configuration_done.wait(DEFAULT_TIMEOUT): sys.stderr.write( "Process not configured for launch in the available timeout.\n" ) sys.exit(1) try: try: import robot except ImportError: sys.stderr.write("\nError importing robot.\n") sys.stderr.write("Python executable: %s.\n\n" % (sys.executable,)) raise from robot import run_cli exitcode = run_cli(robot_args, exit=False) finally: processor.terminate() if processor.terminated.wait(2): log.debug("Processed dap terminate event in robot.") sys.exit(exitcode)
def main(): src_folder = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) try: import robotframework_ls except ImportError: # Automatically add it to the path if __main__ is being executed. assert os.path.exists( src_folder), "Expected: %s to exist" % (src_folder, ) sys.path.append(src_folder) import robotframework_ls # @UnusedImport robotframework_ls.import_robocorp_ls_core() from robocorp_ls_core.robotframework_log import ( configure_logger, log_args_and_python, close_logging_streams, ) from robotframework_debug_adapter.constants import LOG_FILENAME from robotframework_debug_adapter.constants import LOG_LEVEL configure_logger("robot", LOG_LEVEL, LOG_FILENAME) log = get_log() log_args_and_python(log, sys.argv, robotframework_ls) from robotframework_ls.options import DEFAULT_TIMEOUT args = sys.argv[1:] assert args[0] == "--port" port = int(args[1]) debug = True if args[2] == "--debug" else False robot_args = args[3:] if debug: robot_args = [ "--listener=robotframework_debug_adapter.listeners.DebugListener", "--listener=robotframework_debug_adapter.listeners.DebugListenerV2", ] + robot_args s = connect(port) if debug: # Make sure that we can use pydevd (initialize only in debug mode). import robotframework_debug_adapter.vendored.force_pydevd # @UnusedImport import pydevd pydevd.settrace( "127.0.0.1", port=port, suspend=False, trace_only_current_thread=False, overwrite_prev_trace=True, patch_multiprocessing=False, block_until_connected=True, wait_for_ready_to_run=False, notify_stdin=False, ) processor = _RobotTargetComm(s, debug=debug) reader, writer = processor.start_communication_threads(debug) if not processor.configuration_done.wait(DEFAULT_TIMEOUT): sys.stderr.write( "Process not configured for launch in the available timeout.\n") sys.exit(1) try: try: import robot except ImportError: sys.stderr.write("\nError importing robot.\n") sys.stderr.write("Python executable: %s.\n\n" % (sys.executable, )) raise from robot import run_cli exitcode = run_cli(robot_args, exit=False) finally: processor.terminate() if processor.terminated.wait(2): log.debug("Processed dap terminate event in robot.") close_logging_streams() sys.exit(exitcode)