本文整理汇总了C#中ITextSnapshot.AsText方法的典型用法代码示例。如果您正苦于以下问题:C# ITextSnapshot.AsText方法的具体用法?C# ITextSnapshot.AsText怎么用?C# ITextSnapshot.AsText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITextSnapshot
的用法示例。
在下文中一共展示了ITextSnapshot.AsText方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DetermineNewDocumentAsync
private async Task<Document> DetermineNewDocumentAsync(MemberInsertionCompletionItem completionItem, ITextSnapshot textSnapshot, CancellationToken cancellationToken)
{
// The span we're going to replace
var line = textSnapshot.GetLineFromLineNumber(completionItem.Line);
var sourceText = textSnapshot.AsText();
var document = sourceText.GetOpenDocumentInCurrentContextWithChanges();
Contract.ThrowIfNull(document);
// Annotate the line we care about so we can find it after adding usings
var tree = document.GetSyntaxTreeAsync(cancellationToken).WaitAndGetResult(cancellationToken);
var token = GetToken(completionItem, tree, cancellationToken);
var annotatedRoot = tree.GetRoot(cancellationToken).ReplaceToken(token, token.WithAdditionalAnnotations(_otherAnnotation));
document = document.WithSyntaxRoot(annotatedRoot);
var memberContainingDocument = await GenerateMemberAndUsingsAsync(document, completionItem, line, cancellationToken).ConfigureAwait(false);
var insertionRoot = PrepareTreeForMemberInsertion(memberContainingDocument, cancellationToken);
var insertionText = GenerateInsertionText(memberContainingDocument, cancellationToken);
var destinationSpan = ComputeDestinationSpan(insertionRoot, insertionText);
var finalText = insertionRoot.GetText(sourceText.Encoding).Replace(destinationSpan, insertionText.Trim());
document = document.WithText(finalText);
var newRoot = document.GetSyntaxRootAsync(cancellationToken).WaitAndGetResult(cancellationToken);
var declaration = GetSyntax(newRoot.FindToken(destinationSpan.End));
document = document.WithSyntaxRoot(newRoot.ReplaceNode(declaration, declaration.WithAdditionalAnnotations(_annotation)));
return Formatter.FormatAsync(document, _annotation, cancellationToken: cancellationToken).WaitAndGetResult(cancellationToken);
}
示例2: Create
public static CompletionInfo? Create(ITextSnapshot snapshot) {
if (snapshot == null)
throw new ArgumentNullException(nameof(snapshot));
var sourceText = snapshot.AsText();
var document = sourceText.GetOpenDocumentInCurrentContextWithChanges();
if (document == null)
return null;
var completionService = CompletionService.GetService(document);
if (completionService == null)
return null;
return new CompletionInfo(completionService, document, sourceText, snapshot);
}
示例3: GetOpenDocumentInCurrentContextWithChanges
public Document GetOpenDocumentInCurrentContextWithChanges(ITextSnapshot snapshot)
{
var text = snapshot.AsText();
return text.GetOpenDocumentInCurrentContextWithChanges();
}
示例4: GetDocumentAsync
public Task<Document> GetDocumentAsync(ITextSnapshot snapshot, CancellationToken cancellationToken)
{
AssertIsBackground();
return snapshot.AsText().GetDocumentWithFrozenPartialSemanticsAsync(cancellationToken);
}