示例#1
0
        private static IExportProviderFactory CreateExportProviderFactory()
        {
            var catalog = TestExportProvider.GetCSharpAndVisualBasicAssemblyCatalog()
                          .WithParts(ExportProviderCache.GetOrCreateAssemblyCatalog(new[] { typeof(EditorServicesUtil).Assembly }, ExportProviderCache.CreateResolver()));

            return(ExportProviderCache.GetOrCreateExportProviderFactory(catalog));
        }
示例#2
0
 public static ComposableCatalog GetCSharpAndVisualBasicAssemblyCatalog()
 {
     return(ExportProviderCache.GetOrCreateAssemblyCatalog(
                GetNeutralAndCSharpAndVisualBasicTypes().Select(t => t.Assembly).Distinct(), ExportProviderCache.CreateResolver())
            .WithParts(MinimalTestExportProvider.GetEditorAssemblyCatalog())
            .WithDefaultFakes());
 }
 static VisualStudioTestExportProvider()
 {
     Factory = ExportProviderCache.GetOrCreateExportProviderFactory(
         TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic
         .WithParts(ExportProviderCache.GetOrCreateAssemblyCatalog(typeof(CSharpCodeModelService).Assembly))
         .WithPart(typeof(LanguageServices.UnitTests.VisualStudioTestExportProvider.MockWorkspaceEventListenerProvider)));
 }
示例#4
0
        private static IExportProviderFactory CreateExportProviderFactory()
        {
            var assemblies = TestExportProvider
                             .GetCSharpAndVisualBasicAssemblies()
                             .Concat(new[] { typeof(EditorServicesUtil).Assembly });

            return(ExportProviderCache.GetOrCreateExportProviderFactory(ExportProviderCache.GetOrCreateAssemblyCatalog(assemblies, ExportProviderCache.CreateResolver())));
        }
        public void OrderingOfEditorConfigMaintained()
        {
            using var tempRoot = new TempRoot();
            var tempDirectory = tempRoot.CreateDirectory();

            // Write out an .editorconfig. We'll write out 100 random GUIDs
            var expectedKeysInOrder = new List <string>();

            using (var writer = new StreamWriter(tempDirectory.CreateFile(".editorconfig").Path))
            {
                writer.WriteLine("root = true");
                writer.WriteLine("[*.cs]");

                for (int i = 0; i < 100; i++)
                {
                    var key = Guid.NewGuid().ToString();
                    expectedKeysInOrder.Add(key);
                    writer.WriteLine($"{key} = value");
                }
            }

            // Create a workspace with a file in that path
            var codingConventionsCatalog = ExportProviderCache.GetOrCreateAssemblyCatalog(typeof(ICodingConventionsManager).Assembly).WithPart(typeof(MockFileWatcher));
            var exportProvider           = ExportProviderCache.GetOrCreateExportProviderFactory(TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic.WithParts(codingConventionsCatalog)).CreateExportProvider();

            using var workspace = TestWorkspace.CreateWorkspace(
                      new XElement("Workspace",
                                   new XElement("Project", new XAttribute("Language", "C#"),
                                                new XElement("Document", new XAttribute("FilePath", tempDirectory.CreateFile("Test.cs").Path)))), exportProvider: exportProvider);

            var document = workspace.CurrentSolution.Projects.Single().Documents.Single();

            var providerFactory = workspace.ExportProvider.GetExportedValues <IDocumentOptionsProviderFactory>().OfType <LegacyEditorConfigDocumentOptionsProviderFactory>().Single();
            var provider        = providerFactory.TryCreate(workspace);

            var option    = new Option <List <string> >(nameof(LegacyEditorConfigDocumentOptionsProviderTests), nameof(OrderingOfEditorConfigMaintained), null, new[] { new KeysReturningStorageLocation() });
            var optionKey = new OptionKey(option);

            // Fetch the underlying option order with a "option" that returns the keys
            provider.GetOptionsForDocumentAsync(document, CancellationToken.None).Result.TryGetDocumentOption(optionKey, workspace.Options, out object actualKeysInOrderObject);

            var actualKeysInOrder = Assert.IsAssignableFrom <IEnumerable <string> >(actualKeysInOrderObject);

            Assert.Equal(expectedKeysInOrder, actualKeysInOrder);
        }
        public static ComposableCatalog GetEditorAssemblyCatalog()
        {
            var assemblies = new[]
            {
                // EDITOR

                // Microsoft.VisualStudio.Platform.VSEditor.dll:
                Assembly.LoadFrom("Microsoft.VisualStudio.Platform.VSEditor.dll"),

                // Microsoft.VisualStudio.Text.Logic.dll:
                //   Must include this because several editor options are actually stored as exported information
                //   on this DLL.  Including most importantly, the tab size information.
                typeof(Microsoft.VisualStudio.Text.Editor.DefaultOptions).Assembly,

                // Microsoft.VisualStudio.Text.UI.dll:
                //   Include this DLL to get several more EditorOptions including WordWrapStyle.
                typeof(Microsoft.VisualStudio.Text.Editor.WordWrapStyle).Assembly,

                // Microsoft.VisualStudio.Text.UI.Wpf.dll:
                //   Include this DLL to get more EditorOptions values.
                typeof(Microsoft.VisualStudio.Text.Editor.HighlightCurrentLineOption).Assembly,

                // BasicUndo.dll:
                //   Include this DLL to satisfy ITextUndoHistoryRegistry
                typeof(BasicUndo.IBasicUndoHistory).Assembly,

                // Microsoft.VisualStudio.Language.StandardClassification.dll:
                typeof(Microsoft.VisualStudio.Language.StandardClassification.PredefinedClassificationTypeNames).Assembly,

                // Microsoft.VisualStudio.Language
                typeof(Microsoft.VisualStudio.Language.Intellisense.AsyncCompletion.IAsyncCompletionBroker).Assembly,

                // Microsoft.VisualStudio.CoreUtility
                typeof(Microsoft.VisualStudio.Utilities.IFeatureServiceFactory).Assembly,

                // Microsoft.VisualStudio.Text.Internal
                typeof(Microsoft.VisualStudio.Text.Utilities.IExperimentationServiceInternal).Assembly,
            };

            // Consider removing the internal service from the output: https://github.com/dotnet/roslyn/issues/30249
            return(ExportProviderCache.GetOrCreateAssemblyCatalog(assemblies, ExportProviderCache.CreateResolver())
                   .WithPart(typeof(TestExperimentationServiceInternal)));
        }
 public static ComposableCatalog CreateAssemblyCatalog()
 {
     return(ExportProviderCache.GetOrCreateAssemblyCatalog(GetLanguageNeutralTypes().Select(t => t.Assembly).Distinct(), ExportProviderCache.CreateResolver())
            .WithParts(MinimalTestExportProvider.GetEditorAssemblyCatalog()));
 }
示例#8
0
 private static ComposableCatalog CreateAssemblyCatalogWithCSharpAndVisualBasic()
 {
     return(ExportProviderCache
            .GetOrCreateAssemblyCatalog(GetCSharpAndVisualBasicAssemblies(), ExportProviderCache.CreateResolver())
            .WithCompositionService());
 }
示例#9
0
 static VisualStudioTestExportProvider()
 {
     Factory = ExportProviderCache.GetOrCreateExportProviderFactory(
         TestExportProvider.EntireAssemblyCatalogWithCSharpAndVisualBasic.WithParts(
             ExportProviderCache.GetOrCreateAssemblyCatalog(typeof(CSharpCodeModelService).Assembly)));
 }