如何在Visual Studio中突出显示用户指定的单词?

x759pob2  于 2022-12-14  发布在  其他
关注(0)|答案(8)|浏览(322)

我的团队经常在未完成的代码段中放置TODO一词。是否有办法将用户指定的关键字添加到Visual Studio中,以便以某种方式突出显示这些关键字?例如,在vim中,TODO一词会自动突出显示。
例如,我希望看到如下内容:
一月一日***一月一日***一月二日

z9gpfhce

z9gpfhce1#

在“工具”菜单中,进入“选项”-〉“环境”-〉“任务列表”。在这里,您可以输入“令牌”。
这些令牌将被添加到任务列表中,但不会被突出显示。这可以通过available TODO highlighters中的一个来实现。

whlutmcx

whlutmcx2#

就像其他人说的,你需要一个VS的插件(从VS 2015开始)来高亮显示文本。对于那些正在使用Resharper的人:
从菜单转到ReSharper-〉选项-〉工具-〉待办事项。
添加您的新注解和模式。您可以通过编辑来复制现有的注解和模式。我在新注解中使用了与Todo相同的设置:

Title: AnythingYouWant

Regular Expression: `(?<=\W|^)(?<TAG>AnythingYouWant)(\W|$)(.*)`

Put a check "In comments"

Color: Web->Blue

Icon: Normal

并在代码中这样使用它:
// AnythingYouWant此评论以蓝色突出显示

fnvucqvd

fnvucqvd5#

在Visual Studio中:
转至“工具”〉“选项”〉“环境”〉“任务列表
您可以在其中添加任何用户指定的单词,并且它将在您进行生成并查看任务列表时显示在任务列表中,其方式与//TODO:得双曲余切值.

x7rlezfr

x7rlezfr6#

只有通过扩展才能突出显示任务令牌。
如果您有ReSharper(商业版),它会使用相同的颜色突出显示所有任务:字体和颜色〉ReSharper待办事项。ReSharper还在垂直错误条纹上标记任务。
VS 2015的Remaker(免费):https://visualstudiogallery.msdn.microsoft.com/32af9cb5-bb6e-4f02-97c6-a172c3ac5445或VS 2013:https://visualstudiogallery.msdn.microsoft.com/87813da0-8f1c-48a4-b1c4-85dfb7a269a9可以使用不同的样式突出显示不同的任务令牌。
同样适用于VS 10 x Comments Extender(免费),适用于VS 2010-2013,适用于2015年的私人测试版:https://visualstudiogallery.msdn.microsoft.com/17c68951-7743-40bd-ad35-608706f54a92

2lpgd968

2lpgd9687#

我发现并正在使用this可定制的评论突出显示扩展VS 2010-2015。
从它的描述来看:...您可以根据前景色设置任务注解(TODO、HACK、UNDONE)的格式。

a9wyjsp7

a9wyjsp78#

有很多,但我发现最好的和最简单的一个是 * wayou.vscode-todo-highlight。然而,似乎这个扩展的维护一直是abandoned
这些设置简单明了,但不幸的是,示例的开箱即用设置(和文档)很糟糕,所以为了让生活更简单,只需将其 * 复制/粘贴 * 到您的(用户)设置JSON文件中。
在Win-10上,
用户 * 设置位于以下位置:
C:\Users\<username>\AppData\Roaming\Code\User\settings.json .

//------------------------------------------
// wayou.vscode-todo-highlight
//------------------------------------------
// For colors, see: 
// https://stackoverflow.com/questions/20541456/list-of-all-colors-available-for-powershell
"todohighlight.isEnable": true,
"todohighlight.isCaseSensitive": true,
"todohighlight.keywords": [
    "ToDo",
    "DEBUG:",
    "REVIEW:",
    {
        "text": "NOTE:",                                                // 
        "color": "yellow",                                              // 
        "backgroundColor": "#006400",                                   // DarkGreen #FF006400 (argb)
        "overviewRulerColor": "grey",                                   // 
        "fontWeight": "bold",                                           // 
    },
    {
        "text": "HACK:",                                                // 
        "color": "#000",                                                // 
        "isWholeLine": false,                                           // 
        "fontWeight": "bold",                                           // 
        //"margin":  "5px",                                             // [padding, border, margin] Not working!
    },
    {
        "text": "TODO:",                                                // 
        "color": "red",                                                 // 
        //"border": "1px solid red",                                    // 
        "borderRadius": "1px",                                          //NOTE: using borderRadius along with `border` or you will see nothing change
        "backgroundColor": "rgba(4,4,4,.2)",                            // "rgba(0,0,0,.2)"
        "isCaseSensitive": false,                                       // 
        // Add other styling properties here. 
    }
],
//"todohighlight.keywordsPattern": "TODO:|FIXME:|\\(([^)]+)\\)",        //highlight `TODO:`,`FIXME:` or content between parentheses
"todohighlight.defaultStyle": {
    "color": "red",                                                     // 
    "backgroundColor": "#ffab00",                                       // 
    "overviewRulerColor": "#ffab00",                                    // 
    "cursor": "pointer",                                                // 
    "border": "1px solid #666",                                         // 
    "borderRadius": "2px",                                              // 
    "isWholeLine": false,                                               // 
    // Add other default styling properties here. 
},
"todohighlight.include": [
    "**/*.js",
    "**/*.jsx",
    "**/*.ts",
    "**/*.tsx",
    "**/*.html",
    "**/*.php",
    "**/*.css",
    "**/*.scss",
    "**/*.ps1"
],
"todohighlight.exclude": [
    "**/node_modules/**",
    "**/bower_components/**",
    "**/dist/**",
    "**/build/**",
    "**/.vscode/**",
    "**/.github/**",
    "**/_output/**",
    "**/*.min.*",
    "**/*.map",
    "**/.next/**"
],
"todohighlight.maxFilesForSearch": 5120,
"todohighlight.toggleURI": false
//------------------------------------------

注意:我没有包含外部的{}

相关问题