Example #1
0
        protected AbstractCodeActionProvider(string providerName,
                                             IOmnisharpAssemblyLoader loader,
                                             params string[] assembliesNames)
        {
            if (loader == null)
            {
                throw new ArgumentNullException(nameof(loader));
            }

            ProviderName = providerName;

            Assemblies = assembliesNames.Select(name => loader.Load(name));

            var features = Assemblies.SelectMany(assembly => assembly.GetTypes()
                                                 .Where(type => !type.GetTypeInfo().IsInterface&&
                                                        !type.GetTypeInfo().IsAbstract&&
                                                        !type.GetTypeInfo().ContainsGenericParameters));

            // TODO: handle providers with generic params

            _refactorings = features.Where(t => typeof(CodeRefactoringProvider).IsAssignableFrom(t))
                            .Select(type => CreateInstance <CodeRefactoringProvider>(type))
                            .Where(instance => instance != null);

            _codeFixes = features.Where(t => typeof(CodeFixProvider).IsAssignableFrom(t))
                         .Select(type => CreateInstance <CodeFixProvider>(type))
                         .Where(instance => instance != null);
        }
        public static Assembly Load(this IOmnisharpAssemblyLoader self, string name)
        {
            var assemblyName = name;

            if (name.EndsWith(".dll", StringComparison.OrdinalIgnoreCase))
            {
                assemblyName = name.Substring(0, name.Length - 4);
            }

            return(self.Load(new AssemblyName(assemblyName)));
        }
        public RoslynFeaturesHostServicesProvider(IOmnisharpAssemblyLoader loader)
        {
            var builder = ImmutableArray.CreateBuilder <Assembly>();

            var Features       = Configuration.GetRoslynAssemblyFullName("Microsoft.CodeAnalysis.Features");
            var CSharpFeatures = Configuration.GetRoslynAssemblyFullName("Microsoft.CodeAnalysis.CSharp.Features");

            builder.AddRange(loader.Load(Features, CSharpFeatures));

            this.Assemblies = builder.ToImmutable();
        }
Example #4
0
        public void Configure(IApplicationBuilder app,
                              IServiceProvider serviceProvider,
                              IOmnisharpEnvironment env,
                              ILoggerFactory loggerFactory,
                              ISharedTextWriter writer,
                              IOmnisharpAssemblyLoader loader,
                              IOptions<OmniSharpOptions> optionsAccessor)
        {
            Func<RuntimeLibrary, bool> shouldLoad = lib => lib.Dependencies.Any(dep => dep.Name == "OmniSharp.Abstractions" ||
                                                                                       dep.Name == "OmniSharp.Roslyn");
                       
            var assemblies = DependencyContext.Default
                                              .RuntimeLibraries
                                              .Where(shouldLoad)
                                              .SelectMany(lib => lib.Assemblies)
                                              .Select(each => loader.Load(each.Name))
                                              .ToList();

            PluginHost = ConfigureMef(serviceProvider, optionsAccessor.Value, assemblies);

            Workspace = PluginHost.GetExport<OmnisharpWorkspace>();

            if (env.TransportType == TransportType.Stdio)
            {
                loggerFactory.AddStdio(writer, (category, level) => LogFilter(category, level, env));
            }
            else
            {
                loggerFactory.AddConsole((category, level) => LogFilter(category, level, env));
            }

            var logger = loggerFactory.CreateLogger<Startup>();
            foreach (var assembly in assemblies)
            {
                logger.LogDebug($"Loaded {assembly.FullName}");
            }

            app.UseRequestLogging();
            app.UseExceptionHandler("/error");
            app.UseMiddleware<EndpointMiddleware>();
            app.UseMiddleware<StatusMiddleware>();
            app.UseMiddleware<StopServerMiddleware>();

            if (env.TransportType == TransportType.Stdio)
            {
                logger.LogInformation($"Omnisharp server running using {nameof(TransportType.Stdio)} at location '{env.Path}' on host {env.HostPID}.");
            }
            else
            {
                logger.LogInformation($"Omnisharp server running on port '{env.Port}' at location '{env.Path}' on host {env.HostPID}.");
            }

            // ProjectEventForwarder register event to OmnisharpWorkspace during instantiation
            PluginHost.GetExport<ProjectEventForwarder>();
            
            // Initialize all the project systems
            foreach (var projectSystem in PluginHost.GetExports<IProjectSystem>())
            {
                try
                {
                    projectSystem.Initalize(Configuration.GetSection(projectSystem.Key));
                }
                catch (Exception e)
                {
                    var message = $"The project system '{projectSystem.GetType().Name}' threw exception during initialization.\n{e.Message}\n{e.StackTrace}";
                    // if a project system throws an unhandled exception it should not crash the entire server
                    logger.LogError(message);
                }
            }

            // Mark the workspace as initialized
            Workspace.Initialized = true;

            logger.LogInformation("Configuration finished.");
        }
