提交 290b0151 编写于 作者: C CyrusNajmabadi

Fix index of pattern match.

上级 2457a338
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
......@@ -14,7 +15,6 @@
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
using System;
namespace Microsoft.CodeAnalysis.CSharp.Completion.Providers
{
......
......@@ -78,11 +78,13 @@ public bool MatchesPattern(string text, string pattern, CultureInfo culture)
var lastDotIndex = completionItemText.LastIndexOf('.');
if (lastDotIndex >= 0)
{
var textAfterLastDot = completionItemText.Substring(lastDotIndex + 1);
var afterDotPosition = lastDotIndex + 1;
var textAfterLastDot = completionItemText.Substring(afterDotPosition);
var match = GetMatchWorker(textAfterLastDot, pattern, includeMatchSpans, culture);
if (match != null)
{
return match;
return AdjustMatchedSpans(match.Value, afterDotPosition);
}
}
......@@ -91,6 +93,11 @@ public bool MatchesPattern(string text, string pattern, CultureInfo culture)
return GetMatchWorker(completionItemText, pattern, includeMatchSpans, culture);
}
private PatternMatch? AdjustMatchedSpans(PatternMatch value, int offset)
=> value.MatchedSpans.IsDefaultOrEmpty
? value
: value.WithMatchedSpans(value.MatchedSpans.SelectAsArray(s => new TextSpan(s.Start + offset, s.Length)));
private PatternMatch? GetMatchWorker(
string completionItemText, string pattern,
bool includeMatchSpans, CultureInfo culture)
......
......@@ -64,10 +64,11 @@ internal struct PatternMatch : IComparable<PatternMatch>
}
}
public PatternMatch WithMatchedSpans(ImmutableArray<TextSpan> matchedSpans)
=> new PatternMatch(Kind, _punctuationStripped, IsCaseSensitive, matchedSpans, CamelCaseWeight);
public int CompareTo(PatternMatch other)
{
return CompareTo(other, ignoreCase: false);
}
=> CompareTo(other, ignoreCase: false);
public int CompareTo(PatternMatch other, bool ignoreCase)
{
......@@ -109,9 +110,7 @@ private static int CompareCase(PatternMatch result1, PatternMatch result2, bool
}
private static int CompareType(PatternMatch result1, PatternMatch result2)
{
return result1.Kind - result2.Kind;
}
=> result1.Kind - result2.Kind;
private static int CompareCamelCase(PatternMatch result1, PatternMatch result2)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册