public MetadataHelper(IOmnisharpAssemblyLoader loader) { _loader = loader; _featureAssembly = _loader.LazyLoad("Microsoft.CodeAnalysis.Features, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); _csharpFeatureAssembly = _loader.LazyLoad("Microsoft.CodeAnalysis.CSharp.Features, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); _workspaceAssembly = _loader.LazyLoad("Microsoft.CodeAnalysis.Workspaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); _csharpMetadataAsSourceServices = new Lazy <Type>(() => { return(_csharpFeatureAssembly.Value.GetType("Microsoft.CodeAnalysis.CSharp.MetadataAsSource.CSharpMetadataAsSourceService")); }); _symbolKey = new Lazy <Type>(() => { return(_workspaceAssembly.Value.GetType("Microsoft.CodeAnalysis.SymbolKey")); }); _metadataAsSourceHelper = new Lazy <Type>(() => { var type = _featureAssembly.Value.GetType("Microsoft.CodeAnalysis.MetadataAsSource.MetadataAsSourceHelpers"); if (type == null) { throw new IndexOutOfRangeException($"Could not find type Microsoft.CodeAnalysis.MetadataAsSource.MetadataAsSourceHelpers"); } return(type); }); _getLocationInGeneratedSourceAsync = new Lazy <MethodInfo>(() => { return(_metadataAsSourceHelper.Value.GetMethod("GetLocationInGeneratedSourceAsync")); }); }
public FixUsingsFacts() { _loggerFactory = new LoggerFactory(); _loggerFactory.AddConsole(); _logger = _loggerFactory.CreateLogger <FixUsingsFacts>(); _loader = new TestOmnisharpAssemblyLoader(_logger); }
public FixUsingsFacts() { _loggerFactory = new LoggerFactory(); _loggerFactory.AddConsole(); _logger = _loggerFactory.CreateLogger<FixUsingsFacts>(); _loader = new TestOmnisharpAssemblyLoader(_logger); }
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 IEnumerable <Assembly> Load(this IOmnisharpAssemblyLoader self, params string[] names) { foreach (var name in names) { yield return(Load(self, name)); } }
public MetadataHelper(IOmnisharpAssemblyLoader loader) { _loader = loader; _featureAssembly = _loader.LazyLoad("Microsoft.CodeAnalysis.Features, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); _csharpFeatureAssembly = _loader.LazyLoad("Microsoft.CodeAnalysis.CSharp.Features, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); _workspaceAssembly = _loader.LazyLoad("Microsoft.CodeAnalysis.Workspaces, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); _csharpMetadataAsSourceServices = new Lazy<Type>(() => { return _csharpFeatureAssembly.Value.GetType("Microsoft.CodeAnalysis.CSharp.MetadataAsSource.CSharpMetadataAsSourceService"); }); _symbolKey = new Lazy<Type>(() => { return _workspaceAssembly.Value.GetType("Microsoft.CodeAnalysis.SymbolKey"); }); _metadataAsSourceHelper = new Lazy<Type>(() => { var type = _featureAssembly.Value.GetType("Microsoft.CodeAnalysis.MetadataAsSource.MetadataAsSourceHelpers"); if (type == null) { throw new IndexOutOfRangeException($"Could not find type Microsoft.CodeAnalysis.MetadataAsSource.MetadataAsSourceHelpers"); } return type; }); _getLocationInGeneratedSourceAsync = new Lazy<MethodInfo>(() => { return _metadataAsSourceHelper.Value.GetMethod("GetLocationInGeneratedSourceAsync"); }); }
public FixUsingsFacts() { _loggerFactory = new LoggerFactory(); _loggerFactory.AddConsole(); _logger = _loggerFactory.CreateLogger <FixUsingsFacts>(); _loader = new AnnotateAssemblyLoader(_logger); }
public CodingActionsV2Facts() { _loggerFactory = new LoggerFactory(); _loggerFactory.AddConsole(); _logger = _loggerFactory.CreateLogger <CodingActionsV2Facts>(); _loader = new TestOmnisharpAssemblyLoader(_logger); }
public GoToDefinitionFacts() { _loggerFactory = new LoggerFactory(); _loggerFactory.AddConsole(); _logger = _loggerFactory.CreateLogger <GoToDefinitionFacts>(); _loader = new AnnotateAssemblyLoader(_logger); }
public MetadataFacts() { _loggerFactory = new LoggerFactory(); _loggerFactory.AddConsole(); _logger = _loggerFactory.CreateLogger<GoToDefinitionFacts>(); _loader = new TestOmnisharpAssemblyLoader(_logger); }
public CodingActionsV2Facts() { _loggerFactory = new LoggerFactory(); _loggerFactory.AddConsole(); _logger = _loggerFactory.CreateLogger<CodingActionsV2Facts>(); _loader = new TestOmnisharpAssemblyLoader(_logger); }
public MetadataFacts() { _loggerFactory = new LoggerFactory(); _loggerFactory.AddConsole(); _logger = _loggerFactory.CreateLogger <GoToDefinitionFacts>(); _loader = new TestOmnisharpAssemblyLoader(_logger); }
public FixUsingService(OmnisharpWorkspace workspace, ILoggerFactory loggerFactory, IOmnisharpAssemblyLoader loader, [ImportMany] IEnumerable <ICodeActionProvider> codeActionProviders) { _workspace = workspace; _loggerFactory = loggerFactory; _loader = loader; _codeActionProviders = codeActionProviders; }
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(); }
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."); }
public NRefactoryCodeActionProvider(IOmnisharpAssemblyLoader loader) : base("NRefactory", loader) { }
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 RoslynCodeActionProvider(IOmnisharpAssemblyLoader loader) : base("Roslyn", loader, "Microsoft.CodeAnalysis.CSharp.Features, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35", "Microsoft.CodeAnalysis.Features, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35") { }
public static Lazy <Assembly> LazyLoad(this IOmnisharpAssemblyLoader self, string name) { return(new Lazy <Assembly>(() => self.Load(name))); }
public FixUsingsWorker(ILoggerFactory loggerFactory, IOmnisharpAssemblyLoader loader) { _loggerFactory = loggerFactory; _loader = loader; }