diff --git a/src/vscode_plugin/docs/snippetsApi.md b/src/vscode_plugin/docs/snippetsApi.md
index ed62e8b8fb79169a5aeb09bb6c2149dc87542ff1..83c9c87dab6dbd3c6f5250dc7fe97e2aff149b6c 100644
--- a/src/vscode_plugin/docs/snippetsApi.md
+++ b/src/vscode_plugin/docs/snippetsApi.md
@@ -155,7 +155,6 @@
-
**Aki snippets**
|
@@ -166,7 +165,7 @@
- | 1.0.0 |
+ 1.0.0 |
类 |
akiclass |
aki 类使用场景代码片段 |
@@ -182,14 +181,127 @@
aki 枚举使用场景代码片段 |
- | 同步方法 |
+ 同步 |
akisyncfunc |
- aki同步方法使用场景代码片段 |
+ aki 同步方法使用场景代码片段 |
- | 异步方法 |
+ 异步 |
akiasyncfunc |
- aki异步方法使用场景代码片段 |
+ aki 异步方法使用场景代码片段 |
-
-
\ No newline at end of file
+
+ | akicallfuncreturnstring |
+ aki std::function回调场景代码片段 |
+
+
+ | akicallbackreturnstring |
+ aki 非线程安全回调场景代码片段 |
+
+
+ | akisafecallbackreturnstring |
+ aki 线程安全回调场景代码片段 |
+
+
+ | akipromiseresolve |
+ aki promise resolve代码片段 |
+
+
+ | akipromisereject |
+ aki promise reject代码片段 |
+
+
+ | akiposttask |
+ aki 往指定任务调度器投递任务代码片段 |
+
+
+ | aki::Value |
+ akipassvalueasbool |
+ aki 将JS对象转换为C++ bool类型代码片段 |
+
+
+ | akipassvalueasuint8 |
+ aki 将JS对象转换为C++ uint8类型代码片段 |
+
+
+ | akipassvalueasint8 |
+ aki 将JS对象转换为C++ int8类型代码片段 |
+
+
+ | akipassvalueasuint16 |
+ aki 将JS对象转换为C++ uint16类型代码片段 |
+
+
+ | akipassvalueasint16 |
+ aki 将JS对象转换为C++ int16类型代码片段 |
+
+
+ | akipassvalueasint |
+ aki 将JS对象转换为C++ int类型代码片段 |
+
+
+ | akipassvalueasint64 |
+ aki 将JS对象转换为C++ int64类型代码片段 |
+
+
+ | akipassvalueasfloat |
+ aki 将JS对象转换为C++ float类型代码片段 |
+
+
+ | akipassvalueasdouble |
+ aki 将JS对象转换为C++ double类型代码片段 |
+
+
+ | akipassvalueasstring |
+ aki 将JS对象转换为C++ string类型代码片段 |
+
+
+ | akipassvalueasfunction |
+ aki 将JS对象转换为C++ function类型代码片段 |
+
+
+ | akiarraypushvalue |
+ aki 使用CallMethod在C++中调用JS定义的方法代码片段 |
+
+
+ | akipassvalueasobject |
+ aki 在C++中动态创建一个新的JS对象,并对其进行操作代码片段 |
+
+
+ | akicheckvalueisnull |
+ aki 判断JS对象是否为null代码片段 |
+
+
+ | akicheckvalueisbool |
+ aki 判断JS对象是否为bool类型代码片段 |
+
+
+ | akicheckvalueisnumber |
+ aki 判断JS对象是否为number类型代码片段 |
+
+
+ | akicheckvalueisstring |
+ aki 判断JS对象是否为string类型代码片段 |
+
+
+ | akicheckvalueisobject |
+ aki 判断JS对象是否为object类型代码片段 |
+
+
+ | akicheckvalueisarray |
+ aki 判断JS对象是否为array类型代码片段 |
+
+
+ | akicheckvalueisfunction |
+ aki 判断JS对象是否为function类型代码片段 |
+
+
+ | akivaluefromglobaljsonstringify |
+ aki 在C++中访问全局定义的对象,调用JSON.stringify方法 |
+
+
+ | akivaluefromglobaljsonparse |
+ aki 在C++中访问全局定义的对象,调用JSON.parse方法 |
+
+
+
\ No newline at end of file
diff --git a/src/vscode_plugin/package.json b/src/vscode_plugin/package.json
index beb16845b92a623127945c9ba6ee2f928a907e84..0b3fcfc629471516c2222531a3a7c8ab4c74f069 100644
--- a/src/vscode_plugin/package.json
+++ b/src/vscode_plugin/package.json
@@ -164,6 +164,22 @@
{
"language": "cpp",
"path": "./snippets/aki_enum_snippets.json"
+ },
+ {
+ "language": "cpp",
+ "path": "./snippets/aki_callback_snippets.json"
+ },
+ {
+ "language": "cpp",
+ "path": "./snippets/aki_promise_snippets.json"
+ },
+ {
+ "language": "cpp",
+ "path": "./snippets/aki_thread_snippets.json"
+ },
+ {
+ "language": "cpp",
+ "path": "./snippets/aki_value_snippets.json"
}
]
},
diff --git a/src/vscode_plugin/snippets/aki_callback_snippets.json b/src/vscode_plugin/snippets/aki_callback_snippets.json
new file mode 100644
index 0000000000000000000000000000000000000000..a5680c998ef9c05c3e57f5034871df59124c59ef
--- /dev/null
+++ b/src/vscode_plugin/snippets/aki_callback_snippets.json
@@ -0,0 +1,41 @@
+{
+ "Aki callfunction return string": {
+ "prefix": "akicallfuncreturnstring",
+ "body": [
+ "// The bound native method with parameter types std::function can accept JS callbacks as input parameters.",
+ "void CallFunctionReturnString(std::function func) {",
+ " auto str = func();",
+ " AKI_LOG(INFO) << \"std::function callback return from Js: \" << str;",
+ "}",
+ "JSBIND_GLOBAL() {",
+ " JSBIND_FUNCTION(CallFunctionReturnString);",
+ "}"
+ ]
+ },
+ "Aki call js callback return string": {
+ "prefix": "akicallbackreturnstring",
+ "body": [
+ "// The bound native method with parameter types aki::Callback can accept JS callbacks as input parameters.",
+ "void CallJsbCallbackReturnString(aki::Callback func) {",
+ " auto str = func();",
+ " AKI_LOG(INFO) << \"aki::Callback callback return from Js: \" << str;",
+ "}",
+ "JSBIND_GLOBAL() {",
+ " JSBIND_FUNCTION(CallJsbCallbackReturnString);",
+ "}"
+ ]
+ },
+ "Aki call js safety callback return string": {
+ "prefix": "akisafecallbackreturnstring",
+ "body": [
+ "// The bound native method with parameter types aki::SafetyCallback can accept JS callbacks as input parameters.",
+ "void CallJsbSafetyCallbackReturnString(aki::SafetyCallback func) {",
+ " auto str = func();",
+ " AKI_LOG(INFO) << \"aki::SafetyCallback callback return from Js: \" << str;",
+ "}",
+ "JSBIND_GLOBAL() {",
+ " JSBIND_FUNCTION(CallJsbSafetyCallbackReturnString);",
+ "}"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/src/vscode_plugin/snippets/aki_promise_snippets.json b/src/vscode_plugin/snippets/aki_promise_snippets.json
new file mode 100644
index 0000000000000000000000000000000000000000..4b61cbdacaa4e5ea7e1d44f87c39937ef51fab96
--- /dev/null
+++ b/src/vscode_plugin/snippets/aki_promise_snippets.json
@@ -0,0 +1,30 @@
+{
+ "Aki promise resolve":{
+ "prefix": "akipromiseresolve",
+ "body": [
+ "aki::Promise ReturnPromiseResolveImmediately() {",
+ " aki::Promise promise;",
+ " // Fulfill a js Promise with a given value.",
+ " promise.Resolve(\"aki promise\");",
+ " return promise;",
+ "}",
+ "JSBIND_GLOBAL() {",
+ " JSBIND_FUNCTION(ReturnPromiseResolveImmediately);",
+ "}"
+ ]
+ },
+ "Aki promise reject": {
+ "prefix": "akipromisereject",
+ "body": [
+ "aki::Promise ReturnPromiseRejectImmedIately() {",
+ " aki::Promise promise;",
+ " // Reject a js Promise with a given reason.",
+ " promise.Reject(\"aki reject promise\");",
+ " return promise;",
+ "}",
+ "JSBIND_GLOBAL() {",
+ " JSBIND_FUNCTION(ReturnPromiseRejectImmedIately);",
+ "}"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/src/vscode_plugin/snippets/aki_thread_snippets.json b/src/vscode_plugin/snippets/aki_thread_snippets.json
new file mode 100644
index 0000000000000000000000000000000000000000..b77eeb3455f26cab7657d7d14242253e7d604186
--- /dev/null
+++ b/src/vscode_plugin/snippets/aki_thread_snippets.json
@@ -0,0 +1,12 @@
+{
+ "Aki TaskRunner PostTask": {
+ "prefix": "akiposttask",
+ "body": [
+ "// PostTask submits a lambda to the \"main\" task scheduler for execution in its managed threads. Initialize the scheduler with JSBind.initTaskRunner(\"main\") before using PostTask.",
+ "aki::TaskRunner::PostTask(\"main\", []() {",
+ "// execute on Js thread",
+ "// Todo: do something",
+ "});"
+ ]
+ }
+}
\ No newline at end of file
diff --git a/src/vscode_plugin/snippets/aki_value_snippets.json b/src/vscode_plugin/snippets/aki_value_snippets.json
new file mode 100644
index 0000000000000000000000000000000000000000..4120b15f6daebab5687576fd18b185905e1504d1
--- /dev/null
+++ b/src/vscode_plugin/snippets/aki_value_snippets.json
@@ -0,0 +1,248 @@
+{
+ "Passing value as bool": {
+ "prefix": "akipassvalueasbool",
+ "body": [
+ "// As is used to convert JavaScript objects into bool data type in C/C++.",
+ "bool PassingValueAsBool(aki::Value value) { return value.As(); }",
+ "JSBIND_GLOBAL() {",
+ " JSBIND_FUNCTION(PassingValueAsBool);",
+ "}"
+ ]
+ },
+ "Passing value as uint8": {
+ "prefix": "akipassvalueasuint8",
+ "body": [
+ "// As is used to convert JavaScript objects into uint8_t data type in C/C++.",
+ "uint8_t PassingValueAsUint8(aki::Value value) { return value.As(); }",
+ "JSBIND_GLOBAL() {",
+ " JSBIND_FUNCTION(PassingValueAsUint8);",
+ "}"
+ ]
+ },
+ "Passing value as int8": {
+ "prefix": "akipassvalueasint8",
+ "body": [
+ "// As is used to convert JavaScript objects into int8_t data type in C/C++.",
+ "int8_t PassingValueAsInt8(aki::Value value) { return value.As(); }",
+ "JSBIND_GLOBAL() {",
+ " JSBIND_FUNCTION(PassingValueAsInt8);",
+ "}"
+ ]
+ },
+ "Passing value as uint16": {
+ "prefix": "akipassvalueasuint16",
+ "body": [
+ "// As is used to convert JavaScript objects into uint16_t data type in C/C++.",
+ "uint16_t PassingValueAsUint16(aki::Value value) { return value.As(); }",
+ "JSBIND_GLOBAL() {",
+ " JSBIND_FUNCTION(PassingValueAsUint16);",
+ "}"
+ ]
+ },
+ "Passing value as int16": {
+ "prefix": "akipassvalueasint16",
+ "body": [
+ "// As is used to convert JavaScript objects into int16_t data type in C/C++.",
+ "int16_t PassingValueAsInt16(aki::Value value) { return value.As(); }",
+ "JSBIND_GLOBAL() {",
+ " JSBIND_FUNCTION(PassingValueAsInt16);",
+ "}"
+ ]
+ },
+ "Passing value as int": {
+ "prefix": "akipassvalueasint",
+ "body": [
+ "// As is used to convert JavaScript objects into int data type in C/C++.",
+ "int PassingValueAsInt(aki::Value value) { return value.As(); }",
+ "JSBIND_GLOBAL() {",
+ " JSBIND_FUNCTION(PassingValueAsInt);",
+ "}"
+ ]
+ },
+ "Passing value as int64": {
+ "prefix": "akipassvalueasint64",
+ "body": [
+ "// As is used to convert JavaScript objects into int64_t data type in C/C++.",
+ "int64_t PassingValueAsInt64(aki::Value value) { return value.As(); }",
+ "JSBIND_GLOBAL() {",
+ " JSBIND_FUNCTION(PassingValueAsInt64);",
+ "}"
+ ]
+ },
+ "Passing value as float": {
+ "prefix": "akipassvalueasfloat",
+ "body": [
+ "// As is used to convert JavaScript objects into float data type in C/C++.",
+ "float PassingValueAsFloat(aki::Value value) { return value.As(); }",
+ "JSBIND_GLOBAL() {",
+ " JSBIND_FUNCTION(PassingValueAsFloat);",
+ "}"
+ ]
+ },
+ "Passing value as double": {
+ "prefix": "akipassvalueasdouble",
+ "body": [
+ "// As is used to convert JavaScript objects into double data type in C/C++.",
+ "double PassingValueAsDouble(aki::Value value) { return value.As(); }",
+ "JSBIND_GLOBAL() {",
+ " JSBIND_FUNCTION(PassingValueAsDouble);",
+ "}"
+ ]
+ },
+ "Passing value as string": {
+ "prefix": "akipassvalueasstring",
+ "body": [
+ "// As is used to convert JavaScript objects into std::string data type in C/C++.",
+ "std::string PassingValueAsString(aki::Value value) { return value.As(); }",
+ "JSBIND_GLOBAL() {",
+ " JSBIND_FUNCTION(PassingValueAsString);",
+ "}"
+ ]
+ },
+ "Passing value as function": {
+ "prefix": "akipassvalueasfunction",
+ "body": [
+ "// Invoke a JavaScript function, passing a string parameter and returning a result string.",
+ "std::string PassingValueAsFunction(aki::Value value) { return value(\"aki value from c++\").As(); }",
+ "JSBIND_GLOBAL() {",
+ " JSBIND_FUNCTION(PassingValueAsFunction);",
+ "}"
+ ]
+ },
+ "Passing array value return array value": {
+ "prefix": "akiarraypushvalue",
+ "body": [
+ "// aki::Value is a class used for mapping the any type in JavaScript in C/C++.",
+ "aki::Value PassingArrayValueReturnArrayValue(aki::Value value) {",
+ " // aki::Value::CallMethod is used to call the member functions of JavaScript objects and pass parameters.",
+ " // Invoke the push method of the JavaScript array object, and pass the string \"jsbind\" as a parameter to this method.",
+ " value.CallMethod(\"push\", \"jsbind\");",
+ " return value;",
+ "}",
+ "JSBIND_GLOBAL() {",
+ " JSBIND_FUNCTION(PassingArrayValueReturnArrayValue);",
+ "}"
+ ]
+ },
+ "Passing value as json object": {
+ "prefix": "akipassvalueasobject",
+ "body": [
+ "aki::Value PassingValueAsJsonObject(aki::Value value) {",
+ " // Create a new aki::Value object for dynamic property access in C++.",
+ " aki::Value val = aki::Value::NewObject();",
+ " // Set a property name (key) and a value (value) into an aki::Value object.",
+ " val.Set(\"name\", \"John\");",
+ " return val;",
+ "}",
+ "JSBIND_GLOBAL() {",
+ " JSBIND_FUNCTION(PassingValueAsJsonObject);",
+ "}"
+ ]
+ },
+ "Aki check value is undefined": {
+ "prefix": "akicheckvalueisundefined",
+ "body": [
+ "// Determine whether the aki::Value object is mapped to undefined in JavaScript.",
+ "aki::Value PassingValueCheckIsUndefined(aki::Value value) { return aki::Value(value.IsUndefined()); }",
+ "JSBIND_GLOBAL() {",
+ " JSBIND_FUNCTION(PassingValueCheckIsUndefined);",
+ "}"
+ ]
+ },
+ "Aki check value is null": {
+ "prefix": "akicheckvalueisnull",
+ "body": [
+ "// Determine whether the aki::Value object is mapped to null in JavaScript.",
+ "aki::Value PassingValueCheckIsNull(aki::Value value) { return aki::Value(value.IsNull()); }",
+ "JSBIND_GLOBAL() {",
+ " JSBIND_FUNCTION(PassingValueCheckIsNull);",
+ "}"
+ ]
+ },
+ "Aki check value is bool": {
+ "prefix": "akicheckvalueisbool",
+ "body": [
+ "// Determine whether the aki::Value object is mapped to bool in JavaScript.",
+ "aki::Value PassingValueCheckIsBool(aki::Value value) { return aki::Value(value.IsBool()); }",
+ "JSBIND_GLOBAL() {",
+ " JSBIND_FUNCTION(PassingValueCheckIsBool);",
+ "}"
+ ]
+ },
+ "Aki check value is number": {
+ "prefix": "akicheckvalueisnumber",
+ "body": [
+ "// Determine whether the aki::Value object is mapped to number in JavaScript.",
+ "aki::Value PassingValueCheckIsNumber(aki::Value value) { return aki::Value(value.IsNumber()); }",
+ "JSBIND_GLOBAL() {",
+ " JSBIND_FUNCTION(PassingValueCheckIsBool);",
+ "}"
+ ]
+ },
+ "Aki check value is string": {
+ "prefix": "akicheckvalueisstring",
+ "body": [
+ "// Determine whether the aki::Value object is mapped to string in JavaScript.",
+ "aki::Value PassingValueCheckIsString(aki::Value value) { return aki::Value(value.IsString()); }",
+ "JSBIND_GLOBAL() {",
+ " JSBIND_FUNCTION(PassingValueCheckIsString);",
+ "}"
+ ]
+ },
+ "Aki check value is object": {
+ "prefix": "akicheckvalueisobject",
+ "body": [
+ "// Determine whether the aki::Value object is mapped to object in JavaScript.",
+ "aki::Value PassingValueCheckIsObject(aki::Value value) { return aki::Value(value.IsObject()); }",
+ "JSBIND_GLOBAL() {",
+ " JSBIND_FUNCTION(PassingValueCheckIsObject);",
+ "}"
+ ]
+ },
+ "Aki check value is array": {
+ "prefix": "akicheckvalueisarray",
+ "body": [
+ "// Determine whether the aki::Value object is mapped to array in JavaScript.",
+ "aki::Value PassingValueCheckIsArray(aki::Value value) { return aki::Value(value.IsArray()); }",
+ "JSBIND_GLOBAL() {",
+ " JSBIND_FUNCTION(PassingValueCheckIsArray);",
+ "}"
+ ]
+ },
+ "Aki check value is function": {
+ "prefix": "akicheckvalueisfunction",
+ "body": [
+ "// Determine whether the aki::Value object is mapped to function in JavaScript.",
+ "aki::Value PassingValueCheckIsFunction(aki::Value value) { return aki::Value(value.IsFunction()); }",
+ "JSBIND_GLOBAL() {",
+ " JSBIND_FUNCTION(PassingValueCheckIsFunction);",
+ "}"
+ ]
+ },
+ "Aki value from global json stringify": {
+ "prefix": "akivaluefromglobaljsonstringify",
+ "body": [
+ "aki::Value FromGlobalJSONStringify(aki::Value obj) {",
+ " // Used to obtain properties under globalThis on the JS side.",
+ " aki::Value json = aki::Value::FromGlobal(\"JSON\");",
+ " return json[\"stringify\"](obj);",
+ "}",
+ "JSBIND_GLOBAL() {",
+ " JSBIND_FUNCTION(FromGlobalJSONStringify);",
+ "}"
+ ]
+ },
+ "Aki value from global json parse": {
+ "prefix": "akivaluefromglobaljsonparse",
+ "body": [
+ "aki::Value FromGlobalJSONParse(aki::Value obj) {",
+ " // Used to obtain properties under globalThis on the JS side.",
+ " aki::Value json = aki::Value::FromGlobal(\"JSON\");",
+ " return json[\"parse\"](obj);",
+ "}",
+ "JSBIND_GLOBAL() {",
+ " JSBIND_FUNCTION(FromGlobalJSONParse);",
+ "}"
+ ]
+ }
+}
\ No newline at end of file