예제 #1
0
        public DefaultGeneratedCodeContainerStoreTest()
        {
            var documentVersionCache = Mock.Of <DocumentVersionCache>();
            var csharpPublisher      = Mock.Of <CSharpPublisher>();

            Store          = new DefaultGeneratedCodeContainerStore(Dispatcher, documentVersionCache, csharpPublisher);
            ProjectManager = TestProjectSnapshotManager.Create(Dispatcher);
            Store.Initialize(ProjectManager);
        }
        public DefaultHostDocumentFactoryTest()
        {
            var store = new DefaultGeneratedCodeContainerStore(
                Dispatcher,
                Mock.Of <DocumentVersionCache>(),
                new Lazy <ILanguageServer>(() => null));

            Factory = new DefaultHostDocumentFactory(Dispatcher, store);
        }
예제 #3
0
        public DefaultGeneratedCodeContainerStoreTest()
        {
            var documentVersionCache = Mock.Of <DocumentVersionCache>();
            var server = new Lazy <ILanguageServer>(() => null);

            Store          = new DefaultGeneratedCodeContainerStore(Dispatcher, documentVersionCache, server);
            ProjectManager = TestProjectSnapshotManager.Create(Dispatcher);
            Store.Initialize(ProjectManager);
        }
        public DefaultHostDocumentFactoryTest()
        {
            var store = new DefaultGeneratedCodeContainerStore(
                Dispatcher,
                Mock.Of <DocumentVersionCache>(),
                Mock.Of <CSharpPublisher>());

            Factory = new DefaultHostDocumentFactory(Dispatcher, store);
        }
예제 #5
0
        public static async Task MainAsync(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()}.");
                    }
                }
            }

            Serializer.Instance.JsonSerializer.Converters.RegisterRazorConverters();

            var             factory = new LoggerFactory();
            ILanguageServer server  = null;

            server = await OmniSharp.Extensions.LanguageServer.Server.LanguageServer.From(options =>
                                                                                          options
                                                                                          .WithInput(Console.OpenStandardInput())
                                                                                          .WithOutput(Console.OpenStandardOutput())
                                                                                          .WithLoggerFactory(factory)
                                                                                          .AddDefaultLoggingProvider()
                                                                                          .WithMinimumLogLevel(logLevel)
                                                                                          .WithHandler <RazorDocumentSynchronizationEndpoint>()
                                                                                          .WithHandler <RazorCompletionEndpoint>()
                                                                                          .WithHandler <RazorHoverEndpoint>()
                                                                                          .WithHandler <RazorLanguageEndpoint>()
                                                                                          .WithHandler <RazorProjectEndpoint>()
                                                                                          .WithServices(services =>
            {
                services.AddSingleton <RemoteTextLoaderFactory, DefaultRemoteTextLoaderFactory>();
                services.AddSingleton <ProjectResolver, DefaultProjectResolver>();
                services.AddSingleton <DocumentResolver, DefaultDocumentResolver>();
                services.AddSingleton <FilePathNormalizer>();
                services.AddSingleton <RazorProjectService, DefaultRazorProjectService>();
                services.AddSingleton <ProjectSnapshotChangeTrigger, BackgroundDocumentGenerator>();

                // Document processed listeners
                services.AddSingleton <DocumentProcessedListener, RazorDiagnosticsPublisher>();
                services.AddSingleton <DocumentProcessedListener, UnsynchronizableContentDocumentProcessedListener>();

                services.AddSingleton <HostDocumentFactory, DefaultHostDocumentFactory>();
                services.AddSingleton <ProjectSnapshotManagerAccessor, DefaultProjectSnapshotManagerAccessor>();
                services.AddSingleton <TagHelperFactsService, DefaultTagHelperFactsService>();
                services.AddSingleton <VisualStudio.Editor.Razor.TagHelperCompletionService, VisualStudio.Editor.Razor.DefaultTagHelperCompletionService>();
                services.AddSingleton <TagHelperDescriptionFactory, DefaultTagHelperDescriptionFactory>();

                // Completion
                services.AddSingleton <Completion.TagHelperCompletionService, Completion.DefaultTagHelperCompletionService>();
                services.AddSingleton <RazorCompletionItemProvider, DirectiveCompletionItemProvider>();
                services.AddSingleton <RazorCompletionItemProvider, DirectiveAttributeCompletionItemProvider>();
                services.AddSingleton <RazorCompletionItemProvider, DirectiveAttributeParameterCompletionItemProvider>();
                services.AddSingleton <RazorCompletionItemProvider, DirectiveAttributeTransitionCompletionItemProvider>();

                var foregroundDispatcher = new VSCodeForegroundDispatcher();
                services.AddSingleton <ForegroundDispatcher>(foregroundDispatcher);

                var csharpPublisher = new DefaultCSharpPublisher(foregroundDispatcher, new Lazy <OmniSharp.Extensions.LanguageServer.Protocol.Server.ILanguageServer>(() => server));
                services.AddSingleton <ProjectSnapshotChangeTrigger>(csharpPublisher);
                services.AddSingleton <CSharpPublisher>(csharpPublisher);

                services.AddSingleton <RazorCompletionFactsService, DefaultRazorCompletionFactsService>();
                services.AddSingleton <RazorHoverInfoService, DefaultRazorHoverInfoService>();
                services.AddSingleton <HtmlFactsService, DefaultHtmlFactsService>();
                var documentVersionCache = new DefaultDocumentVersionCache(foregroundDispatcher);
                services.AddSingleton <DocumentVersionCache>(documentVersionCache);
                services.AddSingleton <ProjectSnapshotChangeTrigger>(documentVersionCache);
                var containerStore = new DefaultGeneratedCodeContainerStore(
                    foregroundDispatcher,
                    documentVersionCache,
                    csharpPublisher);
                services.AddSingleton <GeneratedCodeContainerStore>(containerStore);
                services.AddSingleton <ProjectSnapshotChangeTrigger>(containerStore);
            }));

            // Workaround for https://github.com/OmniSharp/csharp-language-server-protocol/issues/106
            var languageServer = (OmniSharp.Extensions.LanguageServer.Server.LanguageServer)server;

            languageServer.MinimumLogLevel = logLevel;

            try
            {
                var logger = factory.CreateLogger <Program>();
                var assemblyInformationAttribute = typeof(Program).Assembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>();
                logger.LogInformation("Razor Language Server version " + assemblyInformationAttribute.InformationalVersion);
            }
            catch
            {
                // Swallow exceptions from determining assembly information.
            }

            await server.WaitForExit;

            TempDirectory.Instance.Dispose();
        }