本文整理汇总了C#中TextChange类的典型用法代码示例。如果您正苦于以下问题:C# TextChange类的具体用法?C# TextChange怎么用?C# TextChange使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TextChange类属于命名空间,在下文中一共展示了TextChange类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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));
}
示例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));
}
示例4: RaiseChangeCompleted
public void RaiseChangeCompleted(TextChange change)
{
var e = ChangeCompleted;
if (e != null)
{
e(this, change);
}
}
示例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));
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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; };
}
示例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);
}
示例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));
}