code: func (i *ProviderInstaller) findClosestProtocolCompatibleVersion(versions []*response.TerraformProviderVersion) (*response.TerraformProviderVersion, error) {
  	// Loop through all the provider versions to find the earliest and latest
  	// versions that match the installer protocol to then select the closest of the two
  	var latest, earliest *response.TerraformProviderVersion
  	for _, version := range versions {
  		// Prereleases are filtered and will not be suggested
  		v, err := VersionStr(version.Version).Parse()
  		if err != nil || v.IsPrerelease() {
  			continue
  		}
  
  		if err := i.checkPluginProtocol(version); err == nil {
  			if earliest == nil {
  				// Found the first provider version with compatible protocol
  				earliest = version
  			}
  			// Update the latest protocol compatible version
  			latest = version
  		}
  	}
  	if earliest == nil {
  		// No compatible protocol was found for any version
  		return nil, ErrorNoVersionCompatible
  	}
  
  	// Convert protocols to comparable types
  	protoString := strconv.Itoa(int(i.PluginProtocolVersion))
  	protocolVersion, err := VersionStr(protoString).Parse()
  	if err != nil {
  		return nil, fmt.Errorf("invalid plugin protocol version: %q", i.PluginProtocolVersion)
  	}
  
  	earliestVersionProtocol, err := VersionStr(earliest.Protocols[0]).Parse()
  	if err != nil {
  		return nil, err
  	}
  
  	// Compare installer protocol version with the first protocol listed of the earliest match
  	// [A, B] where A is assumed the earliest compatible major version of the protocol pair
  	if protocolVersion.NewerThan(earliestVersionProtocol) {
  		// Provider protocols are too old, the closest version is the earliest compatible version
  		return earliest, nil
  	}
  
  	// Provider protocols are too new, the closest version is the latest compatible version
  	return latest, nil
  }
docs: // findClosestProtocolCompatibleVersion searches for the provider version with the closest protocol match.
  // Prerelease versions are filtered.