示例#1
0
        public RoslynHost(NuGetConfiguration nuGetConfiguration       = null,
                          IEnumerable <Assembly> additionalAssemblies = null,
                          RoslynHostReferences references             = null)
        {
            _nuGetConfiguration = nuGetConfiguration;
            if (references == null)
            {
                references = RoslynHostReferences.Default;
            }

            _workspaces = new ConcurrentDictionary <DocumentId, RoslynWorkspace>();
            _diagnosticsUpdatedNotifiers = new ConcurrentDictionary <DocumentId, Action <DiagnosticsUpdatedArgs> >();

            IEnumerable <Assembly> assemblies = new[]
            {
                Assembly.Load(new AssemblyName("Microsoft.CodeAnalysis")),
                Assembly.Load(new AssemblyName("Microsoft.CodeAnalysis.CSharp")),
                Assembly.Load(new AssemblyName("Microsoft.CodeAnalysis.Features")),
                Assembly.Load(new AssemblyName("Microsoft.CodeAnalysis.CSharp.Features")),
                typeof(RoslynHost).GetTypeInfo().Assembly,
            };

            if (additionalAssemblies != null)
            {
                assemblies = assemblies.Concat(additionalAssemblies);
            }

            var partTypes = MefHostServices.DefaultAssemblies.Concat(assemblies)
                            .Distinct()
                            .SelectMany(x => x.DefinedTypes)
                            .Select(x => x.AsType())
                            .ToArray();

            _compositionContext = new ContainerConfiguration()
                                  .WithParts(partTypes)
                                  .CreateContainer();

            _host = MefHostServices.Create(_compositionContext);

            _parseOptions = new CSharpParseOptions(kind: SourceCodeKind.Script,
                                                   preprocessorSymbols: PreprocessorSymbols, languageVersion: LanguageVersion.Latest);

            _documentationProviderService = GetService <IDocumentationProviderService>();

            DefaultReferences = references.GetReferences(_documentationProviderService.GetDocumentationProvider);
            DefaultImports    = references.Imports;

            GetService <IDiagnosticService>().DiagnosticsUpdated += OnDiagnosticsUpdated;

            GetService <ISyntaxChangeNotificationService>().OpenedDocumentSyntaxChanged += OnSyntaxChanged;
        }
示例#2
0
        public RoslynHost(IEnumerable <Assembly> additionalAssemblies = null,
                          RoslynHostReferences references             = null,
                          ImmutableArray <string>?disabledDiagnostics = null)
        {
            if (references == null)
            {
                references = RoslynHostReferences.Empty;
            }

            _workspaces = new ConcurrentDictionary <DocumentId, RoslynWorkspace>();
            _diagnosticsUpdatedNotifiers = new ConcurrentDictionary <DocumentId, Action <DiagnosticsUpdatedArgs> >();

            // ReSharper disable once VirtualMemberCallInConstructor
            var assemblies = GetDefaultCompositionAssemblies();

            if (additionalAssemblies != null)
            {
                assemblies = assemblies.Concat(additionalAssemblies);
            }

            var partTypes = assemblies
                            .SelectMany(x => x.DefinedTypes)
                            .Select(x => x.AsType());

            _compositionContext = new ContainerConfiguration()
                                  .WithParts(partTypes)
                                  .CreateContainer();

            HostServices = MefHostServices.Create(_compositionContext);

            // ReSharper disable once VirtualMemberCallInConstructor
            _parseOptions = CreateDefaultParseOptions();

            _documentationProviderService = GetService <IDocumentationProviderService>();

            DefaultReferences = references.GetReferences(DocumentationProviderFactory);
            DefaultImports    = references.Imports;

            DisabledDiagnostics = disabledDiagnostics ?? ImmutableArray <string> .Empty;
            GetService <IDiagnosticService>().DiagnosticsUpdated += OnDiagnosticsUpdated;
        }