Skip to content

Commit e63f328

Browse files
author
Kusto Build System
committed
Auto-sync from Azure-Kusto-Service
1 parent cfef9ef commit e63f328

2 files changed

Lines changed: 53 additions & 10 deletions

File tree

src/Kusto.Language/Binder/Binder_FunctionCalls.cs

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,6 @@ private SemanticInfo BindFunctionCallOrPattern(FunctionCallExpression functionCa
4646
}
4747
}
4848

49-
private static bool IsInvokeOperatorFunctionCall(FunctionCallExpression functionCall)
50-
{
51-
return functionCall.Parent is InvokeOperator
52-
|| (functionCall.Parent is PathExpression p && p.Selector == functionCall && p.Parent is InvokeOperator);
53-
}
54-
5549
/// <summary>
5650
/// Binds a function call
5751
/// </summary>
@@ -329,12 +323,61 @@ private void GetArgumentsAndTypes(
329323

330324
if (IsInvokeOperatorFunctionCall(functionCall))
331325
{
332-
// add fake argument to represent the implicit value
333-
arguments.Insert(0, functionCall.Name);
326+
// add argument to represent the implicit value
327+
if (TryGetInvokeOperatorExpression(functionCall, out var invokeArgument))
328+
{
329+
arguments.Insert(0, invokeArgument);
330+
}
331+
else
332+
{
333+
// no preceding expression was found... use the name node instead.
334+
arguments.Insert(0, functionCall.Name);
335+
}
336+
334337
argumentTypes.Insert(0, _implicitArgumentType ?? TableSymbol.Empty);
335338
}
336339
}
337340

341+
private static bool IsInvokeOperatorFunctionCall(FunctionCallExpression functionCall)
342+
{
343+
// ignore dotted path that is part of function call
344+
Expression x = functionCall;
345+
while (x.Parent is PathExpression p
346+
&& p.Selector == x)
347+
{
348+
x = p.Expression;
349+
}
350+
351+
return x.Parent is InvokeOperator io
352+
&& io.Function == x;
353+
}
354+
355+
private static bool TryGetInvokeOperatorExpression(FunctionCallExpression functionCall, out Expression invokeArgument)
356+
{
357+
// ignore dotted path that is part of function call
358+
Expression x = functionCall;
359+
while (x.Parent is PathExpression p
360+
&& p.Selector == x)
361+
{
362+
x = p.Expression;
363+
}
364+
365+
// check for parent pipe expression to find implicit argument
366+
if (x.Parent is InvokeOperator invokeOp
367+
&& invokeOp.Function == x
368+
&& invokeOp.Parent is PipeExpression invokeOpPipe
369+
&& invokeOpPipe.Operator == invokeOp)
370+
{
371+
invokeArgument = invokeOpPipe.Expression;
372+
return true;
373+
}
374+
else
375+
{
376+
invokeArgument = null;
377+
return false;
378+
}
379+
}
380+
338381
/// <summary>
339382
/// Gets the parameters that correspond to the arguments.
340383
/// </summary>

src/Kusto.Language/Parser/CodeGen/EngineCommandGrammar.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ internal override CommandParserInfo[] CreateCommandParsers(PredefinedRuleParsers
6767
var shape35 = new [] {CD(), CD(), CD("TableName", CompletionHint.None), CD(), CD(isOptional: true)};
6868
var shape36 = new [] {CD("TableName", CompletionHint.None), CD()};
6969
var shape37 = new [] {CD(), CD(), CD(CompletionHint.None), CD(isOptional: true)};
70-
var shape38 = new [] {CD(), CD(), CD(CompletionHint.Table), CD(), CD(isOptional: true)};
70+
var shape38 = new [] {CD(), CD(), CD("TableName", CompletionHint.Table), CD(), CD(isOptional: true)};
7171
var shape39 = CD("NewTableName", CompletionHint.None);
7272
var shape40 = new [] {CD(), CD(), CD("TableName", CompletionHint.Table), CD(), CD("MappingKind"), CD(), CD("MappingName", CompletionHint.Literal), CD("MappingFormat", CompletionHint.Literal), CD(isOptional: true)};
7373
var shape41 = CD("NewColumnName", CompletionHint.None);
@@ -1909,7 +1909,7 @@ internal override CommandParserInfo[] CreateCommandParsers(PredefinedRuleParsers
19091909
If(Not(Token("with")), rules.FunctionNameReference),
19101910
Token("docstring"),
19111911
rules.StringLiteral,
1912-
new [] {CD(), CD(), CD(CompletionHint.Function), CD(), CD("Documentation", CompletionHint.Literal)}));
1912+
new [] {CD(), CD(), CD("FunctionName", CompletionHint.Function), CD(), CD("Documentation", CompletionHint.Literal)}));
19131913

19141914
var AlterFunctionFolder = Command("AlterFunctionFolder",
19151915
Custom(

0 commit comments

Comments
 (0)