Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jas-valgotar committed Mar 4, 2024
1 parent 213a272 commit fd7022c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using Microsoft.PowerFx.Core.Binding.BindInfo;
using Microsoft.PowerFx.Core.Functions;
Expand Down Expand Up @@ -152,9 +153,17 @@ private static bool TryGetParentRecordFieldType(DType aggregateType, TexlNode cu
internal static bool AddAggregateSuggestions(DType aggregateType, IntellisenseData.IntellisenseData intellisenseData, int cursorPos)
{
var suggestionsAdded = false;
var parentRecordNode = intellisenseData.CurNode.Parent as RecordNode;
var alreadyUsedFields = parentRecordNode?.Ids.Select(id => id.Name).ToImmutableHashSet();
foreach (var tName in aggregateType.GetNames(DPath.Root).Where(param => !param.Type.IsError))
{
var usedName = tName.Name;

if (alreadyUsedFields?.Contains(usedName) == true)
{
continue;
}

if (DType.TryGetDisplayNameForColumn(aggregateType, usedName, out var maybeDisplayName))
{
usedName = new DName(maybeDisplayName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ private string[] SuggestStrings(string expression, PowerFxConfig config, Culture
[InlineData("[@In|]", "ErrorKind")]

// FunctionRecordNameSuggestionHandler
[InlineData("Error({Kin|d:0})", "Kind:")]
[InlineData("Error({|Kind:0, Test:\"\"})", "Kind:", "Test:")]
[InlineData("Error({Kin|d:0})")]
[InlineData("Error({|Kind:0, Test:\"\"})")]

// ErrorNodeSuggestionHandler
[InlineData("ForAll([0],`|", "ThisRecord", "Value")]
Expand Down Expand Up @@ -493,7 +493,7 @@ public void SuggestUser(string expression, params string[] expected)
[Theory]
[InlineData("{|", "output1:", "output2:")]

[InlineData("{output1: 1, |", "output1:", "output2:")]
[InlineData("{output1: 1, |", "output2:")]

// We do not suggest nested type, as this can explode if type is DV.
[InlineData("{output1: {|")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,21 +274,42 @@ public void TestArgSuggestion(string expression, params string[] expectedSuggest
"field1:")]
[InlineData(
"RecordInputTest( {field1 : 1}, \"test\", {|",
"id:",
"id:",
"name:")]

// do not repeat already used fields.
[InlineData(
"RecordInputTest( {field1 : 2}, \"test\", { id: 1, |",
"name:")]

[InlineData(
"RecordInputTest( {field1 : 2}, \"test\", { name: \"test\", |",
"id:")]

[InlineData(
"RecordInputTest( {field1 : 2}, \"test\", { id: 1, name: \"test\"}, {|",
"RecordInputTest( {field1 : 2}, \"test\", { id: 1, name:\"test name\", |}")]

[InlineData(
"RecordInputTest( {field1 : 2}, \"test\", { id: 1, name: \"test\"}, {|",
"nested:",
"nested2:")]

// nested record field.
[InlineData(
"RecordInputTest( {field1 : 3}, \"test\", { id: 1, name: \"test\"}, { nested:{|",
"RecordInputTest( {field1 : 3}, \"test\", { id: 1, name: \"test\"}, { nested:{|",
"field1:")]
[InlineData(
"RecordInputTest( {field1 : 4}, \"test\", { id: 1, name: \"test\"}, { nested2:{|",
"id:",
"RecordInputTest( {field1 : 4}, \"test\", { id: 1, name: \"test\"}, { nested2:{|",
"id:",
"name:")]

// do not repeat already used fields.
[InlineData(
"RecordInputTest( {field1 : 4}, \"test\", { id: 1, name: \"test\"}, { nested2:{ id: 2, |",
"name:")]
[InlineData(
"RecordInputTest( {field1 : 4}, \"test\", { id: 1, name: \"test\"}, { nested2:{ id: 2, name: \"test\", |")]

[InlineData(
"RecordInputTest( {field1 : 3}, \"test\", { id: 1, name: \"test\"}, { nested:{ field1: 1}, nested2: {|",
"id:",
Expand Down

0 comments on commit fd7022c

Please sign in to comment.