Пример #1
0
        protected virtual async Task InjectBufferAtSpan(Viewport viewPort, Buffer sourceBuffer, ICollection <Buffer> buffers, IDictionary <string, SourceFile> files, TextSpan span)
        {
            var tree       = CSharpSyntaxTree.ParseText(viewPort.Destination.Text.ToString());
            var textChange = new TextChange(
                span,
                $"{Padding}{sourceBuffer.Content}{Padding}");

            var txt = tree.WithChangedText(tree.GetText().WithChanges(textChange));

            var offset = span.Start + PaddingSize;

            var newCode = (await txt.GetTextAsync()).ToString();

            buffers.Add(new Buffer(
                            sourceBuffer.Id,
                            sourceBuffer.Content,
                            sourceBuffer.Position,
                            offset));
            files[viewPort.Destination.Name] = SourceFile.Create(newCode, viewPort.Destination.Name);
        }
Пример #2
0
        protected Task InjectBuffer(Viewport viewPort, Buffer sourceBuffer, ICollection <Buffer> buffers, IDictionary <string, SourceFile> files,
                                    BufferInjectionPoints bufferIdInjectionPoints)
        {
            TextSpan targetSpan;

            switch (bufferIdInjectionPoints)
            {
            case BufferInjectionPoints.Before:
                targetSpan = CreateTextSpanBefore(viewPort.OuterRegion);
                break;

            case BufferInjectionPoints.After:
                targetSpan = CreateTextSpanAfter(viewPort.OuterRegion);
                break;

            default:
                targetSpan = viewPort.Region;
                break;
            }
            return(InjectBufferAtSpan(viewPort, sourceBuffer, buffers, files, targetSpan));
        }