@@ -13,11 +13,10 @@ open System.Globalization
1313
1414open Microsoft.CodeAnalysis
1515open Microsoft.CodeAnalysis .Text
16- open Microsoft.CodeAnalysis .PatternMatching
1716open Microsoft.CodeAnalysis .ExternalAccess .FSharp .Navigation
1817open Microsoft.CodeAnalysis .ExternalAccess .FSharp .NavigateTo
18+ open Microsoft.VisualStudio .Text .PatternMatching
1919
20- open FSharp.Compiler .CodeAnalysis
2120open FSharp.Compiler .EditorServices
2221open FSharp.Compiler .Syntax
2322
@@ -172,6 +171,7 @@ module private Utils =
172171type internal FSharpNavigateToSearchService
173172 [<ImportingConstructor>]
174173 (
174+ patternMatcherFactory: IPatternMatcherFactory
175175 ) =
176176
177177 let kindsProvided = ImmutableHashSet.Create( FSharpNavigateToItemKind.Module, FSharpNavigateToItemKind.Class, FSharpNavigateToItemKind.Field, FSharpNavigateToItemKind.Property, FSharpNavigateToItemKind.Method, FSharpNavigateToItemKind.Enum, FSharpNavigateToItemKind.EnumItem) :> IImmutableSet< string>
@@ -229,9 +229,13 @@ type internal FSharpNavigateToSearchService
229229 | PatternMatchKind.Exact -> FSharpNavigateToMatchKind.Exact
230230 | PatternMatchKind.Prefix -> FSharpNavigateToMatchKind.Prefix
231231 | PatternMatchKind.Substring -> FSharpNavigateToMatchKind.Substring
232- | PatternMatchKind.CamelCase -> FSharpNavigateToMatchKind.Regular
233- | PatternMatchKind.Fuzzy -> FSharpNavigateToMatchKind.Regular
234- | _ -> FSharpNavigateToMatchKind.Regular
232+ | PatternMatchKind.CamelCaseExact -> FSharpNavigateToMatchKind.CamelCaseExact
233+ | PatternMatchKind.CamelCasePrefix -> FSharpNavigateToMatchKind.CamelCasePrefix
234+ | PatternMatchKind.CamelCaseNonContiguousPrefix -> FSharpNavigateToMatchKind.CamelCaseNonContiguousPrefix
235+ | PatternMatchKind.CamelCaseSubstring -> FSharpNavigateToMatchKind.CamelCaseSubstring
236+ | PatternMatchKind.CamelCaseNonContiguousSubstring -> FSharpNavigateToMatchKind.CamelCaseNonContiguousSubstring
237+ | PatternMatchKind.Fuzzy -> FSharpNavigateToMatchKind.Fuzzy
238+ | _ -> FSharpNavigateToMatchKind.Fuzzy
235239
236240 interface IFSharpNavigateToSearchService with
237241 member _.SearchProjectAsync ( project , _priorityDocuments , searchPattern , kinds , cancellationToken ) : Task < ImmutableArray < FSharpNavigateToSearchResult >> =
@@ -250,14 +254,18 @@ type internal FSharpNavigateToSearchService
250254 |> Array.filter ( fun x -> x.Name.Length = 1 && String.Equals( x.Name, searchPattern, StringComparison.InvariantCultureIgnoreCase))
251255 else
252256 [| yield ! items |> Array.map ( fun items -> items.Find( searchPattern)) |> Array.concat
253- use patternMatcher = new PatternMatcher( searchPattern, allowFuzzyMatching = true )
257+ let patternMatcherOptions = PatternMatcherCreationOptions(
258+ cultureInfo = CultureInfo.CurrentUICulture,
259+ flags = PatternMatcherCreationFlags.AllowFuzzyMatching
260+ )
261+ let patternMatcher = patternMatcherFactory.CreatePatternMatcher( searchPattern, patternMatcherOptions)
254262 yield ! items
255263 |> Array.collect ( fun item -> item.AllItems)
256- |> Array.Parallel.collect ( fun x ->
257- patternMatcher.GetMatches ( x.LogicalName)
258- |> Seq.map ( fun pm ->
259- NavigateToSearchResult ( x , patternMatchKindToNavigateToMatchKind pm.Kind ) :> FSharpNavigateToSearchResult )
260- |> Seq.toArray ) |]
264+ |> Array.Parallel.choose ( fun x ->
265+ patternMatcher.TryMatch ( x.LogicalName)
266+ |> Option.ofNullable
267+ |> Option.map ( fun pm ->
268+ NavigateToSearchResult ( x , patternMatchKindToNavigateToMatchKind pm.Kind ) :> FSharpNavigateToSearchResult ) ) |]
261269
262270 return items |> Array.distinctBy ( fun x -> x.NavigableItem.Document.Id, x.NavigableItem.SourceSpan)
263271 }
0 commit comments