public VisualStudioWorkspaceImpl(ExportProvider exportProvider) : base( MefV1HostServices.Create(exportProvider), backgroundWork: WorkspaceBackgroundWork.ParseAndCompile) { PrimaryWorkspace.Register(this); }
public void TestPreviewDiagnostic() { var diagnosticService = EditorServicesUtil.ExportProvider.GetExportedValue <IDiagnosticAnalyzerService>() as IDiagnosticUpdateSource; var taskSource = new TaskCompletionSource <DiagnosticsUpdatedArgs>(); diagnosticService.DiagnosticsUpdated += (s, a) => taskSource.TrySetResult(a); using (var previewWorkspace = new PreviewWorkspace(MefV1HostServices.Create(EditorServicesUtil.ExportProvider.AsExportProvider()))) { var solution = previewWorkspace.CurrentSolution .AddProject("project", "project.dll", LanguageNames.CSharp) .AddDocument("document", "class { }") .Project .Solution; Assert.True(previewWorkspace.TryApplyChanges(solution)); previewWorkspace.OpenDocument(previewWorkspace.CurrentSolution.Projects.First().DocumentIds[0]); previewWorkspace.EnableDiagnostic(); // wait 20 seconds taskSource.Task.Wait(20000); Assert.True(taskSource.Task.IsCompleted); var args = taskSource.Task.Result; Assert.True(args.Diagnostics.Length > 0); } }
internal static AdhocWorkspace CreateWorkspace() { var exportProvider = ExportProviderFactory.Value.CreateExportProvider(); var host = MefV1HostServices.Create(exportProvider.AsExportProvider()); return(new AdhocWorkspace(host)); }
async Task InitializeInstanceAsync() { ComposableCatalog catalog = ComposableCatalog.Create(StandardResolver) .WithCompositionService() .WithDesktopSupport(); var assemblies = new HashSet <Assembly> (); ReadAssembliesFromAddins(assemblies, "/MonoDevelop/Ide/TypeService/PlatformMefHostServices"); ReadAssembliesFromAddins(assemblies, "/MonoDevelop/Ide/TypeService/MefHostServices"); ReadAssembliesFromAddins(assemblies, "/MonoDevelop/Ide/Composition"); // spawn discovery tasks in parallel for each assembly var tasks = new List <Task <DiscoveredParts> > (assemblies.Count); foreach (var assembly in assemblies) { var task = Task.Run(() => Discovery.CreatePartsAsync(assembly)); tasks.Add(task); } foreach (var task in tasks) { catalog = catalog.AddParts(await task); } var discoveryErrors = catalog.DiscoveredParts.DiscoveryErrors; if (!discoveryErrors.IsEmpty) { foreach (var error in discoveryErrors) { LoggingService.LogInfo("MEF discovery error", error); } // throw new ApplicationException ("MEF discovery errors"); } CompositionConfiguration configuration = CompositionConfiguration.Create(catalog); if (!configuration.CompositionErrors.IsEmpty) { // capture the errors in an array for easier debugging var errors = configuration.CompositionErrors.SelectMany(e => e).ToArray(); foreach (var error in errors) { LoggingService.LogInfo("MEF composition error: " + error.Message); } // For now while we're still transitioning to VSMEF it's useful to work // even if the composition has some errors. TODO: re-enable this. //configuration.ThrowOnErrors (); } RuntimeComposition = RuntimeComposition.CreateRuntimeComposition(configuration); ExportProviderFactory = RuntimeComposition.CreateExportProviderFactory(); ExportProvider = ExportProviderFactory.CreateExportProvider(); HostServices = MefV1HostServices.Create(ExportProvider.AsExportProvider()); ExportProviderV1 = NetFxAdapters.AsExportProvider(ExportProvider); }
async Task InitializeInstanceAsync() { var assemblies = ReadAssembliesFromAddins(); var caching = new Caching(assemblies); // Try to use cached MEF data if (cacheEnabled && caching.CanUse()) { RuntimeComposition = await TryCreateRuntimeCompositionFromCache(caching); } // Otherwise fallback to runtime discovery. if (RuntimeComposition == null) { RuntimeComposition = await CreateRuntimeCompositionFromDiscovery(caching); CachedComposition cacheManager = new CachedComposition(); caching.Write(RuntimeComposition, cacheManager).Ignore(); } ExportProviderFactory = RuntimeComposition.CreateExportProviderFactory(); ExportProvider = ExportProviderFactory.CreateExportProvider(); HostServices = MefV1HostServices.Create(ExportProvider.AsExportProvider()); ExportProviderV1 = NetFxAdapters.AsExportProvider(ExportProvider); }
public void TestPreviewDiagnostic() { var diagnosticService = TestExportProvider.ExportProviderWithCSharpAndVisualBasic.GetExportedValue <IDiagnosticAnalyzerService>() as IDiagnosticUpdateSource; var taskSource = new TaskCompletionSource <DiagnosticsUpdatedArgs>(); diagnosticService.DiagnosticsUpdated += (s, a) => taskSource.TrySetResult(a); using (var previewWorkspace = new PreviewWorkspace(MefV1HostServices.Create(TestExportProvider.ExportProviderWithCSharpAndVisualBasic.AsExportProvider()))) { var solution = previewWorkspace.CurrentSolution .AddProject("project", "project.dll", LanguageNames.CSharp) .AddDocument("document", "class { }") .Project .Solution; Assert.True(previewWorkspace.TryApplyChanges(solution)); previewWorkspace.OpenDocument(previewWorkspace.CurrentSolution.Projects.First().DocumentIds[0]); previewWorkspace.EnableDiagnostic(); // wait 20 seconds taskSource.Task.Wait(20000); if (!taskSource.Task.IsCompleted) { // something is wrong FatalError.Report(new System.Exception("not finished after 20 seconds")); } var args = taskSource.Task.Result; Assert.True(args.Diagnostics.Length > 0); } }
public void UpdatePreview(string text) { const string start = "//["; const string end = "//]"; var service = MefV1HostServices.Create(_componentModel.DefaultExportProvider); var workspace = new PreviewWorkspace(service); var fileName = string.Format("project.{0}", Language == "C#" ? "csproj" : "vbproj"); var project = workspace.CurrentSolution.AddProject(fileName, "assembly.dll", Language); // use the mscorlib, system, and system.core that are loaded in the current process. string[] references = { "mscorlib", "System", "System.Core" }; var metadataService = workspace.Services.GetService <IMetadataService>(); var referenceAssemblies = Thread.GetDomain().GetAssemblies() .Where(x => references.Contains(x.GetName(true).Name, StringComparer.OrdinalIgnoreCase)) .Select(a => metadataService.GetReference(a.Location, MetadataReferenceProperties.Assembly)); project = project.WithMetadataReferences(referenceAssemblies); var document = project.AddDocument("document", SourceText.From(text, Encoding.UTF8)); var formatted = Formatter.FormatAsync(document, this.Options).WaitAndGetResult(CancellationToken.None); var textBuffer = _textBufferFactoryService.CreateTextBuffer(formatted.GetTextAsync().Result.ToString(), _contentType); var container = textBuffer.AsTextContainer(); var documentBackedByTextBuffer = document.WithText(container.CurrentText); var bufferText = textBuffer.CurrentSnapshot.GetText().ToString(); var startIndex = bufferText.IndexOf(start, StringComparison.Ordinal); var endIndex = bufferText.IndexOf(end, StringComparison.Ordinal); var startLine = textBuffer.CurrentSnapshot.GetLineNumberFromPosition(startIndex) + 1; var endLine = textBuffer.CurrentSnapshot.GetLineNumberFromPosition(endIndex); var projection = _projectionBufferFactory.CreateProjectionBufferWithoutIndentation(_contentTypeRegistryService, _editorOptions.CreateOptions(), textBuffer.CurrentSnapshot, "", LineSpan.FromBounds(startLine, endLine)); var textView = _textEditorFactoryService.CreateTextView(projection, _textEditorFactoryService.CreateTextViewRoleSet(PredefinedTextViewRoles.Analyzable)); this.TextViewHost = _textEditorFactoryService.CreateTextViewHost(textView, setFocus: false); workspace.TryApplyChanges(documentBackedByTextBuffer.Project.Solution); workspace.OpenDocument(document.Id); this.TextViewHost.Closed += (s, a) => { workspace.Dispose(); workspace = null; }; }
public VisualStudioWorkspace( SVsServiceProvider serviceProvider, ITextDocumentFactoryService textDocumentFactoryService) : base(MefV1HostServices.Create(GetExportProvider(serviceProvider))) { PrimaryWorkspace.Register(this); _serviceProvider = serviceProvider; _textDocumentFactoryService = textDocumentFactoryService; _backgroundParser = new BackgroundParser(this); _backgroundParser.Start(); _textBufferToTextDocumentMap = new ConditionalWeakTable <ITextBuffer, ITextDocument>(); _documentIdToTextBufferMap = new ConditionalWeakTable <DocumentId, ITextBuffer>(); _textBufferToDocumentIdMap = new ConditionalWeakTable <ITextBuffer, DocumentId>(); _textBufferToViewsMap = new ConditionalWeakTable <ITextBuffer, List <ITextView> >(); _textViewToBuffersMap = new ConditionalWeakTable <ITextView, List <ITextBuffer> >(); Services.GetService <IDocumentTrackingService>(); if (Services.GetService <IOptionService>() is OptionServiceFactory.OptionService optionService) { optionService.RegisterDocumentOptionsProvider(new Implementation.Options.EditorconfigDocumentOptionsProvider()); } }
internal void Test( Func <SyntaxGenerator, SyntaxNode> nodeCreator, string cs, string vb) { var hostServices = MefV1HostServices.Create(TestExportProvider.ExportProviderWithCSharpAndVisualBasic.AsExportProvider()); var workspace = new AdhocWorkspace(hostServices); if (cs != null) { var csharpCodeGenService = workspace.Services.GetLanguageServices(LanguageNames.CSharp).GetService <ICodeGenerationService>(); var codeDefFactory = workspace.Services.GetLanguageServices(LanguageNames.CSharp).GetService <SyntaxGenerator>(); var node = nodeCreator(codeDefFactory); node = node.NormalizeWhitespace(); TokenUtilities.AssertTokensEqual(cs, node.ToFullString(), LanguageNames.CSharp); } if (vb != null) { var visualBasicCodeGenService = workspace.Services.GetLanguageServices(LanguageNames.VisualBasic).GetService <ICodeGenerationService>(); var codeDefFactory = workspace.Services.GetLanguageServices(LanguageNames.VisualBasic).GetService <SyntaxGenerator>(); var node = nodeCreator(codeDefFactory); node = node.NormalizeWhitespace(); TokenUtilities.AssertTokensEqual(vb, node.ToString(), LanguageNames.VisualBasic); } }
public VisualStudioWorkspaceImpl(ExportProvider exportProvider) : base( MefV1HostServices.Create(exportProvider), backgroundWork: WorkspaceBackgroundWork.ParseAndCompile) { _textBufferCloneService = exportProvider.GetExportedValue <ITextBufferCloneService>(); _textBufferFactoryService = exportProvider.GetExportedValue <ITextBufferFactoryService>(); _textBufferFactoryService.TextBufferCreated += AddTextBufferCloneServiceToBuffer; exportProvider.GetExportedValue <PrimaryWorkspace>().Register(this); }
internal void Test( Func <SyntaxGenerator, SyntaxNode> nodeCreator, string cs, string csSimple, string vb, string vbSimple) { Assert.True(cs != null || csSimple != null || vb != null || vbSimple != null, $"At least one of {nameof(cs)}, {nameof(csSimple)}, {nameof(vb)}, {nameof(vbSimple)} must be provided"); var hostServices = MefV1HostServices.Create(TestExportProvider.ExportProviderWithCSharpAndVisualBasic.AsExportProvider()); var workspace = new AdhocWorkspace(hostServices); if (cs != null || csSimple != null) { var codeDefFactory = workspace.Services.GetLanguageServices(LanguageNames.CSharp).GetService <SyntaxGenerator>(); var node = nodeCreator(codeDefFactory); node = node.NormalizeWhitespace(); if (cs != null) { TokenUtilities.AssertTokensEqual(cs, node.ToFullString(), LanguageNames.CSharp); } if (csSimple != null) { var simplifiedRootNode = Simplify(workspace, WrapExpressionInBoilerplate(node, codeDefFactory), LanguageNames.CSharp); var expression = simplifiedRootNode.DescendantNodes().OfType <EqualsValueClauseSyntax>().First().Value; TokenUtilities.AssertTokensEqual(csSimple, expression.NormalizeWhitespace().ToFullString(), LanguageNames.CSharp); } } if (vb != null || vbSimple != null) { var codeDefFactory = workspace.Services.GetLanguageServices(LanguageNames.VisualBasic).GetService <SyntaxGenerator>(); var node = nodeCreator(codeDefFactory); node = node.NormalizeWhitespace(); if (vb != null) { TokenUtilities.AssertTokensEqual(vb, node.ToFullString(), LanguageNames.VisualBasic); } if (vbSimple != null) { var simplifiedRootNode = Simplify(workspace, WrapExpressionInBoilerplate(node, codeDefFactory), LanguageNames.VisualBasic); var expression = simplifiedRootNode.DescendantNodes().OfType <EqualsValueSyntax>().First().Value; TokenUtilities.AssertTokensEqual(vbSimple, expression.NormalizeWhitespace().ToFullString(), LanguageNames.VisualBasic); } } }
public void TestPreviewServices() { using (var previewWorkspace = new PreviewWorkspace(MefV1HostServices.Create(EditorServicesUtil.ExportProvider.AsExportProvider()))) { var service = previewWorkspace.Services.GetService <ISolutionCrawlerRegistrationService>(); Assert.True(service is PreviewSolutionCrawlerRegistrationServiceFactory.Service); var persistentService = previewWorkspace.Services.GetService <IPersistentStorageService>(); Assert.NotNull(persistentService); var storage = persistentService.GetStorage(previewWorkspace.CurrentSolution); Assert.True(storage is NoOpPersistentStorage); } }
public TestWorkspace(ExportProvider exportProvider, string workspaceKind = null, bool disablePartialSolutions = true) : base(MefV1HostServices.Create(exportProvider.AsExportProvider()), workspaceKind ?? WorkspaceKind.Test) { ResetThreadAffinity(); this.TestHookPartialSolutionsDisabled = disablePartialSolutions; this.ExportProvider = exportProvider; this.Projects = new List <TestHostProject>(); this.Documents = new List <TestHostDocument>(); this.AdditionalDocuments = new List <TestHostDocument>(); this.ProjectionDocuments = new List <TestHostDocument>(); this.CanApplyChangeDocument = true; }
public void TestPreviewServices() { using (var previewWorkspace = new PreviewWorkspace(MefV1HostServices.Create(TestExportProvider.ExportProviderWithCSharpAndVisualBasic.AsExportProvider()))) { var workcoordinatorService = previewWorkspace.Services.GetService <IWorkCoordinatorRegistrationService>(); Assert.True(workcoordinatorService is PreviewWorkCoordinatorRegistrationService); var persistentService = previewWorkspace.Services.GetService <IPersistentStorageService>(); Assert.NotNull(persistentService); var storage = persistentService.GetStorage(previewWorkspace.CurrentSolution); Assert.True(storage is NoOpPersistentStorage); } }
async Task InitializeInstanceAsync() { var timings = new Dictionary <string, long> (); var metadata = new CompositionLoadMetadata(timings); using (var timer = Counters.CompositionLoad.BeginTiming(metadata)) { var fullTimer = System.Diagnostics.Stopwatch.StartNew(); var stepTimer = System.Diagnostics.Stopwatch.StartNew(); var mefAssemblies = ReadAssembliesFromAddins(timer); timings ["ReadFromAddins"] = stepTimer.ElapsedMilliseconds; stepTimer.Restart(); var caching = new Caching(mefAssemblies); // Try to use cached MEF data var canUse = metadata.ValidCache = caching.CanUse(); if (canUse) { LoggingService.LogInfo("Creating MEF composition from cache"); RuntimeComposition = await TryCreateRuntimeCompositionFromCache(caching); } timings ["LoadFromCache"] = stepTimer.ElapsedMilliseconds; stepTimer.Restart(); // Otherwise fallback to runtime discovery. if (RuntimeComposition == null) { LoggingService.LogInfo("Creating MEF composition from runtime"); var(runtimeComposition, catalog) = await CreateRuntimeCompositionFromDiscovery(caching, timer); RuntimeComposition = runtimeComposition; CachedComposition cacheManager = new CachedComposition(); caching.Write(RuntimeComposition, catalog, cacheManager).Ignore(); } timings ["LoadRuntimeComposition"] = stepTimer.ElapsedMilliseconds; stepTimer.Restart(); ExportProviderFactory = RuntimeComposition.CreateExportProviderFactory(); ExportProvider = ExportProviderFactory.CreateExportProvider(); HostServices = MefV1HostServices.Create(ExportProvider.AsExportProvider()); ExportProviderV1 = NetFxAdapters.AsExportProvider(ExportProvider); timings ["CreateServices"] = stepTimer.ElapsedMilliseconds; metadata.Duration = fullTimer.ElapsedMilliseconds; } }
public RoslynSetup(SVsServiceProvider exportProvider) { var componentModel = (IComponentModel)exportProvider.GetService(typeof(SComponentModel)); // Initialize the base Workspace only (to set Services) // The MefV1HostServices call breaks compatibility with // older Dev14 CTPs; that could be fixed by reflection. typeof(Workspace).GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance)[0] .Invoke(vsWorkspace, new object[] { MefV1HostServices.Create(componentModel.DefaultExportProvider), "FakeWorkspace" }); var diagnosticService = componentModel.DefaultExportProvider .GetExport <object>("Microsoft.CodeAnalysis.Diagnostics.IDiagnosticAnalyzerService").Value; // Roslyn loads analyzers from DLL filenames that come from the VS-layer // IWorkspaceDiagnosticAnalyzerProviderService. This uses internal types // which I cannot provide. Instead, I inject the standard analyzers into // DiagnosticAnalyzerService myself, after it's created. var analyzerManager = diagnosticService.GetType() .GetField("_hostAnalyzerManager", BindingFlags.NonPublic | BindingFlags.Instance) .GetValue(diagnosticService); analyzerManager.GetType() .GetField("_hostAnalyzerReferencesMap", BindingFlags.NonPublic | BindingFlags.Instance) .SetValue(analyzerManager, new[] { "Microsoft.CodeAnalysis.Features.dll", "Microsoft.CodeAnalysis.EditorFeatures.dll", "Microsoft.CodeAnalysis.CSharp.dll", "Microsoft.CodeAnalysis.CSharp.Features.dll", "Microsoft.CodeAnalysis.CSharp.EditorFeatures.dll", "Microsoft.CodeAnalysis.VisualBasic.dll", "Microsoft.CodeAnalysis.VisualBasic.Features.dll", "Microsoft.CodeAnalysis.VisualBasic.EditorFeatures.dll", }.Select(name => new AnalyzerFileReference( Path.Combine(VsLoader.RoslynAssemblyPath, name), new AnalyzerLoader() )) .ToImmutableDictionary <AnalyzerReference, object>(a => a.Id)); // Based on HostAnalyzerManager.CreateAnalyzerReferencesMap var packageType = Type.GetType("Microsoft.VisualStudio.LanguageServices.Setup.RoslynPackage, Microsoft.VisualStudio.LanguageServices"); var package = Activator.CreateInstance(packageType, nonPublic: true); // Bind Roslyn UI to VS theme colors packageType.GetMethod("InitializeColors", BindingFlags.Instance | BindingFlags.NonPublic) .Invoke(package, null); }
public TestWorkspace(ExportProvider exportProvider, string workspaceKind = null, bool disablePartialSolutions = true) : base(MefV1HostServices.Create(exportProvider.AsExportProvider()), workspaceKind ?? WorkspaceKind.Test) { this.TestHookPartialSolutionsDisabled = disablePartialSolutions; this.ExportProvider = exportProvider; this.Projects = new List <TestHostProject>(); this.Documents = new List <TestHostDocument>(); this.AdditionalDocuments = new List <TestHostDocument>(); this.ProjectionDocuments = new List <TestHostDocument>(); this.CanApplyChangeDocument = true; _backgroundCompiler = new BackgroundCompiler(this); _backgroundParser = new BackgroundParser(this); _backgroundParser.Start(); _metadataAsSourceFileService = exportProvider.GetExportedValues <IMetadataAsSourceFileService>().FirstOrDefault(); }
void CreateWorkspace(ITextBuffer buffer) { if (buffer.GetWorkspace() != null || !buffer.ContentType.IsOfType("Roslyn Languages")) { return; } var componentModel = (IComponentModel)ExportProvider.GetService(typeof(SComponentModel)); var workspace = new EditorWorkspace(MefV1HostServices.Create(componentModel.DefaultExportProvider)); var project = workspace.CurrentSolution .AddProject("Sample Project", "SampleProject", contentTypeLanguages[buffer.ContentType.DisplayName]) .AddMetadataReferences(new[] { "mscorlib", "System", "System.Core", "System.Xml.Linq" } .Select(EditorWorkspace.CreateFrameworkReference) ); project = project.WithParseOptions(project.ParseOptions.WithKind(SourceCodeKind.Script)); workspace.TryApplyChanges(project.Solution); workspace.CreateDocument(project.Id, buffer); }
public VisualStudioWorkspace( SVsServiceProvider serviceProvider, ITextDocumentFactoryService textDocumentFactoryService) : base(MefV1HostServices.Create(GetExportProvider(serviceProvider))) { PrimaryWorkspace.Register(this); _serviceProvider = serviceProvider; _textDocumentFactoryService = textDocumentFactoryService; _backgroundParser = new BackgroundParser(this); _backgroundParser.Start(); _textBufferToTextDocumentMap = new ConditionalWeakTable <ITextBuffer, ITextDocument>(); _textBufferToDocumentIdMap = new ConditionalWeakTable <ITextBuffer, DocumentId>(); _textBufferToViewsMap = new ConditionalWeakTable <ITextBuffer, List <ITextView> >(); _textViewToBuffersMap = new ConditionalWeakTable <ITextView, List <ITextBuffer> >(); Services.GetService <IDocumentTrackingService>(); }
public void UpdatePreview(string text) { const string start = "//["; const string end = "//]"; var service = MefV1HostServices.Create(_componentModel.DefaultExportProvider); var workspace = new PreviewWorkspace(service); var document = workspace.OpenDocument(DocumentId.CreateNewId("document"), SourceText.From(text), Language); var formatted = Formatter.FormatAsync(document, this.Options).WaitAndGetResult(CancellationToken.None); var textBuffer = _textBufferFactoryService.CreateTextBuffer(formatted.SourceText.ToString(), _contentType); var container = textBuffer.AsTextContainer(); var documentBackedByTextBuffer = document.WithText(container.CurrentText); var bufferText = textBuffer.CurrentSnapshot.GetText().ToString(); var startIndex = bufferText.IndexOf(start, StringComparison.Ordinal); var endIndex = bufferText.IndexOf(end, StringComparison.Ordinal); var startLine = textBuffer.CurrentSnapshot.GetLineNumberFromPosition(startIndex) + 1; var endLine = textBuffer.CurrentSnapshot.GetLineNumberFromPosition(endIndex); var projection = _projectionBufferFactory.CreateProjectionBufferWithoutIndentation(_contentTypeRegistryService, _editorOptions.CreateOptions(), textBuffer.CurrentSnapshot, "", LineSpan.FromBounds(startLine, endLine)); var textView = _textEditorFactoryService.CreateTextView(projection, _textEditorFactoryService.CreateTextViewRoleSet()); this.TextViewHost = _textEditorFactoryService.CreateTextViewHost(textView, setFocus: false); workspace.CloseDocument(document.Id); workspace.OpenDocument(document.Id, documentBackedByTextBuffer.SourceText, Language); //workspace.UpdateDocument(documentBackedByTextBuffer.Id, documentBackedByTextBuffer.SourceText); }
internal static HostServices CreateHostServices(SVsServiceProvider serviceProvider) { var composition = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel)); return(MefV1HostServices.Create(composition.DefaultExportProvider)); }
public static HostServices CreateHostServices(ExportProvider exportProvider = null) { exportProvider = exportProvider ?? CreateMinimalExportProvider(); return(MefV1HostServices.Create(exportProvider.AsExportProvider())); }
public static HostServices CreateHostServices() { return(MefV1HostServices.Create( MinimalTestExportProvider.CreateExportProvider( ServiceTestExportProvider.CreateAssemblyCatalog().WithPart(typeof(InProcRemoteHostClientFactory))).AsExportProvider())); }
public void OnBlockCreated(ITextBuffer editorBuffer, LanguageProjectionBuffer projectionBuffer) { var componentModel = (IComponentModel)ServiceProvider.GetService(typeof(SComponentModel)); var workspace = editorBuffer.Properties.GetOrCreateSingletonProperty(() => new MarkdownWorkspace(MefV1HostServices.Create(componentModel.DefaultExportProvider)) ); var contentType = projectionBuffer.IProjectionBuffer.ContentType.DisplayName; var projectId = editorBuffer.Properties.GetOrCreateSingletonProperty(contentType, () => { var newProject = workspace.CurrentSolution .AddProject(contentType + " Markdown Project", "Markdown", contentTypeLanguages[contentType]) .AddMetadataReferences( DefaultReferences.Select(name => VSWorkspace.CreatePortableExecutableReference( Path.Combine(referenceAssemblyPath, name + ".dll"), MetadataReferenceProperties.Assembly )) ); workspace.TryApplyChanges(newProject.Solution); return(newProject.Id); }); workspace.CreateDocument(projectId, projectionBuffer.IProjectionBuffer); WindowHelpers.WaitFor(delegate { var textView = TextViewConnectionListener.GetFirstViewForBuffer(editorBuffer); if (textView == null) { return(false); } InstallCommandTarget(textView, projectionBuffer.IProjectionBuffer); return(true); }); }
public ExportProviderMefHostServices(ExportProvider exportProvider) : base(new ContainerConfiguration().CreateContainer()) { _mefV1HostServices = MefV1HostServices.Create(exportProvider.AsExportProvider()); }