• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# TextChange类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中TextChange的典型用法代码示例。如果您正苦于以下问题:C# TextChange类的具体用法?C# TextChange怎么用?C# TextChange使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TextChange类属于命名空间,在下文中一共展示了TextChange类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: TryGetDocumentWithFullyQualifiedTypeName

        private bool TryGetDocumentWithFullyQualifiedTypeName(Document document, out TextSpan updatedTextSpan, out Document documentWithFullyQualifiedTypeName)
        {
            documentWithFullyQualifiedTypeName = null;
            updatedTextSpan = default(TextSpan);

            var surfaceBufferFieldSpan = new VsTextSpan[1];
            if (snippetExpansionClient.ExpansionSession.GetFieldSpan(_fieldName, surfaceBufferFieldSpan) != VSConstants.S_OK)
            {
                return false;
            }

            SnapshotSpan subjectBufferFieldSpan;
            if (!snippetExpansionClient.TryGetSubjectBufferSpan(surfaceBufferFieldSpan[0], out subjectBufferFieldSpan))
            {
                return false;
            }

            var originalTextSpan = new TextSpan(subjectBufferFieldSpan.Start, subjectBufferFieldSpan.Length);
            updatedTextSpan = new TextSpan(subjectBufferFieldSpan.Start, _fullyQualifiedName.Length);

            var textChange = new TextChange(originalTextSpan, _fullyQualifiedName);
            var newText = document.GetTextAsync(CancellationToken.None).WaitAndGetResult(CancellationToken.None).WithChanges(textChange);

            documentWithFullyQualifiedTypeName = document.WithText(newText);
            return true;
        }
开发者ID:CAPCHIK,项目名称:roslyn,代码行数:26,代码来源:AbstractSnippetFunctionSimpleTypeName.cs


示例2: OwnsChange

 public virtual bool OwnsChange(Span target, TextChange change)
 {
     var end = target.Start.AbsoluteIndex + target.Length;
     var changeOldEnd = change.OldPosition + change.OldLength;
     return change.OldPosition >= target.Start.AbsoluteIndex &&
            (changeOldEnd < end || (changeOldEnd == end && AcceptedCharacters != AcceptedCharacters.None));
 }
开发者ID:cjqian,项目名称:Razor,代码行数:7,代码来源:SpanEditHandler.cs


示例3: GetTransformedDocumentAsync

        private static async Task<Document> GetTransformedDocumentAsync(Document document, Diagnostic diagnostic, CancellationToken cancellationToken)
        {
            var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
            var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);

            TextChange textChange = new TextChange(new TextSpan(diagnostic.Location.SourceSpan.Start, 1), string.Empty);
            return document.WithText(text.WithChanges(textChange));
        }
开发者ID:Romanx,项目名称:StyleCopAnalyzers,代码行数:8,代码来源:SA1626CodeFixProvider.cs


示例4: RaiseChangeCompleted

 public void RaiseChangeCompleted(TextChange change)
 {
     var e = ChangeCompleted;
     if (e != null)
     {
         e(this, change);
     }
 }
开发者ID:rride,项目名称:VsVim,代码行数:8,代码来源:MockTextChangeTracker.cs


示例5: GetTransformedDocumentAsync

        private static async Task<Document> GetTransformedDocumentAsync(Document document, Diagnostic diagnostic, CancellationToken token)
        {
            var newLine = document.Project.Solution.Workspace.Options.GetOption(FormattingOptions.NewLine, LanguageNames.CSharp);

            var sourceText = await document.GetTextAsync(token).ConfigureAwait(false);
            var textChange = new TextChange(diagnostic.Location.SourceSpan, newLine);

            return document.WithText(sourceText.WithChanges(textChange));
        }
开发者ID:endjin,项目名称:StyleCopAnalyzers,代码行数:9,代码来源:SA1507CodeFixProvider.cs


示例6: parameter

