Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8b01462

Browse files
forkiKevinRansom
authored andcommitted
Use the word suggestions and introduce threshold (dotnet#2068)
1 parenta5b21ff commit8b01462

31 files changed

+165
-156
lines changed

‎src/fsharp/CompileOps.fs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ let GetRangeOfError(err:PhasedError) =
156156
| RecursiveUseCheckedAtRuntime(_,_,m)
157157
| LetRecEvaluatedOutOfOrder(_,_,_,m)
158158
| Error(_,m)
159-
|ErrorWithPredictions(_,m,_,_)
159+
|ErrorWithSuggestions(_,m,_,_)
160160
| NumberedError(_,m)
161161
| SyntaxError(_,m)
162162
| InternalError(_,m)
@@ -370,7 +370,7 @@ let GetErrorNumber(err:PhasedError) =
370370
| WrappedError(e,_)-> GetFromException e
371371

372372
| Error((n,_),_)-> n
373-
|ErrorWithPredictions((n,_),_,_,_)-> n
373+
|ErrorWithSuggestions((n,_),_,_,_)-> n
374374
| Failure_->192
375375
| NumberedError((n,_),_)-> n
376376
| IllegalFileNameChar(fileName,invalidChar)-> fst(FSComp.SR.buildUnexpectedFileNameCharacter(fileName,string invalidChar))
@@ -389,7 +389,7 @@ let GetWarningLevel err =
389389
| DefensiveCopyWarning_
390390
| FullAbstraction_->5
391391
| NumberedError((n,_),_)
392-
|ErrorWithPredictions((n,_),_,_,_)
392+
|ErrorWithSuggestions((n,_),_,_,_)
393393
| Error((n,_),_)->
394394
// 1178,tcNoComparisonNeeded1,"The struct, record or union type '%s' is not structurally comparable because the type parameter %s does not satisfy the 'comparison' constraint. Consider adding the 'NoComparison' attribute to this type to clarify that the type is not comparable"
395395
// 1178,tcNoComparisonNeeded2,"The struct, record or union type '%s' is not structurally comparable because the type '%s' does not satisfy the 'comparison' constraint. Consider adding the 'NoComparison' attribute to this type to clarify that the type is not comparable"
@@ -777,9 +777,9 @@ let OutputPhasedErrorR errorStyle (os:System.Text.StringBuilder) (err:PhasedErro
777777
os.Append(Duplicate1E().Format(DecompileOpName s))|> ignore
778778
else
779779
os.Append(Duplicate2E().Format k(DecompileOpName s))|> ignore
780-
| UndefinedName(_,k,id,predictionsF)->
780+
| UndefinedName(_,k,id,suggestionsF)->
781781
os.Append(k(DecompileOpName id.idText))|> ignore
782-
letfiltered= ErrorResolutionHints.FilterPredictions id.idTextpredictionsF
782+
letfiltered= ErrorResolutionHints.FilterPredictions id.idTextsuggestionsF
783783
if List.isEmpty filtered|>notthen
784784
os.Append(ErrorResolutionHints.FormatPredictions errorStyle DecompileOpName filtered)|> ignore
785785

@@ -1268,9 +1268,9 @@ let OutputPhasedErrorR errorStyle (os:System.Text.StringBuilder) (err:PhasedErro
12681268
os.Append(NonUniqueInferredAbstractSlot3E().Format t1 t2)|> ignore
12691269
os.Append(NonUniqueInferredAbstractSlot4E().Format)|> ignore
12701270
| Error((_,s),_)-> os.Append(s)|> ignore
1271-
|ErrorWithPredictions((_,s),_,idText,predictionsF)->
1271+
|ErrorWithSuggestions((_,s),_,idText,suggestionF)->
12721272
os.Append(DecompileOpName s)|> ignore
1273-
letfiltered= ErrorResolutionHints.FilterPredictions idTextpredictionsF
1273+
letfiltered= ErrorResolutionHints.FilterPredictions idTextsuggestionF
12741274
if List.isEmpty filtered|>notthen
12751275
os.Append(ErrorResolutionHints.FormatPredictions errorStyle DecompileOpName filtered)|> ignore
12761276
| NumberedError((_,s),_)-> os.Append(s)|> ignore

‎src/fsharp/ConstraintSolver.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2030,7 +2030,7 @@ and ReportNoCandidatesError (csenv:ConstraintSolverEnv) (nUnnamedCallerArgs,nNam
20302030
|> List.map(fun p-> p.Name.Replace("@",""))
20312031
|> Set.ofList
20322032

2033-
ErrorWithPredictions((msgNum,FSComp.SR.csCtorHasNoArgumentOrReturnProperty(methodName, id.idText, msgText)),id.idRange,id.idText,predictFields)
2033+
ErrorWithSuggestions((msgNum,FSComp.SR.csCtorHasNoArgumentOrReturnProperty(methodName, id.idText, msgText)),id.idRange,id.idText,predictFields)
20342034
else
20352035
Error((msgNum,FSComp.SR.csMemberHasNoArgumentOrReturnProperty(methodName, id.idText, msgText)),id.idRange)
20362036
|[]-> Error((msgNum,msgText),m)

‎src/fsharp/ErrorLogger.fs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ let rec findOriginalException err =
4646
|_-> err
4747

4848

49-
typePredictions= unit-> Set<string>
49+
typeSuggestions= unit-> Set<string>
5050

51-
letNoPredictions:Predictions=fun()-> Set.empty
51+
letNoSuggestions:Suggestions=fun()-> Set.empty
5252

5353
/// Thrown when we stop processing the F# Interactive entry or #load.
5454
exception StopProcessingExnofexnoption
@@ -69,10 +69,10 @@ exception Error of (int * string) * range with // int is e.g. 191 in FS0191 /
6969
|_->"impossible"
7070

7171

72-
exceptionErrorWithPredictionsof(int*string)*range*string*Predictionswith// int is e.g. 191 in FS0191
72+
exceptionErrorWithSuggestionsof(int*string)*range*string*Suggestionswith// int is e.g. 191 in FS0191
7373
overridethis.Message=
7474
match this:> exnwith
75-
|ErrorWithPredictions((_,msg),_,_,_)-> msg
75+
|ErrorWithSuggestions((_,msg),_,_,_)-> msg
7676
|_->"impossible"
7777

7878
exception InternalErrorofstring*range

‎src/fsharp/ErrorResolutionHints.fs‎

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,46 @@
33
/// Functions to format error message details
44
moduleinternalMicrosoft.FSharp.Compiler.ErrorResolutionHints
55

6-
/// Filters predictions based on edit distance to an unknown identifier.
7-
letFilterPredictions(unknownIdent:string)(predictionsF:ErrorLogger.Predictions)=
8-
let rectake n predictions=
9-
predictions
10-
|> Seq.mapi(fun i x-> i,x)
11-
|> Seq.takeWhile(fun(i,_)-> i< n)
12-
|> Seq.map snd
13-
|> Seq.toList
6+
letmaxSuggestions=5
7+
8+
letminStringLengthForThreshold=3
149

10+
letthresholdForSuggestions=0.7
11+
12+
/// Filters predictions based on edit distance to an unknown identifier.
13+
letFilterPredictions(unknownIdent:string)(predictionsF:ErrorLogger.Suggestions)=
1514
letunknownIdent= unknownIdent.ToUpperInvariant()
15+
letuseThreshold= unknownIdent.Length>= minStringLengthForThreshold
1616
predictionsF()
17-
|> Seq.sortByDescending(fun p-> Internal.Utilities.EditDistance.JaroWinklerDistance unknownIdent(p.ToUpperInvariant()))
18-
|> take5
17+
|> Seq.choose(fun p->
18+
letsimilarity= Internal.Utilities.EditDistance.JaroWinklerDistance unknownIdent(p.ToUpperInvariant())
19+
ifnot useThreshold|| similarity>= thresholdForSuggestionsthen
20+
Some(similarity,p)
21+
else
22+
None
23+
)
24+
|> Seq.sortByDescending fst
25+
|> Seq.mapi(fun i x-> i,x)
26+
|> Seq.takeWhile(fun(i,_)-> i< maxSuggestions)
27+
|> Seq.map snd
28+
|> Seq.toList
1929

20-
letFormatPredictions errorStyle normalizeF predictions=
30+
letFormatPredictions errorStyle normalizeF(predictions:(float* string)list)=
2131
match predictionswith
2232
|[]-> System.String.Empty
2333
|_->
2434
match errorStylewith
2535
| ErrorLogger.ErrorStyle.VSErrors->
2636
letpredictionText=
2737
predictions
28-
|> List.map normalizeF
38+
|> List.map(snd>>normalizeF)
2939
|> String.concat","
3040

3141
""+ FSComp.SR.undefinedNameRecordLabelDetails()+""+ predictionText
3242
|_->
3343
letpredictionText=
3444
predictions
35-
|> List.map normalizeF
45+
|> List.map(snd>>normalizeF)
3646
|> Seq.map(sprintf"%s%s" System.Environment.NewLine)
3747
|> String.concat""
3848

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp