vscode配置
1. 编辑界面右侧显示80字符分割线
界面左上角选择"文件->首选项->设置",进入设置界面,选择"文本编辑器->Rulers->在setting.json中编辑",或者直接所搜rulers
2. 添加注释头
{
"add brief":
{
"prefix": ".brief",
"body": [
"",
"/**",
" * @brief : $1",
" */",
"$2",
],
},
"add enum template":
{
"prefix": ".enumTemplate",
"body": [
"",
"/**",
" * @brief : 错误代码定义",
" */",
"typedef enum",
"{",
" ERR_SUCCESS = 0, //< 成功",
" ERR_FAILED = -1, //< 失败",
" ERR_INVALID_PARAMETER = -1000, //< 无效参数",
" ERR_NOT_INITED, //< 未初始化",
" ERR_INITED, //< 已初始化$1",
"} ErrCode;",
""
],
},
"Add File Header": {
"prefix": ".fileHader",
"body": [
"/**"
" * @file : ${TM_FILENAME}",
" * @brief : $1",
" * @version : V1.0.0",
" * @date : ${CURRENT_YEAR}-${CURRENT_MONTH}-${CURRENT_DATE}",
" */",
"#ifndef __${TM_FILENAME_BASE/(.*)/${1:/upcase}/}_H__",
"#define __${TM_FILENAME_BASE/(.*)/${1:/upcase}/}_H__",
"",
"/*================================= Includes =================================*/",
"$2",
"",
"/*================================= Defines ==================================*/",
"$3",
"",
"/*============================= Static Functions =============================*/",
"$4",
"",
"/*============================= Public Functions =============================*/",
"$5",
"",
"#endif /* __${TM_FILENAME_BASE/(.*)/${1:/upcase}/}_H__ */",
],
"description": "Add file describe"
},
"add func header":{
"prefix": ".funcHeader",
"body": [
"",
"/**",
" * @brief : $1",
" * @param [$2] $3 : $4",
" * @param [$5] $6 : $7",
" * @return 返回错误码ErrCode",
" */",
]
},
"check conditon": {
"prefix": ".checkConditon",
"body": [
"#define CHECK_CONDITION(condition, error_code, error_message) \\",
" do { \\",
" if (!(condition)) { \\",
" $1fprintf(stderr, \"Error: %s\\n\", error_message); \\",
" return error_code; \\",
" } \\",
" } while (0) $2",
"$3",
]
},
"check param": {
"prefix": ".checkParam",
"body": [
"#define CHECK_PARAM(param, error_code) \\",
" do { \\",
" if (!(param)) { \\",
" $1fprintf(stderr, \"Error: invalid param\\n\"); \\",
" return error_code; \\",
" } \\",
" } while (0) $2",
"$3",
]
},
"select timeout": {
"prefix": ".select",
"body": [
"#include <sys/select.h>",
"#include <sys/time.h>",
"#include <unistd.h>",
"$1",
"/**",
" * @brief : select_with_timeout",
" * @param [in] fd : 文件描述符",
" * @param [in] timeout_ms : 超时时间(ms)",
" * @return true : 文件描述符准备好",
" * @return false : 超时或出错",
" */",
"bool select_with_timeout(int fd, int timeout_ms) {",
" fd_set read_set;",
" FD_ZERO(&read_set);",
" FD_SET(fd, &read_set);",
"",
" // 设置超时时间",
" struct timeval tv;",
" tv.tv_sec = timeout_ms / 1000;",
" tv.tv_usec = (timeout_ms % 1000) * 1000;",
"",
" // 调用 select 函数",
" int ready = ::select(fd + 1, &read_set, nullptr, nullptr, &tv);",
"",
" if (ready == -1) { ",
" $1fprintf(stderr, \"Error: %s\\n\", strerror(errno));",
" return false;",
" }",
"",
" // 检查文件描述符是否准备好",
" return ready > 0 && FD_ISSET(fd, &read_set);",
"}",
"",
]
},
"delete class functions": {
"prefix": ".deleteClassFunctions",
"body": [
"$1(const $1 &) = delete;",
"$1($1 &&) = delete;",
"$1 &operator=(const $1 &) = delete;",
"$1 &operator=($1 &&) = delete;",
"",
]
},
"class define": {
"prefix": ".class",
"body": [
"class $1"
"{",
"public:",
" $1() = default;",
" ${2:virtual }~$1() = default;",
"",
" $1(const $1 &) = delete;",
" $1($1 &&) = delete;",
" $1 &operator=(const $1 &) = delete;",
" $1 &operator=($1 &&) = delete;",
"",
"protected:",
"",
"private:",
" $3",
"};",
"$4"
]
},
}