当前位置: 首页>>代码示例>>C#>>正文


C# PreviewWorkspace.OpenAdditionalDocument方法代码示例

本文整理汇总了C#中Microsoft.CodeAnalysis.Editor.Shared.Preview.PreviewWorkspace.OpenAdditionalDocument方法的典型用法代码示例。如果您正苦于以下问题:C# PreviewWorkspace.OpenAdditionalDocument方法的具体用法?C# PreviewWorkspace.OpenAdditionalDocument怎么用?C# PreviewWorkspace.OpenAdditionalDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.CodeAnalysis.Editor.Shared.Preview.PreviewWorkspace的用法示例。


在下文中一共展示了PreviewWorkspace.OpenAdditionalDocument方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateRemovedAdditionalDocumentPreviewViewAsync

        public Task<object> CreateRemovedAdditionalDocumentPreviewViewAsync(TextDocument document, double zoomLevel, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            // Note: We don't use the original buffer that is associated with oldDocument
            // (and possibly open in the editor) for oldBuffer below. This is because oldBuffer
            // will be used inside a projection buffer inside our inline diff preview below
            // and platform's implementation currently has a bug where projection buffers
            // are being leaked. This leak means that if we use the original buffer that is
            // currently visible in the editor here, the projection buffer span calculation
            // would be triggered every time user changes some code in this buffer (even though
            // the diff view would long have been dismissed by the time user edits the code)
            // resulting in crashes. Instead we create a new buffer from the same content.
            // TODO: We could use ITextBufferCloneService instead here to clone the original buffer.
            var oldBuffer = CreateNewPlainTextBuffer(document, cancellationToken);

            // Create PreviewWorkspace around the buffer to be displayed in the diff preview
            // so that all IDE services (colorizer, squiggles etc.) light up in this buffer.
            var leftDocumentId = DocumentId.CreateNewId(document.Project.Id);
            var leftSolution = document.Project.Solution
                .RemoveAdditionalDocument(document.Id)
                .AddAdditionalDocument(leftDocumentId, document.Name, oldBuffer.AsTextContainer().CurrentText);
            var leftDocument = leftSolution.GetAdditionalDocument(leftDocumentId);
            var leftWorkspace = new PreviewWorkspace(leftSolution);
            leftWorkspace.OpenAdditionalDocument(leftDocumentId);

            return CreateRemovedDocumentPreviewViewCoreAsync(oldBuffer, leftWorkspace, leftDocument, zoomLevel, cancellationToken);
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:28,代码来源:PreviewFactoryService.cs

示例2: CreateChangedAdditionalDocumentPreviewViewAsync

        public Task<object> CreateChangedAdditionalDocumentPreviewViewAsync(TextDocument oldDocument, TextDocument newDocument, double zoomLevel, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            // Note: We don't use the original buffer that is associated with oldDocument
            // (and currently open in the editor) for oldBuffer below. This is because oldBuffer
            // will be used inside a projection buffer inside our inline diff preview below
            // and platform's implementation currently has a bug where projection buffers
            // are being leaked. This leak means that if we use the original buffer that is
            // currently visible in the editor here, the projection buffer span calculation
            // would be triggered every time user changes some code in this buffer (even though
            // the diff view would long have been dismissed by the time user edits the code)
            // resulting in crashes. Instead we create a new buffer from the same content.
            // TODO: We could use ITextBufferCloneService instead here to clone the original buffer.
            var oldBuffer = CreateNewPlainTextBuffer(oldDocument, cancellationToken);
            var newBuffer = CreateNewPlainTextBuffer(newDocument, cancellationToken);

            // Convert the diffs to be line based.  
            // Compute the diffs between the old text and the new.
            var diffResult = ComputeEditDifferences(oldDocument, newDocument, cancellationToken);

            // Need to show the spans in the right that are different.
            var originalSpans = GetOriginalSpans(diffResult, cancellationToken);
            var changedSpans = GetChangedSpans(diffResult, cancellationToken);

            string description = null;
            var originalLineSpans = CreateLineSpans(oldBuffer.CurrentSnapshot, originalSpans, cancellationToken);
            var changedLineSpans = CreateLineSpans(newBuffer.CurrentSnapshot, changedSpans, cancellationToken);

            // TODO: Why aren't we attaching conflict / warning annotations here like we do for regular documents above?

            // Create PreviewWorkspaces around the buffers to be displayed on the left and right
            // so that all IDE services (colorizer, squiggles etc.) light up in these buffers.
            var leftDocumentId = DocumentId.CreateNewId(oldDocument.Project.Id);
            var leftSolution = oldDocument.Project.Solution
                .RemoveAdditionalDocument(oldDocument.Id)
                .AddAdditionalDocument(leftDocumentId, oldDocument.Name, oldBuffer.AsTextContainer().CurrentText);
            var leftWorkspace = new PreviewWorkspace(leftSolution);
            leftWorkspace.OpenAdditionalDocument(leftDocumentId);

            var rightWorkSpace = new PreviewWorkspace(
                oldDocument.Project.Solution.WithAdditionalDocumentText(oldDocument.Id, newBuffer.AsTextContainer().CurrentText));
            rightWorkSpace.OpenAdditionalDocument(newDocument.Id);

            return CreateChangedDocumentViewAsync(
                oldBuffer, newBuffer, description, originalLineSpans, changedLineSpans,
                leftWorkspace, rightWorkSpace, zoomLevel, cancellationToken);
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:48,代码来源:PreviewFactoryService.cs

示例3: CreateAddedAdditionalDocumentPreviewViewAsync

        public Task<object> CreateAddedAdditionalDocumentPreviewViewAsync(TextDocument document, double zoomLevel, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            var newBuffer = CreateNewPlainTextBuffer(document, cancellationToken);

            // Create PreviewWorkspace around the buffer to be displayed in the diff preview
            // so that all IDE services (colorizer, squiggles etc.) light up in this buffer.
            var rightWorkspace = new PreviewWorkspace(
                document.Project.Solution.WithAdditionalDocumentText(document.Id, newBuffer.AsTextContainer().CurrentText));
            rightWorkspace.OpenAdditionalDocument(document.Id);

            return CreateAddedDocumentPreviewViewCoreAsync(newBuffer, rightWorkspace, document, zoomLevel, cancellationToken);
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:13,代码来源:PreviewFactoryService.cs


注:本文中的Microsoft.CodeAnalysis.Editor.Shared.Preview.PreviewWorkspace.OpenAdditionalDocument方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。