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