本章節(jié)主要介紹下如何自動(dòng)生成文件頭部與函數(shù)注釋相關(guān);學(xué)會(huì)本文檔,將可以自動(dòng)給你添加代碼注釋,并且有一個(gè)統(tǒng)一標(biāo)準(zhǔn),不再那么凌亂,好好的工具配置一次就好好用它既可。
以下環(huán)境在大名鼎鼎的VSCode 下進(jìn)行。
前言在寫代碼過(guò)程中,是否看到那些大廠的代碼寫的注釋都比較規(guī)范和漂亮,曾經(jīng)的自己還在那里CV。修改代碼都會(huì)涉及創(chuàng)建文件創(chuàng)建新的函數(shù),但在這過(guò)程中,如何去規(guī)范或者絲滑去寫好這部分,其實(shí)在代碼的世界里面只要你好好應(yīng)用好工具,一切都變得簡(jiǎn)單,因?yàn)楣ぞ邥?huì)Auto,在這個(gè)過(guò)程中,你只需要去修改一點(diǎn)點(diǎn)東西既可。插件1:koroFileHeader采用插件1的效果:
文件注釋效果:
fnbvieglqrs64017880726.png (30.62 KB, 下載次數(shù): 0)
下載附件
保存到相冊(cè)
fnbvieglqrs64017880726.png
2024-9-18 18:48 上傳
函數(shù)注釋效果:
hge0j211ecd64017880826.png (28.22 KB, 下載次數(shù): 0)
下載附件
保存到相冊(cè)
hge0j211ecd64017880826.png
2024-9-18 18:48 上傳
f12eqxtvqku64017880926.png (21.02 KB, 下載次數(shù): 0)
下載附件
保存到相冊(cè)
f12eqxtvqku64017880926.png
2024-9-18 18:48 上傳
出現(xiàn)快捷鍵不能用的問(wèn)題:
按下ctrl+shift+p,
1.修改文件頭快捷鍵:搜索fileheader,選擇右側(cè)設(shè)置圖標(biāo),就進(jìn)入按鍵綁定頁(yè)面。2.修改函數(shù)注釋快捷鍵:搜索cursorTip,選擇右側(cè)設(shè)置圖標(biāo),就進(jìn)入按鍵綁定頁(yè)面。
CommandKeybindingWhenSourcefileheaderCtrl+Alt+IeditorTextFocusUsercursorTipCtrl+Alt+TeditorTextFocusUser使用方法:Ctrl+Alt+I將會(huì)插入文件頭部注釋;Ctrl+Alt+T將會(huì)對(duì)當(dāng)前鼠標(biāo)函數(shù)位置所在函數(shù)進(jìn)行函數(shù)注釋;在文件頭部"fileheader.configObj"到"files.exclude"settings 文件配置【配置還包含其他插件配置】:該配置文件路徑:C:\Users\你的用戶名\AppData\Roaming\Code\User\settings.json{ "cmake.configureOnOpen": true, "files.autoGuessEncoding": true, "editor.formatOnType": true, "[c]": { "editor.defaultFormatter": "ms-vscode.cpptools" }, "security.workspace.trust.untrustedFiles": "open", "workbench.startupEditor": "none", "redhat.telemetry.enabled": true, "http.proxyAuthorization": null, "cSpell.languageSettings": [], "http.proxySupport": "on", "editor.inlineSuggest.enabled": true, "boot-java.rewrite.reconcile": true, "todohighlight.defaultStyle": {
}, "todohighlight.exclude": [
"**/node_modules/**", "**/bower_components/**", "**/dist/**", "**/build/**", "**/.vscode/**", "**/.github/**", "**/_output/**", "**/*.min.*", "**/*.map", "**/.next/**" ], "fileheader.configObj": { "createFileTime": true, "language": { "languagetest": { "head": "/$$", "middle": " $ @", "end": " $/", "functionSymbol": { "head": "/** ", "middle": " * @", "end": " */" }, "functionParams": "js" } }, "autoAdd": true, "autoAddLine": 100, "autoAlready": true, "annotationStr": { "head": "/*", "middle": " * @", "end": " */", "use": false }, "headInsertLine": { "php": 2, "sh": 2 }, "beforeAnnotation": { "文件后綴": "該文件后綴的頭部注釋之前添加某些內(nèi)容" }, "afterAnnotation": { "文件后綴": "該文件后綴的頭部注釋之后添加某些內(nèi)容" }, "specialOptions": { "特殊字段": "自定義比如LastEditTime/LastEditors" }, "switch": { "newlineAddAnnotation": true }, "supportAutoLanguage": [], "prohibitAutoAdd": [ "json" ], "folderBlacklist": [ "node_modules", "文件夾禁止自動(dòng)添加頭部注釋" ], "prohibitItemAutoAdd": [ "項(xiàng)目的全稱, 整個(gè)項(xiàng)目禁止自動(dòng)添加頭部注釋, 可以使用快捷鍵添加" ], "moveCursor": true, "dateFormat": "YYYY-MM-DD HH:mm:ss", "atSymbol": [ "@", "@" ], "atSymbolObj": { "文件后綴": [ "頭部注釋@符號(hào)", "函數(shù)注釋@符號(hào)" ] }, "colon": [ ": ", ": " ], "colonObj": { "文件后綴": [ "頭部注釋冒號(hào)", "函數(shù)注釋冒號(hào)" ] }, "filePathColon": "路徑分隔符替換", "showErrorMessage": false, "writeLog": false, "wideSame": false, "wideNum": 13, "functionWideNum": 0, "CheckFileChange": false, "createHeader": false, "useWorker": false, "designAddHead": false, "headDesignName": "random", "headDesign": false, "cursorModeInternalAll": {}, "openFunctionParamsCheck": true, "functionParamsShape": [ "{", "}" ], "functionBlankSpaceAll": {}, "functionTypeSymbol": "*", "typeParamOrder": "type param", "customHasHeadEnd": {}, "throttleTime": 10000, "functionParamAddStr": "", "NoMatchParams": "no show param" }, "fileheader.cursorMode": { "function ": "", "description ": "", "author ": "git config user.name && git config user.email", "param ": "", "return ": "", }, "fileheader.customMade": { "FileName": "${file_name}", "Description": "", "Author": "git config user.name && git config user.email", "Version": "v0.0.1", "Date": "Do not edit", "LastEditTime ": "Do not Edit", "custom_string_obkoro1_copyright": "Copyright ${now_year} HywelStar, All Rights Reserved. ", // 版權(quán)聲明 保留所有權(quán)利 自動(dòng)替換年份 "custom_string_obkoro1_date": "Do not edit", // 版權(quán)時(shí)間}, "files.exclude": { "**/*.o": true }, "github.copilot.editor.enableAutoCompletions": true, "STM32VSCodeExtension.projectCreator.executablePath": "f:\Program Files\STMicroelectronics\STM32Cube\STM32CubeMX\STM32CubeMX.exe", "python.analysis.packageIndexDepths": [ { "name": "sklearn", "depth": 2 }, { "name": "matplotlib", "depth": 2 }, { "name": "scipy", "depth": 2 }, { "name": "django", "depth": 2 }, { "name": "flask", "depth": 2 }, { "name": "fastapi", "depth": 2 } ], "settingsSync.ignoredExtensions": [], "cSpell.userWords": [ "Hywel" ], "remote.SSH.configFile": "G:\Remote_ssh\config", "remote.SSH.showLoginTerminal": true, "remote.SSH.remotePlatform": { "192.168.17.104": "linux" },"C_Cpp.intelliSenseEngine": "disabled","diffEditor.ignoreTrimWhitespace": false}插件2:Doxygen Documentation Generator效果文件頭注釋:
k1zi1winy3364017881026.png (29.44 KB, 下載次數(shù): 1)
下載附件
保存到相冊(cè)
k1zi1winy3364017881026.png
2024-9-18 18:48 上傳
效果函數(shù)投注釋:
gok3qslzkph64017881126.png (32.17 KB, 下載次數(shù): 2)
下載附件
保存到相冊(cè)
gok3qslzkph64017881126.png
2024-9-18 18:48 上傳
wwenks4kyk264017881226.png (15.34 KB, 下載次數(shù): 1)
下載附件
保存到相冊(cè)
wwenks4kyk264017881226.png
2024-9-18 18:48 上傳
setting.json 內(nèi)容
當(dāng)前setting.json 為項(xiàng)目的setting,可以改到
C:\Users\你的用戶名\AppData\Roaming\Code\User\settings.json路徑下。
{ "doxdocgen.file.copyrightTag": [ "Copyright (C) 2024-2034 HywelStar.", "All rights reserved.", "", ],
"doxdocgen.file.customTag": [ "@version v0.1", "", "@revision history:", " {date} - Initial version." ],
"doxdocgen.file.fileTemplate": "@file Filename without the absolute path", "doxdocgen.generic.authorTag": "@author HywelStar(hywelstar@163.com)", "doxdocgen.generic.dateTemplate": "@date {date}", "doxdocgen.generic.briefTemplate": "@brief Brief description", "doxdocgen.generic.returnTemplate": "@return Description of return value", "doxdocgen.generic.paramTemplate": "@param {param} in/out Description of parameter", "doxdocgen.generic.customTags": [ "@warning Special notes such as non-reentrancy, blocking issues, etc.", "@note Significant modifications" ],
"doxdocgen.file.fileOrder": [ "copyright", "", // New line "file", "brief", "author", "date", "custom" ],
"doxdocgen.generic.order": [ "brief", "param", "return", "custom" ], "C_Cpp.errorSquiggles": "enabled", "files.associations": { "*.def": "c" }}
總結(jié)對(duì)比本章節(jié)主要對(duì)對(duì)于使用vscode 平臺(tái)使用文件頭部和函數(shù)頭部注釋功能,選擇上面任何一種都可以,不過(guò)筆者使用起來(lái)的感受的話,想要速度快一些可以采用第二種,對(duì)于第一種來(lái)說(shuō)快捷鍵需要函數(shù)注釋還是文件注釋總是有些遲鈍,但是第一種來(lái)說(shuō)定制化和智能化會(huì)更高一些對(duì)時(shí)間修改都會(huì)有自動(dòng)記錄。對(duì)于團(tuán)隊(duì)合作看大家看中哪一種,方面后面代碼一些規(guī)范化,采用同一種形態(tài)的注釋也會(huì)更加完美一些。根據(jù)自身選擇,簡(jiǎn)單就第二種,復(fù)雜化智能化就第一種。另外對(duì)于其他平臺(tái)暫時(shí)還沒(méi)有研究,對(duì)于老牌的source insight, eclipse 都有這樣類似的設(shè)置方式。end
一口Linux
關(guān)注,回復(fù)【1024】海量Linux資料贈(zèng)送
精彩文章合集
文章推薦
?【專輯】ARM?【專輯】粉絲問(wèn)答?【專輯】所有原創(chuàng)?【專輯】linux入門?【專輯】計(jì)算機(jī)網(wǎng)絡(luò)?【專輯】Linux驅(qū)動(dòng)?【干貨】嵌入式驅(qū)動(dòng)工程師學(xué)習(xí)路線?【干貨】Linux嵌入式所有知識(shí)點(diǎn)-思維導(dǎo)圖 |