forked from dotnet/fsharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathErrorResolutionHints.fs
More file actions
29 lines (25 loc) · 1.1 KB
/
Copy pathErrorResolutionHints.fs
File metadata and controls
29 lines (25 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
/// Functions to format error message details
module internal Microsoft.FSharp.Compiler.ErrorResolutionHints
/// Filters predictions based on edit distance to an unknown identifier.
let FilterPredictions unknownIdent allPredictions =
let rec take n predictions =
predictions
|> Seq.mapi (fun i x -> i,x)
|> Seq.takeWhile (fun (i,_) -> i < n)
|> Seq.map snd
|> Seq.toList
allPredictions
|> Seq.toList
|> List.distinct
|> List.sortBy (fun s -> Internal.Utilities.EditDistance.CalcEditDistance(unknownIdent,s))
|> take 5
let FormatPredictions predictions =
match predictions with
| [] -> System.String.Empty
| _ ->
let predictionText =
predictions
|> Seq.map (sprintf "%s %s" System.Environment.NewLine)
|> String.concat ""
System.Environment.NewLine + FSComp.SR.undefinedNameRecordLabelDetails() + predictionText