From a55da9ae0b56223e6489f545cec32107c6fb2f05 Mon Sep 17 00:00:00 2001 From: herman wen Date: Tue, 29 Jul 2025 14:45:01 +0800 Subject: [PATCH 1/3] Add syncSupport function option --- .../custom-functions-metadata/src/parseTree.ts | 18 +++++++++++++++++- .../expected.js.errors.txt | 1 + .../expected.ts.errors.txt | 1 + .../functions.js | 12 ++++++++++++ .../functions.ts | 12 ++++++++++++ 5 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 packages/custom-functions-metadata/test/cases/error-syncsupport-missing-invocation-parameter/expected.js.errors.txt create mode 100644 packages/custom-functions-metadata/test/cases/error-syncsupport-missing-invocation-parameter/expected.ts.errors.txt create mode 100644 packages/custom-functions-metadata/test/cases/error-syncsupport-missing-invocation-parameter/functions.js create mode 100644 packages/custom-functions-metadata/test/cases/error-syncsupport-missing-invocation-parameter/functions.ts diff --git a/packages/custom-functions-metadata/src/parseTree.ts b/packages/custom-functions-metadata/src/parseTree.ts index f06ac59f2..b95abfaed 100644 --- a/packages/custom-functions-metadata/src/parseTree.ts +++ b/packages/custom-functions-metadata/src/parseTree.ts @@ -30,6 +30,7 @@ export interface IFunctionOptions { excludeFromAutoComplete?: boolean; linkedEntityLoadService?: boolean; capturesCallingObject?: boolean; + syncSupport?: boolean } export interface IFunctionParameter { @@ -132,6 +133,7 @@ const REQUIRESADDRESS = "requiresaddress"; const REQUIRESPARAMETERADDRESSES = "requiresparameteraddresses"; const STREAMING = "streaming"; const VOLATILE = "volatile"; +const SYNCSUPPORT = "syncsupport"; const TYPE_MAPPINGS = { [ts.SyntaxKind.NumberKeyword]: "number", @@ -462,7 +464,8 @@ export function parseTree(sourceCode: string, sourceFileName: string): IParseTre !options.requiresStreamParameterAddresses && !options.excludeFromAutoComplete && !options.linkedEntityLoadService && - !options.capturesCallingObject + !options.capturesCallingObject && + !options.syncSupport ) { delete functionMetadata.options; } else { @@ -505,6 +508,10 @@ export function parseTree(sourceCode: string, sourceFileName: string): IParseTre if (!options.capturesCallingObject) { delete options.capturesCallingObject; } + + if (!options.syncSupport) { + delete options.syncSupport; + } } if (!functionMetadata.helpUrl) { @@ -667,6 +674,7 @@ function getOptions( excludeFromAutoComplete: isExcludedFromAutoComplete(func), linkedEntityLoadService: isLinkedEntityLoadService(func), capturesCallingObject: capturesCallingObject(func), + syncSupport: isSyncSupport(func), }; if (isAddressRequired(func) || isRequiresParameterAddresses(func)) { @@ -1062,6 +1070,14 @@ function capturesCallingObject(node: ts.Node): boolean { return hasTag(node, CAPTURESCALLINGOBJECT); } +/** + * Returns true if syncSupport tag found in comments + * @param node jsDocs node + */ +function isSyncSupport(node: ts.Node): boolean { + return hasTag(node, SYNCSUPPORT); +} + function containsTag(tag: ts.JSDocTag, tagName: string): boolean { return (tag.tagName.escapedText as string).toLowerCase() === tagName; } diff --git a/packages/custom-functions-metadata/test/cases/error-syncsupport-missing-invocation-parameter/expected.js.errors.txt b/packages/custom-functions-metadata/test/cases/error-syncsupport-missing-invocation-parameter/expected.js.errors.txt new file mode 100644 index 000000000..148c6846c --- /dev/null +++ b/packages/custom-functions-metadata/test/cases/error-syncsupport-missing-invocation-parameter/expected.js.errors.txt @@ -0,0 +1 @@ +Since @syncSupport is present, the last function parameter should be of type CustomFunctions.Invocation : (10,40) \ No newline at end of file diff --git a/packages/custom-functions-metadata/test/cases/error-syncsupport-missing-invocation-parameter/expected.ts.errors.txt b/packages/custom-functions-metadata/test/cases/error-syncsupport-missing-invocation-parameter/expected.ts.errors.txt new file mode 100644 index 000000000..4b005b6de --- /dev/null +++ b/packages/custom-functions-metadata/test/cases/error-syncsupport-missing-invocation-parameter/expected.ts.errors.txt @@ -0,0 +1 @@ +Since @syncSupport is present, the last function parameter should be of type CustomFunctions.Invocation : (10,48) \ No newline at end of file diff --git a/packages/custom-functions-metadata/test/cases/error-syncsupport-missing-invocation-parameter/functions.js b/packages/custom-functions-metadata/test/cases/error-syncsupport-missing-invocation-parameter/functions.js new file mode 100644 index 000000000..75a138498 --- /dev/null +++ b/packages/custom-functions-metadata/test/cases/error-syncsupport-missing-invocation-parameter/functions.js @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. + +/** + * Test missing invocation parameter type + * @param x {string} string + * @customfunction + * @syncSupport + */ +function customFunctionInvocationTest(x) { + // Empty +} diff --git a/packages/custom-functions-metadata/test/cases/error-syncsupport-missing-invocation-parameter/functions.ts b/packages/custom-functions-metadata/test/cases/error-syncsupport-missing-invocation-parameter/functions.ts new file mode 100644 index 000000000..32e78226f --- /dev/null +++ b/packages/custom-functions-metadata/test/cases/error-syncsupport-missing-invocation-parameter/functions.ts @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. + +/** + * Test missing invocation parameter type + * @param x string + * @customfunction + * @syncSupport + */ +function customFunctionInvocationTest(x: string) { + // Empty +} From aee086a144f76490ba142953fb8624574e79916a Mon Sep 17 00:00:00 2001 From: herman wen Date: Tue, 5 Aug 2025 11:27:32 +0800 Subject: [PATCH 2/3] change name to @sync; fix test bug --- .../src/parseTree.ts | 26 ++++++++++++------- .../expected.js.errors.txt | 1 + .../expected.ts.errors.txt | 1 + .../functions.js | 2 +- .../functions.ts | 2 +- .../expected.js.errors.txt | 1 - .../expected.ts.errors.txt | 1 - 7 files changed, 21 insertions(+), 13 deletions(-) create mode 100644 packages/custom-functions-metadata/test/cases/error-sync-missing-invocation-parameter/expected.js.errors.txt create mode 100644 packages/custom-functions-metadata/test/cases/error-sync-missing-invocation-parameter/expected.ts.errors.txt rename packages/custom-functions-metadata/test/cases/{error-syncsupport-missing-invocation-parameter => error-sync-missing-invocation-parameter}/functions.js (94%) rename packages/custom-functions-metadata/test/cases/{error-syncsupport-missing-invocation-parameter => error-sync-missing-invocation-parameter}/functions.ts (94%) delete mode 100644 packages/custom-functions-metadata/test/cases/error-syncsupport-missing-invocation-parameter/expected.js.errors.txt delete mode 100644 packages/custom-functions-metadata/test/cases/error-syncsupport-missing-invocation-parameter/expected.ts.errors.txt diff --git a/packages/custom-functions-metadata/src/parseTree.ts b/packages/custom-functions-metadata/src/parseTree.ts index b95abfaed..a653251f7 100644 --- a/packages/custom-functions-metadata/src/parseTree.ts +++ b/packages/custom-functions-metadata/src/parseTree.ts @@ -30,7 +30,7 @@ export interface IFunctionOptions { excludeFromAutoComplete?: boolean; linkedEntityLoadService?: boolean; capturesCallingObject?: boolean; - syncSupport?: boolean + sync?: boolean } export interface IFunctionParameter { @@ -133,7 +133,7 @@ const REQUIRESADDRESS = "requiresaddress"; const REQUIRESPARAMETERADDRESSES = "requiresparameteraddresses"; const STREAMING = "streaming"; const VOLATILE = "volatile"; -const SYNCSUPPORT = "syncsupport"; +const SYNC = "sync"; const TYPE_MAPPINGS = { [ts.SyntaxKind.NumberKeyword]: "number", @@ -465,7 +465,7 @@ export function parseTree(sourceCode: string, sourceFileName: string): IParseTre !options.excludeFromAutoComplete && !options.linkedEntityLoadService && !options.capturesCallingObject && - !options.syncSupport + !options.sync ) { delete functionMetadata.options; } else { @@ -509,8 +509,8 @@ export function parseTree(sourceCode: string, sourceFileName: string): IParseTre delete options.capturesCallingObject; } - if (!options.syncSupport) { - delete options.syncSupport; + if (!options.sync) { + delete options.sync; } } @@ -674,7 +674,7 @@ function getOptions( excludeFromAutoComplete: isExcludedFromAutoComplete(func), linkedEntityLoadService: isLinkedEntityLoadService(func), capturesCallingObject: capturesCallingObject(func), - syncSupport: isSyncSupport(func), + sync: isSync(func), }; if (isAddressRequired(func) || isRequiresParameterAddresses(func)) { @@ -689,6 +689,14 @@ function getOptions( } } + if (isSync(func)) { + if (!isInvocationFunction) { + const functionPosition = getPosition(func, func.parameters.end); + const errorString = `Since @sync is present, the last function parameter should be of type CustomFunctions.Invocation :`; + extra.errors.push(logError(errorString, functionPosition)); + } + } + if ( optionsItem.linkedEntityLoadService && (optionsItem.excludeFromAutoComplete || @@ -1071,11 +1079,11 @@ function capturesCallingObject(node: ts.Node): boolean { } /** - * Returns true if syncSupport tag found in comments + * Returns true if sync tag found in comments * @param node jsDocs node */ -function isSyncSupport(node: ts.Node): boolean { - return hasTag(node, SYNCSUPPORT); +function isSync(node: ts.Node): boolean { + return hasTag(node, SYNC); } function containsTag(tag: ts.JSDocTag, tagName: string): boolean { diff --git a/packages/custom-functions-metadata/test/cases/error-sync-missing-invocation-parameter/expected.js.errors.txt b/packages/custom-functions-metadata/test/cases/error-sync-missing-invocation-parameter/expected.js.errors.txt new file mode 100644 index 000000000..3aa4173d7 --- /dev/null +++ b/packages/custom-functions-metadata/test/cases/error-sync-missing-invocation-parameter/expected.js.errors.txt @@ -0,0 +1 @@ +Since @sync is present, the last function parameter should be of type CustomFunctions.Invocation : (10,40) \ No newline at end of file diff --git a/packages/custom-functions-metadata/test/cases/error-sync-missing-invocation-parameter/expected.ts.errors.txt b/packages/custom-functions-metadata/test/cases/error-sync-missing-invocation-parameter/expected.ts.errors.txt new file mode 100644 index 000000000..41f2de32f --- /dev/null +++ b/packages/custom-functions-metadata/test/cases/error-sync-missing-invocation-parameter/expected.ts.errors.txt @@ -0,0 +1 @@ +Since @sync is present, the last function parameter should be of type CustomFunctions.Invocation : (10,48) \ No newline at end of file diff --git a/packages/custom-functions-metadata/test/cases/error-syncsupport-missing-invocation-parameter/functions.js b/packages/custom-functions-metadata/test/cases/error-sync-missing-invocation-parameter/functions.js similarity index 94% rename from packages/custom-functions-metadata/test/cases/error-syncsupport-missing-invocation-parameter/functions.js rename to packages/custom-functions-metadata/test/cases/error-sync-missing-invocation-parameter/functions.js index 75a138498..bc29fbca9 100644 --- a/packages/custom-functions-metadata/test/cases/error-syncsupport-missing-invocation-parameter/functions.js +++ b/packages/custom-functions-metadata/test/cases/error-sync-missing-invocation-parameter/functions.js @@ -5,7 +5,7 @@ * Test missing invocation parameter type * @param x {string} string * @customfunction - * @syncSupport + * @sync */ function customFunctionInvocationTest(x) { // Empty diff --git a/packages/custom-functions-metadata/test/cases/error-syncsupport-missing-invocation-parameter/functions.ts b/packages/custom-functions-metadata/test/cases/error-sync-missing-invocation-parameter/functions.ts similarity index 94% rename from packages/custom-functions-metadata/test/cases/error-syncsupport-missing-invocation-parameter/functions.ts rename to packages/custom-functions-metadata/test/cases/error-sync-missing-invocation-parameter/functions.ts index 32e78226f..b99ed2545 100644 --- a/packages/custom-functions-metadata/test/cases/error-syncsupport-missing-invocation-parameter/functions.ts +++ b/packages/custom-functions-metadata/test/cases/error-sync-missing-invocation-parameter/functions.ts @@ -5,7 +5,7 @@ * Test missing invocation parameter type * @param x string * @customfunction - * @syncSupport + * @sync */ function customFunctionInvocationTest(x: string) { // Empty diff --git a/packages/custom-functions-metadata/test/cases/error-syncsupport-missing-invocation-parameter/expected.js.errors.txt b/packages/custom-functions-metadata/test/cases/error-syncsupport-missing-invocation-parameter/expected.js.errors.txt deleted file mode 100644 index 148c6846c..000000000 --- a/packages/custom-functions-metadata/test/cases/error-syncsupport-missing-invocation-parameter/expected.js.errors.txt +++ /dev/null @@ -1 +0,0 @@ -Since @syncSupport is present, the last function parameter should be of type CustomFunctions.Invocation : (10,40) \ No newline at end of file diff --git a/packages/custom-functions-metadata/test/cases/error-syncsupport-missing-invocation-parameter/expected.ts.errors.txt b/packages/custom-functions-metadata/test/cases/error-syncsupport-missing-invocation-parameter/expected.ts.errors.txt deleted file mode 100644 index 4b005b6de..000000000 --- a/packages/custom-functions-metadata/test/cases/error-syncsupport-missing-invocation-parameter/expected.ts.errors.txt +++ /dev/null @@ -1 +0,0 @@ -Since @syncSupport is present, the last function parameter should be of type CustomFunctions.Invocation : (10,48) \ No newline at end of file From 2eafafbde71fcff748446ccf66a408097cd86032 Mon Sep 17 00:00:00 2001 From: Herman Wen Date: Thu, 21 Aug 2025 17:01:35 +0800 Subject: [PATCH 3/3] update tag from @sync to @supportSync --- .../src/parseTree.ts | 24 +++++++------------ .../expected.js.errors.txt | 1 - .../expected.ts.errors.txt | 1 - .../functions.js | 12 ---------- .../functions.ts | 12 ---------- 5 files changed, 8 insertions(+), 42 deletions(-) delete mode 100644 packages/custom-functions-metadata/test/cases/error-sync-missing-invocation-parameter/expected.js.errors.txt delete mode 100644 packages/custom-functions-metadata/test/cases/error-sync-missing-invocation-parameter/expected.ts.errors.txt delete mode 100644 packages/custom-functions-metadata/test/cases/error-sync-missing-invocation-parameter/functions.js delete mode 100644 packages/custom-functions-metadata/test/cases/error-sync-missing-invocation-parameter/functions.ts diff --git a/packages/custom-functions-metadata/src/parseTree.ts b/packages/custom-functions-metadata/src/parseTree.ts index a653251f7..f12375118 100644 --- a/packages/custom-functions-metadata/src/parseTree.ts +++ b/packages/custom-functions-metadata/src/parseTree.ts @@ -30,7 +30,7 @@ export interface IFunctionOptions { excludeFromAutoComplete?: boolean; linkedEntityLoadService?: boolean; capturesCallingObject?: boolean; - sync?: boolean + supportSync?: boolean; } export interface IFunctionParameter { @@ -133,7 +133,7 @@ const REQUIRESADDRESS = "requiresaddress"; const REQUIRESPARAMETERADDRESSES = "requiresparameteraddresses"; const STREAMING = "streaming"; const VOLATILE = "volatile"; -const SYNC = "sync"; +const SUPPORT_SYNC = "supportsync"; const TYPE_MAPPINGS = { [ts.SyntaxKind.NumberKeyword]: "number", @@ -465,7 +465,7 @@ export function parseTree(sourceCode: string, sourceFileName: string): IParseTre !options.excludeFromAutoComplete && !options.linkedEntityLoadService && !options.capturesCallingObject && - !options.sync + !options.supportSync ) { delete functionMetadata.options; } else { @@ -509,8 +509,8 @@ export function parseTree(sourceCode: string, sourceFileName: string): IParseTre delete options.capturesCallingObject; } - if (!options.sync) { - delete options.sync; + if (!options.supportSync) { + delete options.supportSync; } } @@ -674,7 +674,7 @@ function getOptions( excludeFromAutoComplete: isExcludedFromAutoComplete(func), linkedEntityLoadService: isLinkedEntityLoadService(func), capturesCallingObject: capturesCallingObject(func), - sync: isSync(func), + supportSync: supportSync(func), }; if (isAddressRequired(func) || isRequiresParameterAddresses(func)) { @@ -689,14 +689,6 @@ function getOptions( } } - if (isSync(func)) { - if (!isInvocationFunction) { - const functionPosition = getPosition(func, func.parameters.end); - const errorString = `Since @sync is present, the last function parameter should be of type CustomFunctions.Invocation :`; - extra.errors.push(logError(errorString, functionPosition)); - } - } - if ( optionsItem.linkedEntityLoadService && (optionsItem.excludeFromAutoComplete || @@ -1082,8 +1074,8 @@ function capturesCallingObject(node: ts.Node): boolean { * Returns true if sync tag found in comments * @param node jsDocs node */ -function isSync(node: ts.Node): boolean { - return hasTag(node, SYNC); +function supportSync(node: ts.Node): boolean { + return hasTag(node, SUPPORT_SYNC); } function containsTag(tag: ts.JSDocTag, tagName: string): boolean { diff --git a/packages/custom-functions-metadata/test/cases/error-sync-missing-invocation-parameter/expected.js.errors.txt b/packages/custom-functions-metadata/test/cases/error-sync-missing-invocation-parameter/expected.js.errors.txt deleted file mode 100644 index 3aa4173d7..000000000 --- a/packages/custom-functions-metadata/test/cases/error-sync-missing-invocation-parameter/expected.js.errors.txt +++ /dev/null @@ -1 +0,0 @@ -Since @sync is present, the last function parameter should be of type CustomFunctions.Invocation : (10,40) \ No newline at end of file diff --git a/packages/custom-functions-metadata/test/cases/error-sync-missing-invocation-parameter/expected.ts.errors.txt b/packages/custom-functions-metadata/test/cases/error-sync-missing-invocation-parameter/expected.ts.errors.txt deleted file mode 100644 index 41f2de32f..000000000 --- a/packages/custom-functions-metadata/test/cases/error-sync-missing-invocation-parameter/expected.ts.errors.txt +++ /dev/null @@ -1 +0,0 @@ -Since @sync is present, the last function parameter should be of type CustomFunctions.Invocation : (10,48) \ No newline at end of file diff --git a/packages/custom-functions-metadata/test/cases/error-sync-missing-invocation-parameter/functions.js b/packages/custom-functions-metadata/test/cases/error-sync-missing-invocation-parameter/functions.js deleted file mode 100644 index bc29fbca9..000000000 --- a/packages/custom-functions-metadata/test/cases/error-sync-missing-invocation-parameter/functions.js +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -/** - * Test missing invocation parameter type - * @param x {string} string - * @customfunction - * @sync - */ -function customFunctionInvocationTest(x) { - // Empty -} diff --git a/packages/custom-functions-metadata/test/cases/error-sync-missing-invocation-parameter/functions.ts b/packages/custom-functions-metadata/test/cases/error-sync-missing-invocation-parameter/functions.ts deleted file mode 100644 index b99ed2545..000000000 --- a/packages/custom-functions-metadata/test/cases/error-sync-missing-invocation-parameter/functions.ts +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -/** - * Test missing invocation parameter type - * @param x string - * @customfunction - * @sync - */ -function customFunctionInvocationTest(x: string) { - // Empty -}