Beispiel #1
0
        public static async Task Main(string[] args)
        {
            var logLevel = LogLevel.Information;

            for (var i = 0; i < args.Length; i++)
            {
                if (args[i].IndexOf("debug", StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    while (!Debugger.IsAttached)
                    {
                        Thread.Sleep(1000);
                    }

                    Debugger.Break();
                    continue;
                }

                if (args[i] == "--logLevel" && i + 1 < args.Length)
                {
                    var logLevelString = args[++i];
                    if (!Enum.TryParse(logLevelString, out logLevel))
                    {
                        logLevel = LogLevel.Information;
                        Console.WriteLine($"Invalid log level '{logLevelString}'. Defaulting to {logLevel.ToString()}.");
                    }
                }
            }

            var threadManager   = new ForegroundThreadManager();
            var snapshotManager = new WorkspaceSnapshotManager(threadManager);
            var server          = await LanguageServer.From(options =>
                                                            options
                                                            .WithInput(Console.OpenStandardInput())
                                                            .WithOutput(Console.OpenStandardOutput())
                                                            .WithLoggerFactory(new LoggerFactory())
                                                            .AddDefaultLoggingProvider()
                                                            .WithMinimumLogLevel(LogLevel.Trace)

                                                            // We're adding a new endpoint that will handle a specific set of language server features.
                                                            .WithHandler <TextDocumentSynchronizationEndpoint>()
                                                            .WithHandler <ProtoCompletionEndpoint>()
                                                            .WithHandler <ProtoDefinitionEndpoint>()
                                                            .WithServices(services =>
            {
                services.AddSingleton <ForegroundThreadManager>(threadManager);
                services.AddSingleton <WorkspaceSnapshotManager>(snapshotManager);
            }));

            await Task.Factory.StartNew(
                () => snapshotManager.InitializeAsync(server),
                CancellationToken.None,
                TaskCreationOptions.None,
                threadManager.ForegroundScheduler);

            var languageServer = (LanguageServer)server;

            languageServer.MinimumLogLevel = logLevel;

            await server.WaitForExit;
        }
 public TextDocumentSynchronizationEndpoint(
     ILanguageServer router,
     WorkspaceSnapshotManager snapshotManager,
     ForegroundThreadManager threadManager)
 {
     _router          = router ?? throw new ArgumentNullException(nameof(router));
     _snapshotManager = snapshotManager;
     _threadManager   = threadManager;
 }
Beispiel #3
0
 public RenameEndpoint(
     ForegroundThreadManager threadManager,
     ILanguageServer router,
     WorkspaceSnapshotManager snapshotManager)
 {
     _threadManager   = threadManager;
     _router          = router ?? throw new ArgumentNullException(nameof(router));
     _snapshotManager = snapshotManager;
 }
Beispiel #4
0
 public ProtoCompletionEndpoint(
     ForegroundThreadManager threadManager,
     IEnumerable <ProtoCompletionItemProvider> completionItemProviders,
     ILanguageServer router,
     WorkspaceSnapshotManager snapshotManager)
 {
     _threadManager           = threadManager;
     _completionItemProviders = completionItemProviders;
     _router          = router ?? throw new ArgumentNullException(nameof(router));
     _snapshotManager = snapshotManager;
 }