private IEnumerable <Type> GetApplicableTypes()
        {
            var models = typeof(Request).Assembly.DefinedTypes
                         .Where(z => z.IsPublic && z.FullName.StartsWith(OmnisharpControllerExtractor.InferNamespace(typeof(Request)), StringComparison.Ordinal));
            var stdioProtocol = typeof(Packet).Assembly.DefinedTypes
                                .Where(z => z.IsPublic && z.FullName.StartsWith(OmnisharpControllerExtractor.InferNamespace(typeof(Packet)), StringComparison.Ordinal));

            return(models.Union(stdioProtocol).ToArray());
        }
        public static IEnumerable <KeyValuePair <string, Tuple <string, string> > > GetAugmentationMethods()
        {
            var methods = OmnisharpControllerExtractor.GetMethods().Where(x => !x.StringBased)
                          .Where(x => x.RequestType != null)
                          .GroupBy(x => x.ActionName)
                          .SelectMany(x => { var max = x.Max(z => z.VersionNumber); return(x.Where(z => max == z.VersionNumber)); })
                          .ToArray();
            var events = OmnisharpControllerExtractor.GetEvents().Where(x => !x.StringBased)
                         .Where(x => x.RequestType != null)
                         .GroupBy(x => x.ActionName)
                         .SelectMany(x => { var max = x.Max(z => z.VersionNumber); return(x.Where(z => max == z.VersionNumber)); })
                         .Join(
                OmnisharpControllerExtractor.GetAggregateEvents().Where(x => !x.StringBased)
                .Where(x => x.RequestType != null)
                .GroupBy(x => x.ActionName)
                .SelectMany(x => { var max = x.Max(z => z.VersionNumber); return(x.Where(z => max == z.VersionNumber)); }),
                x => x.ActionName,
                x => x.ActionName,
                (@event, aggregateEvent) => new { @event, aggregateEvent });

            var serverEvents = OmnisharpEventExtractor.GetEvents().GroupBy(x => x.Name).Select(x => x.First(z => !z.Value.Contains("listen")))
                               .Join(OmnisharpEventExtractor.GetAggregateEvents().GroupBy(x => x.Name).Select(x => x.First(z => !z.Value.Contains("listen"))), x => x.Name, x => x.Name, (@event, aggregateEvent) => new { @event, aggregateEvent });

            var v = $@"{string.Join("\n", methods.Select(x => $"request(ReactiveClient.prototype, \"{x.ActionName}\");"))}
{string.Join("\n", events.Select(x => $"response(ReactiveClientEvents.prototype, \"{[email protected]}\", \"/{[email protected]}\");"))}
{string.Join("\n", serverEvents.Select(x => $"event(ReactiveClientEvents.prototype, \"{[email protected]}\");"))}
";

            yield return(new KeyValuePair <string, Tuple <string, string> >("reactive", Tuple.Create("reactive-client.ts", v)));

            v = $@"{string.Join("\n", events.Select(x => $"makeObservable(ReactiveObservationClient.prototype, \"{[email protected]}\", \"/{[email protected]}\");"))}
{string.Join("\n", serverEvents.Select(x => $"makeObservable(ReactiveObservationClient.prototype, \"{[email protected]}\", \"{[email protected]}\");"))}
";

            yield return(new KeyValuePair <string, Tuple <string, string> >("reactive", Tuple.Create("reactive-observation-client.ts", v)));

            v = $@"{string.Join("\n", events.Select(x => $"makeObservable(ReactiveCombinationClient.prototype, \"{[email protected]}\", \"/{[email protected]}\");"))}
{string.Join("\n", serverEvents.Select(x => $"makeObservable(ReactiveCombinationClient.prototype, \"{[email protected]}\", \"{[email protected]}\");"))}
";

            yield return(new KeyValuePair <string, Tuple <string, string> >("reactive", Tuple.Create("reactive-combination-client.ts", v)));

            v = $@"{string.Join("\n", methods.Select(x => $"request(AsyncClient.prototype, \"{x.ActionName}\");"))}
";

            yield return(new KeyValuePair <string, Tuple <string, string> >("async", Tuple.Create("async-client.ts", v)));
        }
        public void Main(string[] args)
        {
            var path = string.Empty;

            if (args.Length == 1)
            {
                path = args[0];
            }

            var fluent = TypeScript.Definitions();

            fluent.ScriptGenerator.IndentationString = "    ";

            fluent.WithMemberTypeFormatter(TsFluentFormatters.FormatPropertyType);
            fluent.WithMemberFormatter(TsFluentFormatters.FormatPropertyName);

            foreach (var model in GetApplicableTypes())
            {
                fluent.For(model);
            }

            var tsModel = fluent.ModelBuilder.Build();

            foreach (var @class in tsModel.Classes.Where(z => z.Module.Name.StartsWith("System", StringComparison.Ordinal)))
            {
                @class.IsIgnored = true;
            }

            var result = fluent.Generate();

            result = string.Join("\n", result, OmnisharpControllerExtractor.GetInterface());
            if (!string.IsNullOrWhiteSpace(path))
            {
                File.WriteAllText(Path.Combine(path, "omnisharp-server.d.ts"), result);
            }
            else
            {
                Console.Write(result);
                Console.ReadLine();
            }
        }
