Sco*_*ger 8 .net c# visual-studio-code
我想设置为在 Visual Studio Code 上保存 C# 代码时触发“格式化文档”和“删除未使用的使用”。或者添加一个键盘快捷键来删除未使用的使用。
我已经添加到下面的用户设置。
"editor.formatOnSave": true
Run Code Online (Sandbox Code Playgroud)
这会在保存时触发格式文档。但我也想删除未使用的用途。如果有未使用的用途,VS 代码会警告我,我可以 Ctrl + . 弹出关于删除未使用的使用。
我还为格式化文档添加了键盘快捷键。
{ "key": "ctrl+k ctrl+f", "command": "editor.action.formatSelection",
"when": "editorHasDocumentSelectionFormattingProvider && editorHasSelection && editorTextFocus && !editorReadonly" },
Run Code Online (Sandbox Code Playgroud)
我想添加 Ctrl+R Ctrl+G 以删除未使用的用途。(由 Visual Studio 默认)。但我不知道如何配置键盘快捷键设置...
{ "key": "ctrl+r ctrl+g", "command": "editor.action.???",
"when": "???" },
Run Code Online (Sandbox Code Playgroud)
删除未使用的使用的配置必须通过 omnisharp 完成。
Omnisharp 设置可在两个位置使用:
对于全局设置:
对于全局设置,使用
%USERPROFILE%/.omnisharp/omnisharp.json
文件
对于项目特定设置:
omnisharp.json
在工作区的根目录使用
设置如下:
{
"FormattingOptions": {
"OrganizeImports": true
}
}
Run Code Online (Sandbox Code Playgroud)
2020 年 5 月 5 日可用的其他默认设置:
{
"FormattingOptions": {
"OrganizeImports": false,
"EnableEditorConfigSupport": false,
"NewLine": "\n",
"UseTabs": false,
"TabSize": 4,
"IndentationSize": 4,
"SpacingAfterMethodDeclarationName": false,
"SpaceWithinMethodDeclarationParenthesis": false,
"SpaceBetweenEmptyMethodDeclarationParentheses": false,
"SpaceAfterMethodCallName": false,
"SpaceWithinMethodCallParentheses": false,
"SpaceBetweenEmptyMethodCallParentheses": false,
"SpaceAfterControlFlowStatementKeyword": true,
"SpaceWithinExpressionParentheses": false,
"SpaceWithinCastParentheses": false,
"SpaceWithinOtherParentheses": false,
"SpaceAfterCast": false,
"SpacesIgnoreAroundVariableDeclaration": false,
"SpaceBeforeOpenSquareBracket": false,
"SpaceBetweenEmptySquareBrackets": false,
"SpaceWithinSquareBrackets": false,
"SpaceAfterColonInBaseTypeDeclaration": true,
"SpaceAfterComma": true,
"SpaceAfterDot": false,
"SpaceAfterSemicolonsInForStatement": true,
"SpaceBeforeColonInBaseTypeDeclaration": true,
"SpaceBeforeComma": false,
"SpaceBeforeDot": false,
"SpaceBeforeSemicolonsInForStatement": false,
"SpacingAroundBinaryOperator": "single",
"IndentBraces": false,
"IndentBlock": true,
"IndentSwitchSection": true,
"IndentSwitchCaseSection": true,
"IndentSwitchCaseSectionWhenBlock": true,
"LabelPositioning": "oneLess",
"WrappingPreserveSingleLine": true,
"WrappingKeepStatementsOnSingleLine": true,
"NewLinesForBracesInTypes": true,
"NewLinesForBracesInMethods": true,
"NewLinesForBracesInProperties": true,
"NewLinesForBracesInAccessors": true,
"NewLinesForBracesInAnonymousMethods": true,
"NewLinesForBracesInControlBlocks": true,
"NewLinesForBracesInAnonymousTypes": true,
"NewLinesForBracesInObjectCollectionArrayInitializers": true,
"NewLinesForBracesInLambdaExpressionBody": true,
"NewLineForElse": true,
"NewLineForCatch": true,
"NewLineForFinally": true,
"NewLineForMembersInObjectInit": true,
"NewLineForMembersInAnonymousTypes": true,
"NewLineForClausesInQuery": true
}
}
Run Code Online (Sandbox Code Playgroud)
我担心,今天写的内容, VSCode Marketplace上没有插件- 也没有内置的设置/功能提供您想要的有关“未使用的使用”行为的内容,就像在完整的 Visual Studio 中一样。
我的建议是在名为“ OmniSharp ”的官方 Microsoft 插件(默认 C# 插件,也支持其他编辑器的 C# 功能)中请求此功能:https: //github.com/OmniSharp/omnisharp-vscode/issues。
旁注:有一个关于“未使用的使用”的问题,以禁用它生成的警告:https ://github.com/OmniSharp/omnisharp-vscode/issues/315
或者转到 VSCode GitHub 问题页面并在那里询问: https: //github.com/microsoft/vscode/issues。
或者最后一条路线是深入研究并编写自己的插件/扩展:https://code.visualstudio.com/docs/extensions/overview。
归档时间: |
|
查看次数: |
3469 次 |
最近记录: |