/// <summary> /// Main Entry point of the Server. /// </summary> /// <param name="args">Arguments: arg[0] the LogLevel (0=Lifecycle,1=Message,2=Protocol) - args[1] a Log File</param> /// <see cref="TypeCobol.LanguageServer.StdioHttp.ServerLogLevel"/> static void Main(string[] args) { ServerLogLevel logLevel; TextWriter logWriter; GetArguments(args, out logLevel, out logWriter); // Open log file try { // Configure the protocols stack var httpServer = new StdioHttpServer(Encoding.UTF8, logLevel, logWriter); var jsonRPCServer = new JsonRPCServer(httpServer); var languageServer = new TypeCobolServer(jsonRPCServer); // Start listening to incoming request (block, infinite loop) httpServer.StartReceivingMessagesFor(jsonRPCServer); } finally { if (logWriter != System.Console.Error) { logWriter.Close(); } } }
static int Main(string[] args) { bool help = false; bool version = false; var p = new OptionSet() { "USAGE", " " + ProgName + " [OPTIONS]", "", "VERSION:", " " + Version, "", "DESCRIPTION:", " Run the Language Server Robot.", { "l|loglevel=", "Logging level (1=Lifecycle, 2=Message, 3=Protocol).", (string v) => { if (v != null) { try { // args[0] : Trace level LogLevel = (ServerLogLevel)Int32.Parse(v); if (!System.Enum.IsDefined(typeof(ServerLogLevel), (Int32)LogLevel)) { LogLevel = ServerLogLevel.Protocol; } } catch (Exception e) { System.Console.Error.WriteLine(e.Message); } } } }, { "v|version", "Show version", _ => version = true }, { "h|help", "Show help", _ => help = true }, { "lf|logfile=", "{PATH} the target log file", (string v) => LogFile = v }, { "nologs", "No log message notifications", _ => NoLogsMessageNotification = true }, { "r|robot", "Robot Client mode.", _ => LsrMode = true }, { "lsr=", "{PATH} the lsr path", (string v) => LsrPath = v }, { "s|script=", "{PATH} script path in lsr", (string v) => LsrScript = v }, { "td|timerdisabled", "Disable the delay that handle the automatic launch of Node Phase analyze", _ => TimerDisabledOption = true }, { "ro|roptions=", "LSR options", (string v) => LsrOptions = v + " " }, { "tsource", "Source document testing mode.", _ => LsrSourceTesting = true }, { "tscanner", "Scanner testing mode.", _ => LsrScannerTesting = true }, { "tpreprocess", "Preprocessing testing mode.", _ => LsrPreprocessTesting = true }, { "tparser", "parsing testing mode.", _ => LsrParserTesting = true }, { "tsemantic", "Semantic analysis testing mode.", _ => LsrSemanticTesting = true }, { "antlrp", "Use ANTLR to parse a Program.", _ => UseAntlrProgramParsing = true }, }; System.Collections.Generic.List <string> arguments; try { arguments = p.Parse(args); } catch (OptionException ex) { return(exit(1, ex.Message)); } if (help) { p.WriteOptionDescriptions(System.Console.Out); return(0); } if (version) { System.Console.WriteLine(Version); return(0); } TextWriter logWriter = null; if (LogFile != null) { try { StreamWriter sw = new StreamWriter(LogFile); sw.AutoFlush = true; logWriter = sw; } catch (Exception e) { if (!LsrMode) { System.Console.Error.WriteLine(e.Message); } } } if (logWriter == null) { logWriter = new DebugTextWriter(); } if (LsrMode && LsrPath != null && LsrScript != null) { if (!StartLsr(LsrPath, (LsrOptions ?? "") + "-ioc -c -script=" + LsrScript)) { System.Console.Error.WriteLine("Fail to run LSR process"); return(-1); } } //Run this server try { //Queue storing messages coming from client, this queue is read by readingThread MessagesActionQueue = new Queue <MessageActionWrapper>(); // Configure the protocols stack var httpServer = new StdioHttpServer(Encoding.UTF8, LogLevel, logWriter, MessagesActionQueue); httpServer.IsLsrTdMode = TimerDisabledOption; if (Process != null) { httpServer.RedirectedInputStream = Process.StandardOutput.BaseStream; httpServer.RedirectedOutpuStream = Process.StandardInput; } var jsonRPCServer = new JsonRPCServer(httpServer); var typeCobolServer = new TypeCobolServer(jsonRPCServer, MessagesActionQueue); typeCobolServer.NoLogsMessageNotification = NoLogsMessageNotification; typeCobolServer.LsrSourceTesting = LsrSourceTesting; typeCobolServer.LsrScannerTesting = LsrScannerTesting; typeCobolServer.LsrPreprocessTesting = LsrPreprocessTesting; typeCobolServer.LsrParserTesting = LsrParserTesting; typeCobolServer.LsrSemanticTesting = LsrSemanticTesting; typeCobolServer.TimerDisabledOption = TimerDisabledOption; typeCobolServer.UseAntlrProgramParsing = UseAntlrProgramParsing; //Creating the thread that will read mesages and handle them var backgroundExecutionThread = new Thread(() => { MessageHandler(jsonRPCServer, typeCobolServer); }) { IsBackground = true }; backgroundExecutionThread.Start(); // Start listening to incoming request (block, infinite loop) httpServer.StartReceivingMessagesFor(jsonRPCServer); } finally { if (logWriter != System.Console.Error) { logWriter.Close(); } } return(0); }