@@ -11,13 +11,13 @@ import (
1111 "sync"
1212 "time"
1313
14- "github.com/agext/levenshtein"
1514 "github.com/hashicorp/hcl/v2"
1615 "github.com/zclconf/go-cty/cty"
1716
1817 "github.com/hashicorp/terraform/internal/addrs"
1918 "github.com/hashicorp/terraform/internal/configs"
2019 "github.com/hashicorp/terraform/internal/configs/configschema"
20+ "github.com/hashicorp/terraform/internal/didyoumean"
2121 "github.com/hashicorp/terraform/internal/instances"
2222 "github.com/hashicorp/terraform/internal/lang"
2323 "github.com/hashicorp/terraform/internal/lang/marks"
@@ -229,7 +229,7 @@ func (d *evaluationStateData) GetInputVariable(addr addrs.InputVariable, rng tfd
229229 for k := range moduleConfig .Module .Variables {
230230 suggestions = append (suggestions , k )
231231 }
232- suggestion := nameSuggestion (addr .Name , suggestions )
232+ suggestion := didyoumean . NameSuggestion (addr .Name , suggestions )
233233 if suggestion != "" {
234234 suggestion = fmt .Sprintf (" Did you mean %q?" , suggestion )
235235 } else {
@@ -325,7 +325,7 @@ func (d *evaluationStateData) GetLocalValue(addr addrs.LocalValue, rng tfdiags.S
325325 for k := range moduleConfig .Module .Locals {
326326 suggestions = append (suggestions , k )
327327 }
328- suggestion := nameSuggestion (addr .Name , suggestions )
328+ suggestion := didyoumean . NameSuggestion (addr .Name , suggestions )
329329 if suggestion != "" {
330330 suggestion = fmt .Sprintf (" Did you mean %q?" , suggestion )
331331 }
@@ -624,7 +624,7 @@ func (d *evaluationStateData) GetPathAttr(addr addrs.PathAttr, rng tfdiags.Sourc
624624 return cty .StringVal (filepath .ToSlash (sourceDir )), diags
625625
626626 default :
627- suggestion := nameSuggestion (addr .Name , []string {"cwd" , "module" , "root" })
627+ suggestion := didyoumean . NameSuggestion (addr .Name , []string {"cwd" , "module" , "root" })
628628 if suggestion != "" {
629629 suggestion = fmt .Sprintf (" Did you mean %q?" , suggestion )
630630 }
@@ -940,25 +940,6 @@ func (d *evaluationStateData) GetTerraformAttr(addr addrs.TerraformAttr, rng tfd
940940 }
941941}
942942
943- // nameSuggestion tries to find a name from the given slice of suggested names
944- // that is close to the given name and returns it if found. If no suggestion
945- // is close enough, returns the empty string.
946- //
947- // The suggestions are tried in order, so earlier suggestions take precedence
948- // if the given string is similar to two or more suggestions.
949- //
950- // This function is intended to be used with a relatively-small number of
951- // suggestions. It's not optimized for hundreds or thousands of them.
952- func nameSuggestion (given string , suggestions []string ) string {
953- for _ , suggestion := range suggestions {
954- dist := levenshtein .Distance (given , suggestion , nil )
955- if dist < 3 { // threshold determined experimentally
956- return suggestion
957- }
958- }
959- return ""
960- }
961-
962943// moduleDisplayAddr returns a string describing the given module instance
963944// address that is appropriate for returning to users in situations where the
964945// root module is possible. Specifically, it returns "the root module" if the
0 commit comments