Exemple #4
0
        private static IEnumerable <Type> GetApplicableTypes()
        {
            var allTypes = new[] {
                typeof(OmniSharp.Startup).Assembly,
                typeof(OmniSharp.Models.Request).Assembly,
                typeof(OmniSharp.DotNet.Models.DotNetFramework).Assembly,
                //typeof(OmniSharp.Models.MSBuildProject).Assembly,
                typeof(OmniSharp.NuGet.OmniSharpSourceRepositoryProvider).Assembly,
                typeof(OmniSharp.Roslyn.BufferManager).Assembly,
                typeof(OmniSharp.Roslyn.CSharp.Services.CodeActions.RoslynCodeActionProvider).Assembly,
                typeof(OmniSharp.ScriptCs.ScriptCsContextModel).Assembly,
                typeof(OmniSharp.Stdio.StdioServer).Assembly,
            }
            .SelectMany(x => x.GetTypes())
            .ToArray();

            var models = allTypes
                         .Where(z => z.IsPublic && z.FullName.Contains("Models."))
                         .Select(x =>
            {
                Console.WriteLine(x.FullName);
                return(x);
            })
                         .Where(x => x.Name != nameof(ProjectInformationResponse))
                         .Where(x => x.Name != nameof(WorkspaceInformationResponse));

            var stdioProtocol = allTypes
                                .Where(z => z.IsPublic && z.FullName.StartsWith(OmnisharpControllerExtractor.InferNamespace(typeof(Packet)), StringComparison.Ordinal))
                                .Select(x =>
            {
                Console.WriteLine(x.FullName);
                return(x);
            });

            var scriptCs = typeof(OmniSharp.ScriptCs.ScriptCsContextModel);

            return(models.Union(stdioProtocol).Union(new[] { typeof(OmniSharp.ScriptCs.ScriptCsContextModel) }).ToArray());
        }
Exemple #5
0
        public static void Main(string[] args)
        {
            var path = string.Empty;

            if (args.Length == 1)
            {
                path = args[0];
            }

            var fluent = TypeScript.Definitions();

            fluent.ScriptGenerator.IndentationString = "    ";

            fluent.WithMemberTypeFormatter(TsFluentFormatters.FormatPropertyType);
            fluent.WithMemberFormatter(TsFluentFormatters.FormatPropertyName);

            foreach (var model in GetApplicableTypes())
            {
                fluent.For(model);
            }

            var tsModel = fluent.ModelBuilder.Build();

            foreach (var @class in tsModel.Classes.Where(z => z.Module.Name.StartsWith("System", StringComparison.Ordinal)))
            {
                @class.IsIgnored = true;
            }

            var result = fluent.Generate();

            var generated         = string.Join("\n", OmnisharpControllerExtractor.GetInterface());
            var projectInterfaces = $@"
declare module {OmnisharpControllerExtractor.InferNamespace(typeof(Request)).TrimEnd('.')} {{
    interface ProjectInformationResponse {{
        MsBuildProject: OmniSharp.Models.MSBuildProject;
        DotNetProject: OmniSharp.Models.DotNetProjectInformation;
    }}

    interface WorkspaceInformationResponse {{
        DotNet: OmniSharp.Models.DotNetWorkspaceInformation;
        MSBuild: OmniSharp.Models.MsBuildWorkspaceInformation;
        ScriptCs: OmniSharp.ScriptCs.ScriptCsContextModel;
    }}
}}
            ";

            result = string.Join("\n", "import {Observable} from \"rxjs\";", result, generated, OmnisharpEventExtractor.GetInterface(), projectInterfaces);
            result = result
                     .Replace("interface", "export interface")
                     .Replace("declare module", "export module")
                     .Replace("export module OmniSharp {", "")
                     .Replace("OmniSharp.", "")
                     .Replace("DotNet.Models", "Models")
            ;

            var lines = result.Split('\n');
            var opens = 0;

            for (var i = 0; i < lines.Length; i++)
            {
                if (lines[i].Contains('{'))
                {
                    opens++;
                }
                if (lines[i].Contains('}'))
                {
                    opens--;
                }
                if (opens < 0 && lines[i].TrimEnd().Length == 1)
                {
                    lines[i] = string.Empty;
                    opens    = 0;
                }
            }

            result = string.Join("\n", lines);

            result = "/* tslint:disable */\n" + result + "\n";

            if (!string.IsNullOrWhiteSpace(path))
            {
                File.WriteAllText(Path.Combine(path, "lib", "omnisharp-server.ts"), result);
                foreach (var item in OmnisharpAugmentationExtractor.GetAugmentationMethods())
                {
                    var p        = Path.Combine(path, "lib", item.Key, item.Value.Item1);
                    var contents = File.ReadAllText(p);
                    contents  = contents.Substring(0, contents.IndexOf("// <#GENERATED />"));
                    contents += "// <#GENERATED />\n" + item.Value.Item2;
                    File.WriteAllText(p, contents);
                }
            }
            else
            {
                Console.Write(result);
                Console.ReadLine();
            }
        }