#pragma warning disable RS0027 // Public API with optional parameter(s) should have the most parameters amongst its public overloads.
#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters
        public static CompletionChange Create(
#pragma warning restore RS0026 // Do not add multiple public overloads with optional parameters
#pragma warning restore RS0027 // Public API with optional parameter(s) should have the most parameters amongst its public overloads.
            TextChange textChange,
            int? newPosition = null,
            bool includesCommitCharacter = false)
        {
            return new CompletionChange(textChange, newPosition, includesCommitCharacter);
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:11,代码来源:CompletionChange.cs


示例7: CompletionChange

        private CompletionChange(TextChange textChange, int? newPosition, bool includesCommitCharacter)
        {
            TextChange = textChange;
#pragma warning disable CS0618 // Type or member is obsolete
            TextChanges = ImmutableArray.Create(textChange);
#pragma warning restore CS0618 // Type or member is obsolete
            NewPosition = newPosition;
            IncludesCommitCharacter = includesCommitCharacter;
        }
开发者ID:Rickinio,项目名称:roslyn,代码行数:9,代码来源:CompletionChange.cs


示例8: TestIsDelete

        public void TestIsDelete()
        {
            // Arrange
            var oldBuffer = new Mock<ITextBuffer>().Object;
            var newBuffer = new Mock<ITextBuffer>().Object;
            var change = new TextChange(0, 1, oldBuffer, 0, newBuffer);

            // Assert
            Assert.True(change.IsDelete);
        }
开发者ID:cjqian,项目名称:Razor,代码行数:10,代码来源:TextChangeTest.cs


示例9: Bug18241

 public void Bug18241()
 {
     var tree = SyntaxFactory.ParseSyntaxTree(" class C { void M() { await X() on ");
     SourceText text = tree.GetText();
     TextSpan span = new TextSpan(text.Length, 0);
     TextChange change = new TextChange(span, "/*comment*/");
     SourceText newText = text.WithChanges(change);
     // This line caused an assertion and then crashed in the parser.
     var newTree = tree.WithChangedText(newText);
 }
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:10,代码来源:BindingAwaitTests.cs


示例10: TestDeleteCreatesTheRightSizeChange

        public void TestDeleteCreatesTheRightSizeChange()
        {
            // Arrange
            var oldBuffer = new Mock<ITextBuffer>().Object;
            var newBuffer = new Mock<ITextBuffer>().Object;
            var change = new TextChange(0, 1, oldBuffer, 0, newBuffer);

            // Assert
            Assert.Equal(0, change.NewText.Length);
            Assert.Equal(1, change.OldText.Length);
        }
开发者ID:cjqian,项目名称:Razor,代码行数:11,代码来源:TextChangeTest.cs


示例11: CanAcceptChange

 protected override PartialParseResult CanAcceptChange(Span target, TextChange normalizedChange)
 {
     if (((AutoCompleteAtEndOfSpan && IsAtEndOfSpan(target, normalizedChange)) || IsAtEndOfFirstLine(target, normalizedChange)) &&
         normalizedChange.IsInsert &&
         ParserHelpers.IsNewLine(normalizedChange.NewText) &&
         AutoCompleteString != null)
     {
         return PartialParseResult.Rejected | PartialParseResult.AutoCompleteBlock;
     }
     return PartialParseResult.Rejected;
 }
开发者ID:x-strong,项目名称:Razor,代码行数:11,代码来源:AutoCompleteEditHandler.cs


示例12: CanAcceptChange

        protected override PartialParseResult CanAcceptChange(Span target, TextChange normalizedChange)
        {
            if (AcceptedCharacters == AcceptedCharacters.Any)
            {
                return PartialParseResult.Rejected;
            }

            // In some editors intellisense insertions are handled as "dotless commits".  If an intellisense selection is confirmed
            // via something like '.' a dotless commit will append a '.' and then insert the remaining intellisense selection prior
            // to the appended '.'.  This 'if' statement attempts to accept the intermediate steps of a dotless commit via
            // intellisense.  It will accept two cases:
            //     1. '@foo.' -> '@foobaz.'.
            //     2. '@foobaz..' -> '@foobaz.bar.'. Includes Sub-cases '@foobaz()..' -> '@foobaz().bar.' etc.
            // The key distinction being the double '.' in the second case.
            if (IsDotlessCommitInsertion(target, normalizedChange))
            {
                return HandleDotlessCommitInsertion(target);
            }

            if (IsAcceptableReplace(target, normalizedChange))
            {
                return HandleReplacement(target, normalizedChange);
            }
            var changeRelativePosition = normalizedChange.OldPosition - target.Start.AbsoluteIndex;

            // Get the edit context
            char? lastChar = null;
            if (changeRelativePosition > 0 && target.Content.Length > 0)
            {
                lastChar = target.Content[changeRelativePosition - 1];
            }

            // Don't support 0->1 length edits
            if (lastChar == null)
            {
                return PartialParseResult.Rejected;
            }

            // Accepts cases when insertions are made at the end of a span or '.' is inserted within a span.
            if (IsAcceptableInsertion(target, normalizedChange))
            {
                // Handle the insertion
                return HandleInsertion(target, lastChar.Value, normalizedChange);
            }

            if (IsAcceptableDeletion(target, normalizedChange))
            {
                return HandleDeletion(target, lastChar.Value, normalizedChange);
            }

            return PartialParseResult.Rejected;
        }
开发者ID:cjqian,项目名称:Razor,代码行数:52,代码来源:ImplicitExpressionEditHandler.cs


示例13: Create

 private void Create(params string[] lines)
 {
     _textView = CreateTextView(lines);
     _textBuffer = _textView.TextBuffer;
     _factory = new MockRepository(MockBehavior.Loose);
     _operations = _factory.Create<ICommonOperations>(MockBehavior.Strict);
     _vimTextBuffer = _factory.Create<IVimTextBuffer>(MockBehavior.Strict);
     _vimTextBuffer.SetupProperty(x => x.LastEditPoint);
     _trackerRaw = new TextChangeTracker(_vimTextBuffer.Object, _textView, _operations.Object);
     _trackerRaw.TrackCurrentChange = true;
     _tracker = _trackerRaw;
     _tracker.ChangeCompleted += (sender, args) => { _lastChange = args.TextChange; };
 }
开发者ID:Kazark,项目名称:VsVim,代码行数:13,代码来源:TextChangeTrackerTest.cs


示例14: ConstructorInitializesProperties

        public void ConstructorInitializesProperties()
        {
            // Act
            var oldBuffer = new Mock<ITextBuffer>().Object;
            var newBuffer = new Mock<ITextBuffer>().Object;
            var change = new TextChange(42, 24, oldBuffer, 1337, newBuffer);

            // Assert
            Assert.Equal(42, change.OldPosition);
            Assert.Equal(24, change.OldLength);
            Assert.Equal(1337, change.NewLength);
            Assert.Same(newBuffer, change.NewBuffer);
            Assert.Same(oldBuffer, change.OldBuffer);
        }
开发者ID:cjqian,项目名称:Razor,代码行数:14,代码来源:TextChangeTest.cs


示例15: ApplyChange

        public virtual EditResult ApplyChange(Span target, TextChange change, bool force)
        {
            var result = PartialParseResult.Accepted;
            var normalized = change.Normalize();
            if (!force)
            {
                result = CanAcceptChange(target, normalized);
            }

            // If the change is accepted then apply the change
            if ((result & PartialParseResult.Accepted) == PartialParseResult.Accepted)
            {
                return new EditResult(result, UpdateSpan(target, normalized));
            }
            return new EditResult(result, new SpanBuilder(target));
        }
开发者ID:cjqian,项目名称:Razor,代码行数:16,代码来源:SpanEditHandler.cs


示例16: UpdateSpan

 protected virtual SpanBuilder UpdateSpan(Span target, TextChange normalizedChange)
 {
     var newContent = normalizedChange.ApplyChange(target);
     var newSpan = new SpanBuilder(target);
     newSpan.ClearSymbols();
     foreach (ISymbol sym in Tokenizer(newContent))
     {
         sym.OffsetStart(target.Start);
         newSpan.Accept(sym);
     }
     if (target.Next != null)
     {
         var newEnd = SourceLocationTracker.CalculateNewLocation(target.Start, newContent);
         target.Next.ChangeStart(newEnd);
     }
     return newSpan;
 }
开发者ID:cjqian,项目名称:Razor,代码行数:17,代码来源:SpanEditHandler.cs


示例17: AdjustForVirtualSpace

        private string AdjustForVirtualSpace(TextChange textChange)
        {
            var newText = textChange.NewText;

            var caretPoint = this.TextView.Caret.Position.BufferPosition;
            var virtualCaretPoint = this.TextView.Caret.Position.VirtualBufferPosition;

            if (textChange.Span.IsEmpty &&
                textChange.Span.Start == caretPoint &&
                virtualCaretPoint.IsInVirtualSpace)
            {
                // They're in virtual space and the text change is specified against the cursor
                // position that isn't in virtual space.  In this case, add the virtual spaces to the
                // thing we're adding.
                var editorOperations = _editorOperationsFactoryService.GetEditorOperations(this.TextView);
                var whitespace = editorOperations.GetWhitespaceForVirtualSpace(virtualCaretPoint);
                return whitespace + newText;
            }

            return newText;
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:21,代码来源:Controller_Commit.cs


示例18: TextChange

        public TextChange(TextChange change, ITextProvider newTextProvider)
            : this()
        {
            this.Combine(change);

            ITextSnapshotProvider newSnapshotProvider = newTextProvider as ITextSnapshotProvider;
            ITextSnapshotProvider changeNewSnapshotProvider = change.NewTextProvider as ITextSnapshotProvider;

            if ((newSnapshotProvider != null) && (changeNewSnapshotProvider != null))
            {
                ITextSnapshot changeNewSnapshot = changeNewSnapshotProvider.Snapshot;
                ITextSnapshot newSnapshot = newSnapshotProvider.Snapshot;

                if (changeNewSnapshot.Version.ReiteratedVersionNumber != newSnapshot.Version.ReiteratedVersionNumber)
                {
                    SnapshotSpan changeNewSpan = change.NewRange.ToSnapshotSpan(changeNewSnapshot);
                    Span? oldChangedSpan;
                    Span? newChangedSpan;

                    if (changeNewSnapshot.Version.GetChangedExtent(newSnapshot.Version, out oldChangedSpan, out newChangedSpan))
                    {
                        int start = Math.Min(oldChangedSpan.Value.Start, change.NewRange.Start);
                        int end = Math.Max(oldChangedSpan.Value.End, change.NewRange.End);

                        changeNewSpan = new SnapshotSpan(changeNewSnapshot, Span.FromBounds(start, end));
                    }

                    SnapshotSpan newSpan = changeNewSpan.TranslateTo(newSnapshot, SpanTrackingMode.EdgeInclusive);

                    NewRange = new TextRange(newSpan.Start.Position, newSpan.Length);
                }
            }

            NewTextProvider = newTextProvider;
            Version = NewTextProvider.Version;
        }
开发者ID:Microsoft,项目名称:RTVS,代码行数:36,代码来源:TextChange.cs


示例19: RemovePartialFromClassWithIncorrectSpan

 [Fact]//(Skip = "Bug")]
 public void RemovePartialFromClassWithIncorrectSpan()
 {
     var test = @"partial class C{}";
     var resultString = "class C{}";
     var startTree = SyntaxTree.Parse(test);
     var finalString = startTree.GetCompilationUnitRoot().ToString();
     var incrementalChange = new TextChange(startTree.Text, SourceText.From(resultString), new TextChangeRange[] { new TextChangeRange(new TextSpan(0, 7), 0) }); // NOTE: The string length here is a bit too short for the change
     var newTree = startTree.WithChange(incrementalChange);
     var output = newTree.GetCompilationUnitRoot().ToString();
     Assert.Equal(output, resultString);
 }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:12,代码来源:IncrementalParsingTests.cs


示例20: DontReuseLambdaParameterAsMethodParameter

        public void DontReuseLambdaParameterAsMethodParameter()
        {
            var items = new string[]
            {
                "a b.c*/ d => {e(f =>",
                "/*",
            };

            var oldText = SourceText.From(items[0]);
            var oldTree = SyntaxFactory.ParseSyntaxTree(oldText); // f is a simple lambda parameter

            var change = new TextChange(new TextSpan(0, 0), items[1]); // Prepend
            var newText = oldText.WithChanges(change); // f is a method decl parameter

            var incrTree = oldTree.WithChangedText(newText);
            var fullTree = SyntaxFactory.ParseSyntaxTree(newText);

            Assert.Equal(
                fullTree.GetDiagnostics().Select(d => d.ToString()),
                incrTree.GetDiagnostics().Select(d => d.ToString()));

            WalkTreeAndVerify(incrTree.GetRoot(), fullTree.GetRoot());
        }
开发者ID:XieShuquan,项目名称:roslyn,代码行数:23,代码来源:IncrementalParsingTests.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# TextChangedEventArgs类代码示例发布时间:2022-05-24
下一篇:
C# TextBuffer类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap