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 Jun 25, 2019
1 parent 6633abe commit 1c00156
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 (suggestionF:ErrorLogger.Suggestions) (idText:string) =
let FilterPredictions (suggestionF:ErrorLogger.Suggestions) (idText:string) =
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 @@ -50,7 +52,7 @@ let FilterPredictions (suggestionF:ErrorLogger.Suggestions) (idText:string) =
// 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 1c00156

Please sign in to comment.