Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate OptionSetInfo, prepare way for new ChoiceInfo function #2235

Merged
merged 4 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ internal class BuiltinFunctionsCore
public static readonly TexlFunction Float = _featureGateFunctions.Add(new FloatFunction());
public static readonly TexlFunction Float_UO = _featureGateFunctions.Add(new FloatFunction_UO());
public static readonly TexlFunction IsUTCToday = _featureGateFunctions.Add(new IsUTCTodayFunction());
public static readonly TexlFunction OptionsSetInfo = _featureGateFunctions.Add(new OptionSetInfoFunction());
public static readonly TexlFunction UTCNow = _featureGateFunctions.Add(new UTCNowFunction());
public static readonly TexlFunction UTCToday = _featureGateFunctions.Add(new UTCTodayFunction());
public static readonly TexlFunction BooleanL = _featureGateFunctions.Add(new BooleanLFunction());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
// Licensed under the MIT license.

using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.PowerFx.Core.Functions;
using Microsoft.PowerFx.Core.IR;
using Microsoft.PowerFx.Core.Localization;
using Microsoft.PowerFx.Core.Types;
using Microsoft.PowerFx.Functions;
using Microsoft.PowerFx.Types;

namespace Microsoft.PowerFx.Core.Texl.Builtins
namespace Microsoft.PowerFx.Functions
{
internal sealed class OptionSetInfoFunction : BuiltinFunction
internal sealed class OptionSetInfoFunction : BuiltinFunction, IAsyncTexlFunction
gregli-msft marked this conversation as resolved.
Show resolved Hide resolved
{
public override bool IsSelfContained => true;

Expand All @@ -23,5 +28,20 @@ public OptionSetInfoFunction()
{
yield return new[] { TexlStrings.AboutOptionSetInfoArg1 };
}

public async Task<FormulaValue> InvokeAsync(FormulaValue[] args, CancellationToken cancellationToken)
gregli-msft marked this conversation as resolved.
Show resolved Hide resolved
{
switch (args[0])
{
case ErrorValue errorValue:
return errorValue;
case BlankValue:
return new StringValue(IRContext.NotInSource(FormulaType.String), string.Empty);
case OptionSetValue osv:
return new StringValue(IRContext.NotInSource(FormulaType.String), osv.Option);
}

return CommonErrors.GenericInvalidArgument(args[0].IRContext);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using Microsoft.PowerFx.Core.Functions;
using Microsoft.PowerFx.Core.Texl.Builtins;
using Microsoft.PowerFx.Functions;
using Microsoft.PowerFx.Interpreter;

Expand Down Expand Up @@ -60,5 +61,11 @@ public static void EnableRegExFunctions(this PowerFxConfig config, TimeSpan regE
config.AdditionalFunctions.Add(func.Key, func.Value);
}
}

[Obsolete("OptionSetInfo function is deprecated. Use the Value function on an option set backed by a number and the Boolean function on an option set bacekd by a Boolean instead. A new ChoiceInfo function is in the works for access to logical names.")]
gregli-msft marked this conversation as resolved.
Show resolved Hide resolved
public static void EnableOptionSetInfo(this PowerFxConfig powerFxConfig)
{
powerFxConfig.AddFunction(new OptionSetInfoFunction());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1235,17 +1235,6 @@ static Library()
BuiltinFunctionsCore.Now,
NoErrorHandling(Now)
},
{
BuiltinFunctionsCore.OptionsSetInfo,
StandardErrorHandling<OptionSetValue>(
BuiltinFunctionsCore.OptionsSetInfo.Name,
expandArguments: NoArgExpansion,
replaceBlankValues: DoNotReplaceBlank,
checkRuntimeTypes: ExactValueTypeOrBlank<OptionSetValue>,
checkRuntimeValues: DeferRuntimeValueChecking,
returnBehavior: ReturnBehavior.ReturnEmptyStringIfAnyArgIsBlank,
targetFunction: OptionSetValueToLogicalName)
},
{
BuiltinFunctionsCore.Or,
Or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1169,13 +1169,6 @@ public static FormulaValue GuidPure(IRContext irContext, StringValue[] args)
}
}

public static FormulaValue OptionSetValueToLogicalName(IRContext irContext, OptionSetValue[] args)
{
var optionSet = args[0];
var logicalName = optionSet.Option;
return new StringValue(irContext, logicalName);
}

public static FormulaValue PlainText(IRContext irContext, StringValue[] args)
{
string text = args[0].Value.Trim();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public void Test()
config.EnableJsonFunctions();
#pragma warning disable CS0618 // Type or member is obsolete
config.EnableRegExFunctions();
config.EnableOptionSetInfo();
#pragma warning restore CS0618 // Type or member is obsolete

config.SymbolTable.EnableMutationFunctions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1032,6 +1032,9 @@ public async void OptionSetInfoTests(string expression, string expected)
symValues.Set(option1Solt, option1);

var config = new PowerFxConfig() { SymbolTable = symbol };
#pragma warning disable CS0618 // Type or member is obsolete
config.EnableOptionSetInfo();
#pragma warning restore CS0618 // Type or member is obsolete
config.AddOptionSet(optionSet);
var recalcEngine = new RecalcEngine(config);

Expand Down
3 changes: 3 additions & 0 deletions src/tools/Repl/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ private static RecalcEngine ReplRecalcEngine()

config.EnableSetFunction();
config.EnableJsonFunctions();
#pragma warning disable CS0618 // Type or member is obsolete
config.EnableOptionSetInfo();
#pragma warning restore CS0618 // Type or member is obsolete

config.AddFunction(new ResetFunction());
config.AddFunction(new Option0Function());
Expand Down