From 6858027192f62c39558a2cce34e9540c0c9b9fbb Mon Sep 17 00:00:00 2001 From: chen-zhongwei050 Date: Fri, 8 Nov 2024 16:29:52 +0800 Subject: [PATCH 1/7] add napi enum, struct, sync snippets Signed-off-by: chen-zhongwei050 --- .../snippets/napi_enum_snippets.json | 35 +++++++++++++++++++ .../snippets/napi_struct_snippets.json | 33 +++++++++++++++++ .../snippets/napi_sync_snippets.json | 27 ++++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 src/vscode_plugin/snippets/napi_enum_snippets.json create mode 100644 src/vscode_plugin/snippets/napi_struct_snippets.json create mode 100644 src/vscode_plugin/snippets/napi_sync_snippets.json diff --git a/src/vscode_plugin/snippets/napi_enum_snippets.json b/src/vscode_plugin/snippets/napi_enum_snippets.json new file mode 100644 index 00000000..e5f5b3fd --- /dev/null +++ b/src/vscode_plugin/snippets/napi_enum_snippets.json @@ -0,0 +1,35 @@ +{ + "Napi Enum": { + "prefix": "napienum", + "body": [ + "napi_value CreateEnumObjectToJs(napi_env env, napi_callback_info info) {", + " napi_status status;", + " // Todo: you can use \"napiint32out\" command that return int32_t value to js.", + " // Todo: you can use \"napiobjectout\" command that return object value to js.", + " // Todo: you can use \"napisetvalue2object\" command that set value to objectOut", + " return objectOut;", + "}", + "napi_value GetEnumValueFromJs(napi_env env, napi_callback_info info)", + "{", + " // Todo: you can use \"napiobjectin\" command that get object value from js.", + " int32_t enumValue;", + " // Todo: you can use \"napiint32in\" command that get int32_t value from js.", + " return nullptr;", + "}", + "EXTERN_C_START", + "// Initialize the module.", + "static napi_value Init(napi_env env, napi_value exports)", + "{", + " // Define promise method for a N-API object.", + " napi_property_descriptor desc[] = {", + " {\"createEnumObjectToJs\", nullptr, CreateEnumObjectToJs, nullptr, nullptr, nullptr, napi_default, nullptr},", + " {\"getEnumValueFromJs\", nullptr, GetEnumValueFromJs, nullptr, nullptr, nullptr, napi_default, nullptr}", + " };", + " // Add an array of properties to a ArkTs object.", + " napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);", + " return exports;", + "}", + "EXTERN_C_END" + ] + } +} \ No newline at end of file diff --git a/src/vscode_plugin/snippets/napi_struct_snippets.json b/src/vscode_plugin/snippets/napi_struct_snippets.json new file mode 100644 index 00000000..32a90214 --- /dev/null +++ b/src/vscode_plugin/snippets/napi_struct_snippets.json @@ -0,0 +1,33 @@ +{ + "Napi Struct": { + "prefix": "napistruct", + "body": [ + "napi_value GetStructValueFromJs(napi_env env, napi_callback_info info)", + "{", + " // Todo: you can use \"napiobjectin\" command that get object value from js.", + " // Todo: you can use \"napigetvaluefromobject\" command that get value from js object.", + " return nullptr;", + "}", + "napi_value CreateStructObjectToJs(napi_env env, napi_callback_info info)", + "{", + " // Todo: you can use \"napiobjectout\" command that return object to js.", + " // Todo: you can use \"napisetvalue2object\" command that set value to objectOut.", + " return objectOut.", + "}", + "EXTERN_C_START", + "// Initialize the module.", + "static napi_value Init(napi_env env, napi_value exports)", + "{", + " // Define properties and methods for a N-API object.", + " napi_property_descriptor desc[] = {", + " { \"getStructValueFromJs\", nullptr, GetStructValueFromJs, nullptr, nullptr, nullptr, napi_default, nullptr },", + " { \"createStructObjectToJs\", nullptr, CreateStructObjectToJs, nullptr, nullptr, nullptr, napi_default, nullptr }", + " };", + " // Add an array of properties to a ArkTs object.", + " napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);", + " return exports;", + "}", + "EXTERN_C_END" + ] + } +} \ No newline at end of file diff --git a/src/vscode_plugin/snippets/napi_sync_snippets.json b/src/vscode_plugin/snippets/napi_sync_snippets.json new file mode 100644 index 00000000..a20d2608 --- /dev/null +++ b/src/vscode_plugin/snippets/napi_sync_snippets.json @@ -0,0 +1,27 @@ +{ + "Napi SyncFunc": { + "prefix": "napisyncfunc", + "body": [ + "static napi_value Add(napi_env env, napi_callback_info info)", + "{", + " // Todo: you can use \"napiobjectin\" command that get object param from js.", + " // Todo: you can use \"napidoublein\" command that get double param from js.", + " // Todo: you can use \"napidoubleout\" command that return double value to js.", + " return doubleOut;", + "}", + "EXTERN_C_START", + "// Initialize the module.", + "static napi_value Init(napi_env env, napi_value exports)", + "{", + " // Define promise method for a N-API object.", + " napi_property_descriptor desc[] = {", + " {\"add\", nullptr, Add, nullptr, nullptr, nullptr, napi_default, nullptr}", + " };", + " // Add an array of properties to a ArkTs object.", + " napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);", + " return exports;", + "}", + "EXTERN_C_END" + ] + } +} \ No newline at end of file From 8d79f07188e8e21daccc5d547ae5658fd29b62a4 Mon Sep 17 00:00:00 2001 From: chen-zhongwei050 Date: Mon, 11 Nov 2024 10:16:02 +0800 Subject: [PATCH 2/7] fix napi asyncfunc snippets Signed-off-by: chen-zhongwei050 --- src/vscode_plugin/package.json | 12 ++++++++++++ src/vscode_plugin/snippets/napi_async_snippets.json | 13 +++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/vscode_plugin/package.json b/src/vscode_plugin/package.json index 3d361525..976de547 100644 --- a/src/vscode_plugin/package.json +++ b/src/vscode_plugin/package.json @@ -123,6 +123,18 @@ { "language": "cpp", "path": "./snippets/napi_callback_snippets.json" + }, + { + "language": "cpp", + "path": "./snippets/napi_sync_snippets.json" + }, + { + "language": "cpp", + "path": "./snippets/napi_enum_snippets.json" + }, + { + "language": "cpp", + "path": "./snippets/napi_struct_snippets.json" } ] }, diff --git a/src/vscode_plugin/snippets/napi_async_snippets.json b/src/vscode_plugin/snippets/napi_async_snippets.json index c9eabeb6..1d3d3381 100644 --- a/src/vscode_plugin/snippets/napi_async_snippets.json +++ b/src/vscode_plugin/snippets/napi_async_snippets.json @@ -12,10 +12,23 @@ " OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, \"ASYNC\", \"ExecuteAsyncWork\");", "}", "static void CompleteAsyncWork(napi_env env, napi_status status, void* data) {", + " AsyncData* asyncData = static_cast(data);", + " napi_value callback = nullptr;", + " // Retrieve the js value associated with a reference.", + " napi_get_reference_value(env, asyncData->callbackRef, &callback);", + " // Todo: execute the callback: napi_call_function(env, nullptr, callback, 1, callbackArg, &result);", + " // Delete the napi_ref object and asynchronous work object.", + " napi_delete_reference(env, asyncData->callbackRef);", + " napi_delete_async_work(env, asyncData->work);", + " delete asyncData;", " OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, \"ASYNC\", \"CompleteAsyncWork\");", "}", "napi_value StartAsyncWork(napi_env env, napi_callback_info info)", "{", + " AsyncData* asyncData = new AsyncData();", + " napi_value callback = nullptr;", + " // Convert the callback to napi_ref to extend its lifecycle to prevent it from being garbage-collected.", + " napi_create_reference(env, callback, 1, &asyncData->callbackRef);", " napi_value resourceName = nullptr;", " // Create a js string which is used as the name for the asynchronous work object being created.", " napi_create_string_utf8(env, \"asyncWork\", NAPI_AUTO_LENGTH, &resourceName);", From 7bf15248e8db4d9f4724a22662d3a38d8d16ad9b Mon Sep 17 00:00:00 2001 From: chen-zhongwei050 Date: Wed, 13 Nov 2024 18:00:38 +0800 Subject: [PATCH 3/7] modify async, callback, promise, enum, struct snippets Signed-off-by: chen-zhongwei050 --- .../snippets/napi_async_snippets.json | 56 ------------------- .../snippets/napi_asyncwork_snippets.json | 30 ++++++++++ .../snippets/napi_callback_snippets.json | 24 +------- .../snippets/napi_enum_snippets.json | 33 ++--------- .../snippets/napi_promise_snippets.json | 50 ++++++----------- .../snippets/napi_struct_snippets.json | 34 +++-------- .../snippets/napi_sync_snippets.json | 27 --------- 7 files changed, 61 insertions(+), 193 deletions(-) delete mode 100644 src/vscode_plugin/snippets/napi_async_snippets.json create mode 100644 src/vscode_plugin/snippets/napi_asyncwork_snippets.json delete mode 100644 src/vscode_plugin/snippets/napi_sync_snippets.json diff --git a/src/vscode_plugin/snippets/napi_async_snippets.json b/src/vscode_plugin/snippets/napi_async_snippets.json deleted file mode 100644 index 1d3d3381..00000000 --- a/src/vscode_plugin/snippets/napi_async_snippets.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "Napi Async Func": { - "prefix": "napiasyncfunc", - "body": [ - "struct AsyncData{", - " napi_async_work work;", - " napi_ref callbackRef;", - " // save async work param in.", - " // save async work result.", - "};", - "static void ExecuteAsyncWork(napi_env env, void* data) {", - " OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, \"ASYNC\", \"ExecuteAsyncWork\");", - "}", - "static void CompleteAsyncWork(napi_env env, napi_status status, void* data) {", - " AsyncData* asyncData = static_cast(data);", - " napi_value callback = nullptr;", - " // Retrieve the js value associated with a reference.", - " napi_get_reference_value(env, asyncData->callbackRef, &callback);", - " // Todo: execute the callback: napi_call_function(env, nullptr, callback, 1, callbackArg, &result);", - " // Delete the napi_ref object and asynchronous work object.", - " napi_delete_reference(env, asyncData->callbackRef);", - " napi_delete_async_work(env, asyncData->work);", - " delete asyncData;", - " OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, \"ASYNC\", \"CompleteAsyncWork\");", - "}", - "napi_value StartAsyncWork(napi_env env, napi_callback_info info)", - "{", - " AsyncData* asyncData = new AsyncData();", - " napi_value callback = nullptr;", - " // Convert the callback to napi_ref to extend its lifecycle to prevent it from being garbage-collected.", - " napi_create_reference(env, callback, 1, &asyncData->callbackRef);", - " napi_value resourceName = nullptr;", - " // Create a js string which is used as the name for the asynchronous work object being created.", - " napi_create_string_utf8(env, \"asyncWork\", NAPI_AUTO_LENGTH, &resourceName);", - " // Create an asynchronous work object.", - " napi_create_async_work(env, nullptr, resourceName, ExecuteAsyncWork, CompleteAsyncWork, asyncData, &asyncData->work);", - " // Add the asynchronous work object to a queue.", - " napi_queue_async_work(env, asyncData->work);", - " return nullptr;", - "}", - "EXTERN_C_START", - "// Initialize the module.", - "static napi_value Init(napi_env env, napi_value exports)", - "{", - " // Define properties and methods for a N-API object.", - " napi_property_descriptor desc[] = {", - " { \"startAsyncWork\", nullptr, StartAsyncWork, nullptr, nullptr, nullptr, napi_default, nullptr },", - " };", - " // Add an array of properties to a ArkTs object.", - " napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);", - " return exports;", - "}", - "EXTERN_C_END" - ] - } -} \ No newline at end of file diff --git a/src/vscode_plugin/snippets/napi_asyncwork_snippets.json b/src/vscode_plugin/snippets/napi_asyncwork_snippets.json new file mode 100644 index 00000000..5d3f1a83 --- /dev/null +++ b/src/vscode_plugin/snippets/napi_asyncwork_snippets.json @@ -0,0 +1,30 @@ +{ + "Napi Async Func": { + "prefix": "napiasyncfunc", + "body": [ + "struct AsyncData{", + " napi_async_work work;", + " napi_ref callbackRef;", + " // save async work param in.", + " // save async work result.", + "};", + "static void ExecuteAsyncWork(napi_env env, void* data) {", + " std::this_thread::sleep_for(std::chrono::seconds(2));", + " OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, \"ASYNC\", \"ExecuteAsyncWork\");", + "}", + "static void CompleteAsyncWork(napi_env env, napi_status status, void* data) {", + " // Todo: you can use \"napicallthreadsafefunc\" command that execute the callback.", + " OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, \"ASYNC\", \"CompleteAsyncWork\");", + "}", + "napi_value StartAsyncWork(napi_env env, napi_callback_info info)", + "{", + " // Create an asynchronous work object.", + " napi_create_async_work(env, nullptr, resourceName, ExecuteAsyncWork, CompleteAsyncWork, asyncData, &asyncData->work);", + " // Add the asynchronous work object to a queue.", + " napi_queue_async_work(env, asyncData->work);", + " OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, \"ASYNC\", \"Main thread.\");", + " return nullptr;", + "}" + ] + } +} \ No newline at end of file diff --git a/src/vscode_plugin/snippets/napi_callback_snippets.json b/src/vscode_plugin/snippets/napi_callback_snippets.json index f8589865..e14c06b5 100644 --- a/src/vscode_plugin/snippets/napi_callback_snippets.json +++ b/src/vscode_plugin/snippets/napi_callback_snippets.json @@ -2,28 +2,8 @@ "Napi Callback": { "prefix": "napicallback", "body": [ - "static napi_value CallbackSample(napi_env env, napi_callback_info info)", - "{", - " napi_value callback;", - " napi_value callbackArg[1] = nullptr;", - " napi_value result;", - " // Invokes a js function with the provided arguments and returns the result.", - " napi_call_function(env, nullptr, callback, 1, callbackArg, &result);", - " return nullptr;", - "}", - "EXTERN_C_START", - "// Initialize the module.", - "static napi_value Init(napi_env env, napi_value exports)", - "{", - " // Define properties and methods for a N-API object.", - " napi_property_descriptor desc[] = {", - " { \"callbackSample\", nullptr, CallbackSample, nullptr, nullptr, nullptr, napi_default, nullptr }", - " };", - " // Add an array of properties to a ArkTs object.", - " napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);", - " return exports;", - "}", - "EXTERN_C_END" + "// Invokes a js function with the provided arguments and returns the result.", + "napi_call_function(env, recv, callbackFunc, argc, callbackArg, &result);" ] } } \ No newline at end of file diff --git a/src/vscode_plugin/snippets/napi_enum_snippets.json b/src/vscode_plugin/snippets/napi_enum_snippets.json index e5f5b3fd..5d48fe03 100644 --- a/src/vscode_plugin/snippets/napi_enum_snippets.json +++ b/src/vscode_plugin/snippets/napi_enum_snippets.json @@ -2,34 +2,9 @@ "Napi Enum": { "prefix": "napienum", "body": [ - "napi_value CreateEnumObjectToJs(napi_env env, napi_callback_info info) {", - " napi_status status;", - " // Todo: you can use \"napiint32out\" command that return int32_t value to js.", - " // Todo: you can use \"napiobjectout\" command that return object value to js.", - " // Todo: you can use \"napisetvalue2object\" command that set value to objectOut", - " return objectOut;", - "}", - "napi_value GetEnumValueFromJs(napi_env env, napi_callback_info info)", - "{", - " // Todo: you can use \"napiobjectin\" command that get object value from js.", - " int32_t enumValue;", - " // Todo: you can use \"napiint32in\" command that get int32_t value from js.", - " return nullptr;", - "}", - "EXTERN_C_START", - "// Initialize the module.", - "static napi_value Init(napi_env env, napi_value exports)", - "{", - " // Define promise method for a N-API object.", - " napi_property_descriptor desc[] = {", - " {\"createEnumObjectToJs\", nullptr, CreateEnumObjectToJs, nullptr, nullptr, nullptr, napi_default, nullptr},", - " {\"getEnumValueFromJs\", nullptr, GetEnumValueFromJs, nullptr, nullptr, nullptr, napi_default, nullptr}", - " };", - " // Add an array of properties to a ArkTs object.", - " napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);", - " return exports;", - "}", - "EXTERN_C_END" - ] + "// Todo: you can use \"napiint32in\" or \"napistringutf8in\" command that get int32_t or string value from js.", + "// Todo: you can use \"napiint32out\" or \"napistringutf8out\" command that return int32_t or string value to js" + ], + "description": "enum in 和 out是否要分开" } } \ No newline at end of file diff --git a/src/vscode_plugin/snippets/napi_promise_snippets.json b/src/vscode_plugin/snippets/napi_promise_snippets.json index 7a11abbf..ca43750b 100644 --- a/src/vscode_plugin/snippets/napi_promise_snippets.json +++ b/src/vscode_plugin/snippets/napi_promise_snippets.json @@ -1,37 +1,23 @@ { - "Napi Promise": { - "prefix": "napipromise", + "Napi create promise": { + "prefix": "napicreatepromise", "body": [ - "static napi_value PromiseSample(napi_env env, napi_callback_info info)", - "{", - " napi_value promise;", - " napi_deferred deferred;", - " // Create a new js Promise.", - " napi_create_promise(env, &deferred, &promise);", - " napi_value valueOut = nullptr;", - " bool isResolved = true;", - " if (isResolved) {", - " // Fulfill a js Promise with a given value.", - " napi_resolve_deferred(env, deferred, valueOut);", - " } else {", - " // Reject a js Promise with a given reason.", - " napi_reject_deferred(env, deferred, valueOut);", - " }", - " return promise;", - "}", - "EXTERN_C_START", - "// Initialize the module.", - "static napi_value Init(napi_env env, napi_value exports)", - "{", - " // Define properties and methods for a N-API object.", - " napi_property_descriptor desc[] = {", - " { \"promiseSample\", nullptr, PromiseSample, nullptr, nullptr, nullptr, napi_default, nullptr }", - " };", - " // Add an array of properties to a ArkTs object.", - " napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);", - " return exports;", - "}", - "EXTERN_C_END" + "// Create a new js Promise.", + "napi_create_promise(env, &deferred, &promise);" + ] + }, + "Napi resolve deferred": { + "prefix": "napiresolvedeferred", + "body": [ + "// Fulfill a js Promise with a given value.", + "napi_resolve_deferred(env, deferred, resolution);" + ] + }, + "Napi reject deferred": { + "prefix": "napirejectdeferred", + "body": [ + "// Reject a js Promise with a given reason.", + "napi_reject_deferred(env, deferred, rejection);" ] } } \ No newline at end of file diff --git a/src/vscode_plugin/snippets/napi_struct_snippets.json b/src/vscode_plugin/snippets/napi_struct_snippets.json index 32a90214..8f14dba1 100644 --- a/src/vscode_plugin/snippets/napi_struct_snippets.json +++ b/src/vscode_plugin/snippets/napi_struct_snippets.json @@ -2,32 +2,12 @@ "Napi Struct": { "prefix": "napistruct", "body": [ - "napi_value GetStructValueFromJs(napi_env env, napi_callback_info info)", - "{", - " // Todo: you can use \"napiobjectin\" command that get object value from js.", - " // Todo: you can use \"napigetvaluefromobject\" command that get value from js object.", - " return nullptr;", - "}", - "napi_value CreateStructObjectToJs(napi_env env, napi_callback_info info)", - "{", - " // Todo: you can use \"napiobjectout\" command that return object to js.", - " // Todo: you can use \"napisetvalue2object\" command that set value to objectOut.", - " return objectOut.", - "}", - "EXTERN_C_START", - "// Initialize the module.", - "static napi_value Init(napi_env env, napi_value exports)", - "{", - " // Define properties and methods for a N-API object.", - " napi_property_descriptor desc[] = {", - " { \"getStructValueFromJs\", nullptr, GetStructValueFromJs, nullptr, nullptr, nullptr, napi_default, nullptr },", - " { \"createStructObjectToJs\", nullptr, CreateStructObjectToJs, nullptr, nullptr, nullptr, napi_default, nullptr }", - " };", - " // Add an array of properties to a ArkTs object.", - " napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);", - " return exports;", - "}", - "EXTERN_C_END" - ] + "// Todo: you can use \"napiobjectin\" command that get object value from js.", + "// Todo: you can use \"napigetvaluefromobject\" command that get value from js object.", + "// Todo: business code.", + "// Todo: you can use \"napiobjectout\" command that return object to js.", + "// Todo: you can use \"napisetvalue2object\" command that set value to objectOut." + ], + "description": "是否需要将struct的in和out分开" } } \ No newline at end of file diff --git a/src/vscode_plugin/snippets/napi_sync_snippets.json b/src/vscode_plugin/snippets/napi_sync_snippets.json deleted file mode 100644 index a20d2608..00000000 --- a/src/vscode_plugin/snippets/napi_sync_snippets.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "Napi SyncFunc": { - "prefix": "napisyncfunc", - "body": [ - "static napi_value Add(napi_env env, napi_callback_info info)", - "{", - " // Todo: you can use \"napiobjectin\" command that get object param from js.", - " // Todo: you can use \"napidoublein\" command that get double param from js.", - " // Todo: you can use \"napidoubleout\" command that return double value to js.", - " return doubleOut;", - "}", - "EXTERN_C_START", - "// Initialize the module.", - "static napi_value Init(napi_env env, napi_value exports)", - "{", - " // Define promise method for a N-API object.", - " napi_property_descriptor desc[] = {", - " {\"add\", nullptr, Add, nullptr, nullptr, nullptr, napi_default, nullptr}", - " };", - " // Add an array of properties to a ArkTs object.", - " napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);", - " return exports;", - "}", - "EXTERN_C_END" - ] - } -} \ No newline at end of file From f8900a5da197909da4c6ba37fcd3d5762485d43c Mon Sep 17 00:00:00 2001 From: chen-zhongwei050 Date: Wed, 13 Nov 2024 18:02:00 +0800 Subject: [PATCH 4/7] modify package.json Signed-off-by: chen-zhongwei050 --- src/vscode_plugin/package.json | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/vscode_plugin/package.json b/src/vscode_plugin/package.json index 976de547..15b43488 100644 --- a/src/vscode_plugin/package.json +++ b/src/vscode_plugin/package.json @@ -114,7 +114,7 @@ }, { "language": "cpp", - "path": "./snippets/napi_async_snippets.json" + "path": "./snippets/napi_asyncwork_snippets.json" }, { "language": "cpp", @@ -124,10 +124,6 @@ "language": "cpp", "path": "./snippets/napi_callback_snippets.json" }, - { - "language": "cpp", - "path": "./snippets/napi_sync_snippets.json" - }, { "language": "cpp", "path": "./snippets/napi_enum_snippets.json" From 132e6dd78f7ca54a7b203db045ebd67890640e6f Mon Sep 17 00:00:00 2001 From: chen-zhongwei050 Date: Thu, 14 Nov 2024 09:48:11 +0800 Subject: [PATCH 5/7] modify enum, struct snippets Signed-off-by: chen-zhongwei050 --- src/vscode_plugin/snippets/napi_enum_snippets.json | 5 +++-- src/vscode_plugin/snippets/napi_struct_snippets.json | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/vscode_plugin/snippets/napi_enum_snippets.json b/src/vscode_plugin/snippets/napi_enum_snippets.json index 5d48fe03..dafd8c31 100644 --- a/src/vscode_plugin/snippets/napi_enum_snippets.json +++ b/src/vscode_plugin/snippets/napi_enum_snippets.json @@ -2,9 +2,10 @@ "Napi Enum": { "prefix": "napienum", "body": [ + "// Enum in.", "// Todo: you can use \"napiint32in\" or \"napistringutf8in\" command that get int32_t or string value from js.", + "// Enum out.", "// Todo: you can use \"napiint32out\" or \"napistringutf8out\" command that return int32_t or string value to js" - ], - "description": "enum in 和 out是否要分开" + ] } } \ No newline at end of file diff --git a/src/vscode_plugin/snippets/napi_struct_snippets.json b/src/vscode_plugin/snippets/napi_struct_snippets.json index 8f14dba1..69feb2eb 100644 --- a/src/vscode_plugin/snippets/napi_struct_snippets.json +++ b/src/vscode_plugin/snippets/napi_struct_snippets.json @@ -2,12 +2,12 @@ "Napi Struct": { "prefix": "napistruct", "body": [ + "// Struct in", "// Todo: you can use \"napiobjectin\" command that get object value from js.", "// Todo: you can use \"napigetvaluefromobject\" command that get value from js object.", - "// Todo: business code.", + "// Struct out", "// Todo: you can use \"napiobjectout\" command that return object to js.", "// Todo: you can use \"napisetvalue2object\" command that set value to objectOut." - ], - "description": "是否需要将struct的in和out分开" + ] } } \ No newline at end of file From 895b20536e936c02ce2fbb883dcef96a81bc9df2 Mon Sep 17 00:00:00 2001 From: chen-zhongwei050 Date: Thu, 14 Nov 2024 10:35:15 +0800 Subject: [PATCH 6/7] fix asyncwork snippets bug Signed-off-by: chen-zhongwei050 --- src/vscode_plugin/snippets/napi_asyncwork_snippets.json | 2 +- src/vscode_plugin/snippets/napi_callback_snippets.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vscode_plugin/snippets/napi_asyncwork_snippets.json b/src/vscode_plugin/snippets/napi_asyncwork_snippets.json index 5d3f1a83..3adeb89d 100644 --- a/src/vscode_plugin/snippets/napi_asyncwork_snippets.json +++ b/src/vscode_plugin/snippets/napi_asyncwork_snippets.json @@ -13,7 +13,7 @@ " OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, \"ASYNC\", \"ExecuteAsyncWork\");", "}", "static void CompleteAsyncWork(napi_env env, napi_status status, void* data) {", - " // Todo: you can use \"napicallthreadsafefunc\" command that execute the callback.", + " // Todo: you can use \"napicallfunc\" command that execute the callback.", " OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, \"ASYNC\", \"CompleteAsyncWork\");", "}", "napi_value StartAsyncWork(napi_env env, napi_callback_info info)", diff --git a/src/vscode_plugin/snippets/napi_callback_snippets.json b/src/vscode_plugin/snippets/napi_callback_snippets.json index e14c06b5..4ef3e4da 100644 --- a/src/vscode_plugin/snippets/napi_callback_snippets.json +++ b/src/vscode_plugin/snippets/napi_callback_snippets.json @@ -1,6 +1,6 @@ { "Napi Callback": { - "prefix": "napicallback", + "prefix": "napicallfunc", "body": [ "// Invokes a js function with the provided arguments and returns the result.", "napi_call_function(env, recv, callbackFunc, argc, callbackArg, &result);" From 5ea5aeeb94f5da612354892dd26123292e31ca86 Mon Sep 17 00:00:00 2001 From: chen-zhongwei050 Date: Thu, 14 Nov 2024 11:51:02 +0800 Subject: [PATCH 7/7] fix asyncwork snippets bug Signed-off-by: chen-zhongwei050 --- src/vscode_plugin/snippets/napi_asyncwork_snippets.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vscode_plugin/snippets/napi_asyncwork_snippets.json b/src/vscode_plugin/snippets/napi_asyncwork_snippets.json index 3adeb89d..1ff8a0eb 100644 --- a/src/vscode_plugin/snippets/napi_asyncwork_snippets.json +++ b/src/vscode_plugin/snippets/napi_asyncwork_snippets.json @@ -1,6 +1,6 @@ { "Napi Async Func": { - "prefix": "napiasyncfunc", + "prefix": "napiasyncwork", "body": [ "struct AsyncData{", " napi_async_work work;",