本章節(jié)主要介紹下如何自動生成文件頭部與函數(shù)注釋相關(guān);學(xué)會本文檔,將可以自動給你添加代碼注釋,并且有一個統(tǒng)一標(biāo)準(zhǔn),不再那么凌亂,好好的工具配置一次就好好用它既可。
以下環(huán)境在大名鼎鼎的VSCode 下進(jìn)行。
前言在寫代碼過程中,是否看到那些大廠的代碼寫的注釋都比較規(guī)范和漂亮,曾經(jīng)的自己還在那里CV。修改代碼都會涉及創(chuàng)建文件創(chuàng)建新的函數(shù),但在這過程中,如何去規(guī)范或者絲滑去寫好這部分,其實(shí)在代碼的世界里面只要你好好應(yīng)用好工具,一切都變得簡單,因?yàn)楣ぞ邥嗀uto,在這個過程中,你只需要去修改一點(diǎn)點(diǎn)東西既可。插件1:koroFileHeader采用插件1的效果:
文件注釋效果:
fnbvieglqrs64017880726.png (30.62 KB, 下載次數(shù): 0)
下載附件
保存到相冊
fnbvieglqrs64017880726.png
2024-9-18 18:48 上傳
函數(shù)注釋效果:
hge0j211ecd64017880826.png (28.22 KB, 下載次數(shù): 0)
下載附件
保存到相冊
hge0j211ecd64017880826.png
2024-9-18 18:48 上傳
f12eqxtvqku64017880926.png (21.02 KB, 下載次數(shù): 0)
下載附件
保存到相冊
f12eqxtvqku64017880926.png
2024-9-18 18:48 上傳
出現(xiàn)快捷鍵不能用的問題:
按下ctrl+shift+p,
1.修改文件頭快捷鍵:搜索fileheader,選擇右側(cè)設(shè)置圖標(biāo),就進(jìn)入按鍵綁定頁面。2.修改函數(shù)注釋快捷鍵:搜索cursorTip,選擇右側(cè)設(shè)置圖標(biāo),就進(jìn)入按鍵綁定頁面。
CommandKeybindingWhenSourcefileheaderCtrl+Alt+IeditorTextFocusUsercursorTipCtrl+Alt+TeditorTextFocusUser使用方法:Ctrl+Alt+I將會插入文件頭部注釋;Ctrl+Alt+T將會對當(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", "文件夾禁止自動添加頭部注釋" ], "prohibitItemAutoAdd": [ "項(xiàng)目的全稱, 整個項(xiàng)目禁止自動添加頭部注釋, 可以使用快捷鍵添加" ], "moveCursor": true, "dateFormat": "YYYY-MM-DD HH:mm:ss", "atSymbol": [ "@", "@" ], "atSymbolObj": { "文件后綴": [ "頭部注釋@符號", "函數(shù)注釋@符號" ] }, "colon": [ ": ", ": " ], "colonObj": { "文件后綴": [ "頭部注釋冒號", "函數(shù)注釋冒號" ] }, "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)利 自動替換年份 "custom_string_obkoro1_date": "Do not edit", // 版權(quán)時間}, "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)
下載附件
保存到相冊
k1zi1winy3364017881026.png
2024-9-18 18:48 上傳
效果函數(shù)投注釋:
gok3qslzkph64017881126.png (32.17 KB, 下載次數(shù): 0)
下載附件
保存到相冊
gok3qslzkph64017881126.png
2024-9-18 18:48 上傳
wwenks4kyk264017881226.png (15.34 KB, 下載次數(shù): 0)
下載附件
保存到相冊
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é)對比本章節(jié)主要對對于使用vscode 平臺使用文件頭部和函數(shù)頭部注釋功能,選擇上面任何一種都可以,不過筆者使用起來的感受的話,想要速度快一些可以采用第二種,對于第一種來說快捷鍵需要函數(shù)注釋還是文件注釋總是有些遲鈍,但是第一種來說定制化和智能化會更高一些對時間修改都會有自動記錄。對于團(tuán)隊(duì)合作看大家看中哪一種,方面后面代碼一些規(guī)范化,采用同一種形態(tài)的注釋也會更加完美一些。根據(jù)自身選擇,簡單就第二種,復(fù)雜化智能化就第一種。另外對于其他平臺暫時還沒有研究,對于老牌的source insight, eclipse 都有這樣類似的設(shè)置方式。end
一口Linux
關(guān)注,回復(fù)【1024】海量Linux資料贈送
精彩文章合集
文章推薦
?【專輯】ARM?【專輯】粉絲問答?【專輯】所有原創(chuàng)?【專輯】linux入門?【專輯】計(jì)算機(jī)網(wǎng)絡(luò)?【專輯】Linux驅(qū)動?【干貨】嵌入式驅(qū)動工程師學(xué)習(xí)路線?【干貨】Linux嵌入式所有知識點(diǎn)-思維導(dǎo)圖 |