Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/fsharp/CompileOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -742,8 +742,12 @@ let OutputPhasedErrorR (os:System.Text.StringBuilder) (err:PhasedError) =
os.Append(Duplicate1E().Format (DecompileOpName s)) |> ignore
else
os.Append(Duplicate2E().Format k (DecompileOpName s)) |> ignore
| UndefinedName(_,k,id,_) ->
| UndefinedName(_,k,id,predictions) ->
os.Append(k (DecompileOpName id.idText)) |> ignore
if Set.isEmpty predictions |> not then
let filtered = ErrorResolutionHints.FilterPredictions id.idText predictions
os.Append(ErrorResolutionHints.FormatPredictions filtered) |> ignore

| InternalUndefinedItemRef(f,smr,ccuName,s) ->
let _, errs = f(smr, ccuName, s)
os.Append(errs) |> ignore
Expand Down
29 changes: 29 additions & 0 deletions src/fsharp/ErrorResolutionHints.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
5 changes: 4 additions & 1 deletion src/fsharp/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ undefinedNameValueOfConstructor,"The value or constructor '%s' is not defined"
undefinedNameValueNamespaceTypeOrModule,"The value, namespace, type or module '%s' is not defined"
undefinedNameConstructorModuleOrNamespace,"The constructor, module or namespace '%s' is not defined"
undefinedNameType,"The type '%s' is not defined"
undefinedNameTypeIn,"The type '%s' is not defined in '%s'."
undefinedNameRecordLabelOrNamespace,"The record label or namespace '%s' is not defined"
undefinedNameRecordLabel,"The record label '%s' is not defined"
undefinedNameRecordLabel,"The record label '%s' is not defined."
undefinedNameRecordLabelDetails,"Maybe you want one of the following:"
undefinedNameTypeParameter,"The type parameter '%s' is not defined"
undefinedNamePatternDiscriminator,"The pattern discriminator '%s' is not defined"
missingElseBranch,"The 'if' expression is missing an 'else' branch. The 'then' branch has type '%s'. Because 'if' is an expression, and not a statement, add an 'else' branch which returns a value of the same type."
Expand Down Expand Up @@ -951,6 +953,7 @@ lexfltSeparatorTokensOfPatternMatchMisaligned,"The '|' tokens separating rules o
1127,nrIsNotConstructorOrLiteral,"This is not a constructor or literal, or a constructor is being used incorrectly"
1128,nrUnexpectedEmptyLongId,"Unexpected empty long identifier"
1129,nrTypeDoesNotContainSuchField,"The type '%s' does not contain a field '%s'"
1129,nrRecordDoesNotContainSuchLabel,"The record type '%s' does not contain a label '%s'."
1130,nrInvalidFieldLabel,"Invalid field label"
1132,nrInvalidExpression,"Invalid expression '%s'"
1133,nrNoConstructorsAvailableForType,"No constructors are available for the type '%s'"
Expand Down
6 changes: 6 additions & 0 deletions src/fsharp/FSharp.Compiler-proto/FSharp.Compiler-proto.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@
<Compile Include="..\..\utils\HashMultiMap.fs">
<Link>HashMultiMap.fs</Link>
</Compile>
<Compile Include="..\..\utils\EditDistance.fs">
<Link>Utilities\EditDistance.fs</Link>
</Compile>
<Compile Include="..\..\utils\TaggedCollections.fsi">
<Link>TaggedCollections.fsi</Link>
</Compile>
Expand Down Expand Up @@ -211,6 +214,9 @@
<Compile Include="..\ErrorLogger.fs">
<Link>ErrorLogger.fs</Link>
</Compile>
<Compile Include="..\ErrorResolutionHints.fs">
<Link>ErrorResolutionHints.fs</Link>
</Compile>
<Compile Include="..\InternalCollections.fsi">
<Link>InternalCollections.fsi</Link>
</Compile>
Expand Down
8 changes: 7 additions & 1 deletion src/fsharp/FSharp.Compiler/FSharp.Compiler.fsproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<!-- 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. -->
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
Expand Down Expand Up @@ -84,6 +84,9 @@
<Compile Include="..\..\utils\HashMultiMap.fs">
<Link>Utilities\HashMultiMap.fs</Link>
</Compile>
<Compile Include="..\..\utils\EditDistance.fs">
<Link>Utilities\EditDistance.fs</Link>
</Compile>
<Compile Include="..\..\utils\TaggedCollections.fsi">
<Link>Utilities\TaggedCollections.fsi</Link>
</Compile>
Expand Down Expand Up @@ -159,6 +162,9 @@
<Compile Include="..\ErrorLogger.fs">
<Link>ErrorLogging\ErrorLogger.fs</Link>
</Compile>
<Compile Include="..\ErrorResolutionHints.fs">
<Link>ErrorLogging\ErrorResolutionHints.fs</Link>
</Compile>
<Compile Include="..\ReferenceResolution.fsi">
<Link>ReferenceResolution\ReferenceResolution.fsi</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@
<Compile Include="..\..\utils\HashMultiMap.fs">
<Link>Utilities\HashMultiMap.fs</Link>
</Compile>
<Compile Include="..\..\utils\EditDistance.fs">
<Link>Utilities\EditDistance.fs</Link>
</Compile>
<Compile Include="..\..\utils\TaggedCollections.fsi">
<Link>Utilities\TaggedCollections.fsi</Link>
</Compile>
Expand Down Expand Up @@ -152,6 +155,9 @@
<Compile Include="..\ErrorLogger.fs">
<Link>ErrorLogging\ErrorLogger.fs</Link>
</Compile>
<Compile Include="..\ErrorResolutionHints.fs">
<Link>ErrorLogging\ErrorResolutionHints.fs</Link>
</Compile>
<Compile Include="..\ReferenceResolution.fsi">
<Link>ReferenceResolution\ReferenceResolution.fsi</Link>
</Compile>
Expand Down
Loading