提交 76fc0e8c 编写于 作者: C Cyrus Najmabadi

Use NRT

上级 5a8eb12f
......@@ -2,9 +2,12 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.ComponentModel.Composition;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Editor.Shared.Extensions;
......@@ -88,7 +91,7 @@ private Span GetReplacementSpan(SnapshotPoint caretPosition)
return Span.FromBounds(start, end);
}
private string GetTextToInsert(SnapshotPoint caretPosition)
private string? GetTextToInsert(SnapshotPoint caretPosition)
{
var currentLine = caretPosition.GetContainingLine();
var firstNonWhitespacePosition = currentLine.GetFirstNonWhitespacePosition() ?? -1;
......@@ -128,7 +131,7 @@ private string GetTextToInsert(SnapshotPoint caretPosition)
var newLine = options.GetOption(FormattingOptions.NewLine, LanguageNames.CSharp);
return newLine + exteriorText;
string GetExteriorText()
string? GetExteriorText()
{
if (startsWithBlockCommentStartString)
{
......@@ -231,7 +234,8 @@ private static bool BlockCommentEndsRightAfterCaret(SnapshotPoint caretPosition)
}
public static bool IsCaretInsideBlockCommentSyntax(
SnapshotPoint caretPosition, out Document document, out SyntaxTrivia trivia)
SnapshotPoint caretPosition,
[NotNullWhen(true)] out Document? document, out SyntaxTrivia trivia)
{
trivia = default;
......@@ -240,7 +244,7 @@ private static bool BlockCommentEndsRightAfterCaret(SnapshotPoint caretPosition)
if (document == null)
return false;
var syntaxTree = document.GetSyntaxTreeSynchronously(CancellationToken.None);
var syntaxTree = document.GetRequiredSyntaxTreeSynchronously(CancellationToken.None);
trivia = syntaxTree.FindTriviaAndAdjustForEndOfFile(caretPosition, CancellationToken.None);
var isBlockComment = trivia.IsKind(SyntaxKind.MultiLineCommentTrivia) || trivia.IsKind(SyntaxKind.MultiLineDocumentationCommentTrivia);
......
......@@ -41,6 +41,12 @@ public static async Task<SyntaxTree> GetRequiredSyntaxTreeAsync(this Document do
return syntaxTree ?? throw new InvalidOperationException(string.Format(WorkspaceExtensionsResources.SyntaxTree_is_required_to_accomplish_the_task_but_is_not_supported_by_document_0, document.Name));
}
public static SyntaxTree GetRequiredSyntaxTreeSynchronously(this Document document, CancellationToken cancellationToken)
{
var syntaxTree = document.GetSyntaxTreeSynchronously(cancellationToken);
return syntaxTree ?? throw new InvalidOperationException(string.Format(WorkspaceExtensionsResources.SyntaxTree_is_required_to_accomplish_the_task_but_is_not_supported_by_document_0, document.Name));
}
public static async Task<SyntaxNode> GetRequiredSyntaxRootAsync(this Document document, CancellationToken cancellationToken)
{
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册