Skip to content

Commit

Permalink
Mitigate dotnet#6044 and don't call suggestions for small identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Dec 21, 2018
1 parent 0302e63 commit e8a793a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/fsharp/ErrorResolutionHints.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ let maxSuggestions = 5
let minThresholdForSuggestions = 0.7
let highConfidenceThreshold = 0.85
let minStringLengthForThreshold = 3
let minStringLengthForSuggestion = 5

/// We report a candidate if its edit distance is <= the threshold.
/// The threshold is set to about a quarter of the number of characters.
Expand All @@ -24,7 +25,8 @@ let IsInEditDistanceProximity idText suggestion =
editDistance <= threshold

/// Filters predictions based on edit distance to the given unknown identifier.
let FilterPredictions (idText:string) (suggestionF:ErrorLogger.Suggestions) =
let FilterPredictions (idText:string) (suggestionF:ErrorLogger.Suggestions) =
if idText.Length < minStringLengthForSuggestion then [] else // we should not try to suggest all the time when people are typing
let uppercaseText = idText.ToUpperInvariant()
let allSuggestions = suggestionF()

Expand All @@ -49,7 +51,7 @@ let FilterPredictions (idText:string) (suggestionF:ErrorLogger.Suggestions) =
// value as well as to formally squelch the associated compiler
// error/warning (FS1182), we remove such names from the suggestions,
// both to prevent accidental usages as well as to encourage good taste
if IsOperatorName suggestion || suggestion.StartsWithOrdinal("_") then None else
if IsOperatorName suggestion || suggestion.Length < minStringLengthForSuggestion || suggestion.StartsWithOrdinal("_") then None else
let suggestion:string = demangle suggestion
let suggestedText = suggestion.ToUpperInvariant()
let similarity = EditDistance.JaroWinklerDistance uppercaseText suggestedText
Expand Down

0 comments on commit e8a793a

Please sign in to comment.