提交 7b41f630 编写于 作者: K Kevin Pilch 提交者: GitHub

Merge pull request #16189 from diryboy/eofSpan2

Fix block comments editing when caret on EOF
......@@ -160,7 +160,8 @@ private static string GetPaddingOrIndentation(ITextSnapshotLine currentLine, int
private static bool IsCaretInsideBlockCommentSyntax(SnapshotPoint caretPosition)
{
var document = caretPosition.Snapshot.GetOpenDocumentInCurrentContextWithChanges();
var snapshot = caretPosition.Snapshot;
var document = snapshot.GetOpenDocumentInCurrentContextWithChanges();
if (document == null)
{
return false;
......@@ -170,7 +171,41 @@ private static bool IsCaretInsideBlockCommentSyntax(SnapshotPoint caretPosition)
var trivia = syntaxTree.FindTriviaAndAdjustForEndOfFile(caretPosition, CancellationToken.None);
var isBlockComment = trivia.IsKind(SyntaxKind.MultiLineCommentTrivia) || trivia.IsKind(SyntaxKind.MultiLineDocumentationCommentTrivia);
return isBlockComment && trivia.FullSpan.Start < caretPosition;
if (isBlockComment)
{
var span = trivia.FullSpan;
if (span.Start < caretPosition && caretPosition < span.End)
{
return true;
}
// FindTriviaAndAdjustForEndOfFile always returns something if position is EOF,
// whether or not the result includes the position.
// And the SyntaxTrivia for block comments always ends on EOF, closed or not.
// So we need to handle
// /**/|EOF
// and
// /* |EOF
if (caretPosition == snapshot.Length)
{
if (span.Length < "/**/".Length)
{
return true;
}
// If the block comment is not closed, SyntaxTrivia contains diagnostics
// So when the SyntaxTrivia is clean, the block comment should be closed
if (!trivia.ContainsDiagnostics)
{
return false;
}
var textBeforeCaret = snapshot.GetText(caretPosition.Position - 2, 2);
return textBeforeCaret != "*/";
}
}
return false;
}
}
}
\ No newline at end of file
}
......@@ -69,6 +69,42 @@ public async Task EdgeCase3()
await VerifyAsync(code, expected);
}
[WorkItem(16128, "https://github.com/dotnet/roslyn/issues/16128")]
[WpfFact, Trait(Traits.Feature, Traits.Features.BlockCommentEditing)]
public async Task EofCase0()
{
var code = @"
/* */$$";
var expected = @"
/* */
$$";
await VerifyAsync(code, expected);
}
[WorkItem(16128, "https://github.com/dotnet/roslyn/issues/16128")]
[WpfFact, Trait(Traits.Feature, Traits.Features.BlockCommentEditing)]
public async Task EofCase1()
{
var code = @"
/*$$";
var expected = @"
/*
* $$";
await VerifyAsync(code, expected);
}
[WorkItem(16128, "https://github.com/dotnet/roslyn/issues/16128")]
[WpfFact, Trait(Traits.Feature, Traits.Features.BlockCommentEditing)]
public async Task EofCase2()
{
var code = @"
/***$$";
var expected = @"
/***
* $$";
await VerifyAsync(code, expected);
}
[WpfFact, Trait(Traits.Feature, Traits.Features.BlockCommentEditing)]
public async Task InsertOnStartLine0()
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册