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


C# ITextSnapshot.AsText方法代码示例

本文整理汇总了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);
        }
开发者ID:Eyas,项目名称:roslyn,代码行数:31,代码来源:AbstractMemberInsertingCompletionProvider.cs

示例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);
		}
开发者ID:manojdjoshi,项目名称:dnSpy,代码行数:12,代码来源:CompletionInfo.cs

示例3: GetOpenDocumentInCurrentContextWithChanges

 public Document GetOpenDocumentInCurrentContextWithChanges(ITextSnapshot snapshot)
 {
     var text = snapshot.AsText();
     return text.GetOpenDocumentInCurrentContextWithChanges();
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:5,代码来源:IDocumentProvider.cs

示例4: GetDocumentAsync

 public Task<Document> GetDocumentAsync(ITextSnapshot snapshot, CancellationToken cancellationToken)
 {
     AssertIsBackground();
     return snapshot.AsText().GetDocumentWithFrozenPartialSemanticsAsync(cancellationToken);
 }
开发者ID:Rickinio,项目名称:roslyn,代码行数:5,代码来源:IDocumentProvider.cs


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