提交 1ea0b37d 编写于 作者: B BalajiKris

Brace matching has code to check for matching spans left of the caret - to...

Brace matching has code to check for matching spans left of the caret - to deal with cases like {$$()}. We need to protect against negative numbers when caret is at position 0. (changeset 1405386)
上级 96610b95
......@@ -26,6 +26,12 @@ internal class BraceMatchingService : IBraceMatchingService
public async Task<BraceMatchingResult?> GetMatchingBracesAsync(Document document, int position, CancellationToken cancellationToken)
{
var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
if (position < 0 || position > text.Length)
{
throw new ArgumentException(nameof(position));
}
var matchers = _braceMatchers.Where(b => b.Metadata.Language == document.Project.Language);
foreach (var matcher in matchers)
{
......
......@@ -18,7 +18,13 @@ internal static class IBraceMatchingServiceExtensions
var braces1 = await service.GetMatchingBracesAsync(document, position, cancellationToken).ConfigureAwait(false);
// These are the matching spans when checking the token to the left of the position.
var braces2 = await service.GetMatchingBracesAsync(document, position - 1, cancellationToken).ConfigureAwait(false);
BraceMatchingResult? braces2 = null;
// Ensure caret is valid at left of position.
if (position > 0)
{
braces2 = await service.GetMatchingBracesAsync(document, position - 1, cancellationToken).ConfigureAwait(false);
}
// Favor matches where the position is on the outside boundary of the braces. i.e. if we
// have: {^()}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册