Example #5
0
        public void Configure(IApplicationBuilder app,
                              IServiceProvider serviceProvider,
                              IOmnisharpEnvironment env,
                              ILoggerFactory loggerFactory,
                              ISharedTextWriter writer,
                              IOmnisharpAssemblyLoader loader,
                              IOptions <OmniSharpOptions> optionsAccessor)
        {
            Func <RuntimeLibrary, bool> shouldLoad = lib => lib.Dependencies.Any(dep => dep.Name == "OmniSharp.Abstractions" ||
                                                                                 dep.Name == "OmniSharp.Roslyn");

            var dependencyContext = DependencyContext.Default;
            var assemblies        = dependencyContext.RuntimeLibraries
                                    .Where(shouldLoad)
                                    .SelectMany(lib => lib.GetDefaultAssemblyNames(dependencyContext))
                                    .Select(each => loader.Load(each.Name))
                                    .ToList();

            PluginHost = ConfigureMef(serviceProvider, optionsAccessor.Value, assemblies);

            Workspace = PluginHost.GetExport <OmnisharpWorkspace>();

            if (env.TransportType == TransportType.Stdio)
            {
                loggerFactory.AddStdio(writer, (category, level) => LogFilter(category, level, env));
            }
            else
            {
                loggerFactory.AddConsole((category, level) => LogFilter(category, level, env));
            }

            var logger = loggerFactory.CreateLogger <Startup>();

            foreach (var assembly in assemblies)
            {
                logger.LogDebug($"Loaded {assembly.FullName}");
            }

            app.UseRequestLogging();
            app.UseExceptionHandler("/error");
            app.UseMiddleware <EndpointMiddleware>();
            app.UseMiddleware <StatusMiddleware>();
            app.UseMiddleware <StopServerMiddleware>();

            if (env.TransportType == TransportType.Stdio)
            {
                logger.LogInformation($"Omnisharp server running using {nameof(TransportType.Stdio)} at location '{env.Path}' on host {env.HostPID}.");
            }
            else
            {
                logger.LogInformation($"Omnisharp server running on port '{env.Port}' at location '{env.Path}' on host {env.HostPID}.");
            }

            // ProjectEventForwarder register event to OmnisharpWorkspace during instantiation
            PluginHost.GetExport <ProjectEventForwarder>();

            // Initialize all the project systems
            foreach (var projectSystem in PluginHost.GetExports <IProjectSystem>())
            {
                try
                {
                    projectSystem.Initalize(Configuration.GetSection(projectSystem.Key));
                }
                catch (Exception e)
                {
                    var message = $"The project system '{projectSystem.GetType().Name}' threw exception during initialization.\n{e.Message}\n{e.StackTrace}";
                    // if a project system throws an unhandled exception it should not crash the entire server
                    logger.LogError(message);
                }
            }

            // Mark the workspace as initialized
            Workspace.Initialized = true;

            logger.LogInformation("Configuration finished.");
        }
 public static Lazy <Assembly> LazyLoad(this IOmnisharpAssemblyLoader self, string name)
 {
     return(new Lazy <Assembly>(() => self.Load(name)));
 }