// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Threading; using System.Threading.Tasks; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.Editor { internal class SolutionPreviewItem { public readonly ProjectId ProjectId; public readonly DocumentId DocumentId; public readonly Func> LazyPreview; public readonly string Text; /// /// Construct an instance of /// /// for the that contains the content being visualized in the supplied /// for the being visualized in the supplied /// Lazily instantiated preview content. /// Use lazy instantiation to ensure that any IWpfTextViews that may be present inside a given preview are only instantiated at the point /// when the VS lightbulb requests that preview. Otherwise, we could end up instantiating a bunch of IWpfTextViews most of which will never get /// passed to the VS lightbulb. Such zombie IWpfTextViews will never get closed and we will end up leaking memory. public SolutionPreviewItem(ProjectId projectId, DocumentId documentId, Func> lazyPreview) { ProjectId = projectId; DocumentId = documentId; LazyPreview = lazyPreview; } public SolutionPreviewItem(ProjectId projectId, DocumentId documentId, string text) : this(projectId, documentId, c => Task.FromResult(text)) { Text = text; } } }