本章節(jié)主要介紹下如何自動(dòng)生成文件頭部與函數(shù)注釋相關(guān);學(xué)會(huì)本文檔,將可以自動(dòng)給你添加代碼注釋?zhuān)⑶矣幸粋(gè)統(tǒng)一標(biāo)準(zhǔn),不再那么凌亂,好好的工具配置一次就好好用它既可。
以下環(huán)境在大名鼎鼎的VSCode 下進(jìn)行。
前言在寫(xiě)代碼過(guò)程中,是否看到那些大廠(chǎng)的代碼寫(xiě)的注釋都比較規(guī)范和漂亮,曾經(jīng)的自己還在那里CV。修改代碼都會(huì)涉及創(chuàng)建文件創(chuàng)建新的函數(shù),但在這過(guò)程中,如何去規(guī)范或者絲滑去寫(xiě)好這部分,其實(shí)在代碼的世界里面只要你好好應(yīng)用好工具,一切都變得簡(jiǎn)單,因?yàn)楣ぞ邥?huì)Auto,在這個(gè)過(guò)程中,你只需要去修改一點(diǎn)點(diǎn)東西既可。插件1:koroFileHeader采用插件1的效果:
文件注釋效果:
v032bs1jfrk64010792341.png (30.62 KB, 下載次數(shù): 0)
下載附件
保存到相冊(cè)
v032bs1jfrk64010792341.png
2024-9-8 18:51 上傳
函數(shù)注釋效果:
pkjvhcbfhjk64010792441.png (28.22 KB, 下載次數(shù): 0)
下載附件
保存到相冊(cè)
pkjvhcbfhjk64010792441.png
2024-9-8 18:51 上傳
hrx3kidakuf64010792541.png (21.02 KB, 下載次數(shù): 0)
下載附件
保存到相冊(cè)
hrx3kidakuf64010792541.png
2024-9-8 18:51 上傳
出現(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ì)插入文件頭部注釋?zhuān)籆trl+Alt+T將會(huì)對(duì)當(dāng)前鼠標(biāo)函數(shù)位置所在函數(shù)進(jìn)行函數(shù)注釋?zhuān)?/u>在文件頭部"fileheader.configObj"到"files.exclude"settings 文件配置【配置還包含其他插件配置】:該配置文件路徑:C:\Users\你的用戶(hù)名\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)目的全稱(chē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效果文件頭注釋?zhuān)?br />
1x3mpi1ubga64010792641.png (29.44 KB, 下載次數(shù): 0)
下載附件
保存到相冊(cè)
1x3mpi1ubga64010792641.png
2024-9-8 18:51 上傳
效果函數(shù)投注釋?zhuān)?br />
le0tchjy1he64010792742.png (32.17 KB, 下載次數(shù): 1)
下載附件
保存到相冊(cè)
le0tchjy1he64010792742.png
2024-9-8 18:51 上傳
bkrqomil3fd64010792842.png (15.34 KB, 下載次數(shù): 0)
下載附件
保存到相冊(cè)
bkrqomil3fd64010792842.png
2024-9-8 18:51 上傳
setting.json 內(nèi)容
當(dāng)前setting.json 為項(xiàng)目的setting,可以改到
C:\Users\你的用戶(hù)名\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)的感受的話(huà),想要速度快一些可以采用第二種,對(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 都有這樣類(lèi)似的設(shè)置方式。end
一口Linux
關(guān)注,回復(fù)【1024】海量Linux資料贈(zèng)送
精彩文章合集
文章推薦
?【專(zhuān)輯】ARM?【專(zhuān)輯】粉絲問(wèn)答?【專(zhuān)輯】所有原創(chuàng)?【專(zhuān)輯】linux入門(mén)?【專(zhuān)輯】計(jì)算機(jī)網(wǎng)絡(luò)?【專(zhuān)輯】Linux驅(qū)動(dòng)?【干貨】嵌入式驅(qū)動(dòng)工程師學(xué)習(xí)路線(xiàn)?【干貨】Linux嵌入式所有知識(shí)點(diǎn)-思維導(dǎo)圖 |