转载自https://zhuanlan.zhihu.com/p/647274361
安装插件
安装插件“Doxygen Documentation Generator”,用来生成注释。
安装插件”C/C++ Snippets”,用来生成文件头、代码块分割线等。
插件设置
所需文件(见下方)

图1设置文件
Doxygen插件设置
点击“文件”—>”首选项”—>”设置”—>”拓展”—>”Doxygen Docume…”—>”在settings.json中编辑”,在打开的settings.json文件中粘贴图1“doxygen_settings.json”文件中的内容。

图2 Doxygen设置
C/C++ Snippets插件设置
按下快捷键“Ctrl+Shift+P”,在弹出的窗口中输入snip,点击筛选出来的“首选项:配置用户代码片段”,如下图所示。

图3 Snippets配置1
点击“新建全局代码片段文件”,如下图所示。

图4 Snippets配置2
输入要新建的文件名,如“stm32“,并按回车键确认。
将图1中“stm32.code-snippets“文件内容复制到新生成的文件中并保存。
使用
添加文件头
打开一个文件,例如“test.h“。
在文件最上方第一行输入“/**“并回车,将自动生成文件头注释,如下图所示。

添加.h文件防重复编译代码
输入“.hinit“并回车,将自动生成防重复编译相关代码、CPP兼容相关代码和程序块分割线,如下图所示。

添加函数注释
在“function“代码段内声明一个函数后,在函数名上方输入”/**“并回车,将自动生成函数注释,如下图所示。添加数据类型的注释方法与此相同。

图7 函数注释
添加main.c文件表格
打开main.c文件。
输入“.table“并回车,将自动生成表格相关注释。
另外,输入“.line“并回车,即可出现代码块分割线,如下图所示。

doxygen_setting.json
{
"doxdocgen.generic.linesToGet": 2,
"doxdocgen.generic.authorName": "xxx",
"doxdocgen.generic.authorEmail": "xxx@xxx.com",
"doxdocgen.generic.useGitUserEmail": true,
"doxdocgen.generic.useGitUserName": true,
"doxdocgen.generic.authorTag": "@author{indent:12} {author} ({email})",
"doxdocgen.file.fileTemplate": "@file{indent:12} {name}",
"doxdocgen.file.versionTag": "@version{indent:12} 0.1",
"doxdocgen.file.copyrightTag": ["@copyright{indent:12} xxxx技有限公司"],
"doxdocgen.file.customTag": ["*****************************************************************************"],
"doxdocgen.generic.briefTemplate": "@brief{indent:12} {text}",
"doxdocgen.generic.dateTemplate": "@date{indent:12} {date}",
"doxdocgen.generic.paramTemplate": "@param{indent:12} {param} ",
"doxdocgen.generic.returnTemplate": "@return{indent:12} {type} ",
"doxdocgen.file.fileOrder": [
"custom",
"file",
"brief",
"author",
"date",
"copyright",
"custom"
],
"doxdocgen.generic.order": [
"brief",
"empty",
"tparam",
"param",
"return",
"custom"
]
}
stm32.code-snippets
{
// Place your 全局 snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
// Example:
// "Print to console": {
// "scope": "javascript,typescript",
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"MainPage Table": {
"prefix": ".table",
"body": [
"",
"/**@mainpage",
" *<table>",
" *<tr><th>项目名称 <td>",
" *<tr><th>设计负责人 <td>",
" *<tr><th>版权 <td>xxxx科技有限公司",
" </table>",
"",
" @section ",
" * ",
"",
" @section ",
" * ",
"",
" @section ",
" * ",
" */",
"",
],
"description": "MainPage Table"
},
"Avoid Repetition": {
"prefix": ".hinit",
"body": [
"\n#ifndef ${1:${TM_FILENAME/(.*)\\.h$/${1:/upcase}_H/i}} \n#define $1 \n\n${2:#ifdef __cplusplus\nextern \"C\"{\n#endif}",
"",
"/*----------------------------------include-----------------------------------*/",
"",
"/*-----------------------------------macro------------------------------------*/",
"",
"/*----------------------------------typedef-----------------------------------*/",
"",
"/*----------------------------------variable----------------------------------*/",
"",
"/*-------------------------------------os-------------------------------------*/",
"",
"/*----------------------------------function----------------------------------*/",
"",
"/*------------------------------------test------------------------------------*/",
"",
"#ifdef __cplusplus",
"}",
"#endif",
"",
"#endif\t/* $1 */\n"
],
"description": "Avoid Repetition"
},
"Code Block Separation Line": {
"prefix": ".line",
"body": [
"",
"/*----------------------------------include-----------------------------------*/",
"",
"/*-----------------------------------macro------------------------------------*/",
"",
"/*----------------------------------typedef-----------------------------------*/",
"",
"/*----------------------------------variable----------------------------------*/",
"",
"/*-------------------------------------os-------------------------------------*/",
"",
"/*----------------------------------function----------------------------------*/",
"",
"/*------------------------------------test------------------------------------*/",
"",
],
"description": "Avoid Repetition"
}
}