public static void CSSCompletion() { TestScript(script => { Console.Write("CS-Script Autocompletion: "); File.WriteAllText(script, " //css_inc test.cs"); var caret = 5; var completions = SyntaxProvider.GetCompletion(script, caret); Output.WriteLine("OK"); caret = 12; completions = SyntaxProvider.GetCompletion(script, caret); File.WriteAllText(script, " //css_inc cmd.cs"); caret = 12; completions = SyntaxProvider.GetCompletion(script, caret); caret = 15; completions = SyntaxProvider.GetCompletion(script, caret); // Console.WriteLine(" '" + completions.Split('\n').FirstOrDefault(x => x.StartsWith(word)) + "'"); }, local: true); }
public static void DryRun() { var code = @"//css_inc global-usings //using System.IO; using System; using System.Diagnostics; //global using global::System.IO; File. print(""sdsaasdsad"".);"; TestScript(script => { Console.Write("CS-Script DryRun: "); File.WriteAllText(script, code); var pattern = "File."; var caret = code.IndexOf(pattern) + pattern.Length; var completions = SyntaxProvider.GetCompletion(script, caret); Output.WriteLine("OK"); // Console.WriteLine(" '" + completions.Split('\n').FirstOrDefault(x => x.StartsWith(word)) + "'"); }, local: true); }
static void Run(Args input) { if (input.cscs_path != null) { // Console.WriteLine($"Input {input.cscs_path} ..."); // Console.WriteLine($"Probing 0 {csscript.cscs_path} ..."); csscript.cscs_path = Path.GetFullPath(input.cscs_path); } Console.WriteLine($"Probing {csscript.cscs_path} ..."); if (csscript.cscs_path == null || !File.Exists(csscript.cscs_path)) { Console.WriteLine("Probing cscs.exe ..."); if (File.Exists(csscript.default_cscs_path)) { csscript.cscs_path = csscript.default_cscs_path; } else if (File.Exists(csscript.default_cscs_path2)) { csscript.cscs_path = csscript.default_cscs_path2; } else if (File.Exists(csscript.default_cscs_path3)) { csscript.cscs_path = csscript.default_cscs_path3; } else { Console.WriteLine("Probing cscs.exe failed..."); } } else { Console.WriteLine("cscs.exe: " + csscript.cscs_path); } if (input.test) { if (csscript.cscs_path == null) { csscript.cscs_path = csscript.default_cscs_path; } Test.All(); } else { if (input.listen) { SocketServer.Listen(input); } else { Output.WriteLine(SyntaxProvider.ProcessRequest(input)); } } }
public static void CodeMapVSCode() { var script = Path.GetTempFileName(); Output.WriteLine("---"); Output.Write("CodeMap-VSCode: "); try { var code = @"//css_autoclass using System; void main() { void ttt() { } } //css_ac_end static class Extensions { static public void Convert(this string text) { } }"; File.WriteAllText(script, code); var map = SyntaxProvider.CodeMap(script, false, true); Output.WriteLine("OK"); } catch (Exception e) { Output.WriteLine("failed"); Output.WriteLine(e); } finally { try { File.Delete(script); } catch { } } }
// "codemap" - request public static string GetCodeMap(string script) => SyntaxProvider.CodeMap(script, false, false);
// "format" - request public static string FormatCode(string script, ref int caretPos) => SyntaxProvider.FormatCode(script, ref caretPos);
// public static IEnumerable<ICompletionData> GetCompletion(string script, int offset) => SyntaxProvider.GetCompletionRaw(script, offset); // "tooltip" - request public static string GetTooltip(string script, int offset, string hint, bool shortHintedTooltips) => SyntaxProvider.GetTooltip(script, offset, hint, shortHintedTooltips);
// "signaturehelp" - request public static string GetSignatureHelp(string script, int offset) => SyntaxProvider.GetSignatureHelp(script, offset);
// public static DomRegion Resolve(string script, int offset) => SyntaxProvider.ResolveRaw(script, offset); // "completion" - request public static string GetCompletion(string script, int offset) => SyntaxProvider.GetCompletion(script, offset);
// "resolve" - request public static string Resolve(string script, int offset) => SyntaxProvider.Resolve(script, offset, false);
// "suggest_usings" - request public static string FindUsings(string script, string word) => SyntaxProvider.FindUsings(script, word, false);
// "references" - request public static string FindRefreneces(string script, int offset, string context = null) => SyntaxProvider.FindRefreneces(script, offset, context);
public static void Listen(Args processArgs) { try { var serverSocket = new TcpListener(IPAddress.Loopback, processArgs.port); serverSocket.Start(); if (processArgs.client != 0) { connections[processArgs.client] = true; Output.WriteLine("Monitor client: " + processArgs.client); } Task.Run(() => MonitorConnections(processArgs.timeout, requestShutdown: serverSocket.Stop)); Output.WriteLine($" >> Server (v{Assembly.GetExecutingAssembly().GetName().Version}) Started (port={processArgs.port})"); new Engine().Preload(); Output.WriteLine($" >> Syntax engine loaded"); while (true) { Output.WriteLine(" >> Waiting for client request..."); TcpClient clientSocket = serverSocket.AcceptTcpClient(); Output.WriteLine(" >> Accepted client..."); lock (connections) { try { Output.WriteLine(" >> Reading request..."); string request = clientSocket.ReadAllText(); var args = new Args(request.GetLines()); if (args.exit) { clientSocket.WriteAllText("Bye"); break; } else { if (args.client != 0) { connections[args.client] = true; // Output.WriteLine("Monitor client: " + args.client); } } Output.WriteLine(" >> Processing client request"); string response = SyntaxProvider.ProcessRequest(args); if (response != null) { clientSocket.WriteAllText(response); } } catch (Exception e) { Output.WriteLine(e.Message); } } } serverSocket.Stop(); Output.WriteLine(" >> exit"); } catch (SocketException e) { if (e.ErrorCode == 10048) { Output.WriteLine(">" + e.Message); } else { Output.WriteLine(e.Message); } } catch (Exception e) { Output.WriteLine(e); } }