我想将VSCode中的黄色括号级别更改为更明显的颜色。

huangapple go评论92阅读模式
英文:

I want to change the yellow bracket level in VSCode to a more visible colour

问题

我正在使用VSCode和(默认)Light+主题,在Windows 10上。我喜欢这个主题,但是对于白色背景下的黄色有很多困扰 - 对于所有的“亮色”主题都是如此,所以改变主题没有意义。

我在设置中找到了workbench.colorCustomizations,具体是改变editorBracketHighlight.foreground1,但它不会保持我选择的颜色(深蓝色) - 当我打开VSCode编辑器时,它有时会显示为蓝色(但不一致),但即使我最初看到蓝色,它很快就会切换回黄色。似乎有各种方法可以更改设置,但我还没有找到一个可以保持的方法!

顺便说一句,我已经指定了editor.bracketPairColorization.enabled(并且这确实有效,使用旧的颜色),所以这不是问题...

希望能得到帮助!谢谢!

顺便说一句,我不在乎这是否与我的工作台或所有项目以及所有语言或每种语言具体相关联(我现在只使用Go),因为我希望对所有项目和所有语言都生效...

英文:

I am using VSCode and the (default) Light+ theme, on Windows 10. I like this theme but have a lot of trouble seeing the yellow against the white - same is true for all the "light" themes, so there is no point changing themes.

I have found workbench.colorCustomizations in Settings - specifically changing editorBracketHighlight.foreground1 , but it won't stay on the colour I have selected (dark blue) - it sometimes shows as blue (and not consistently) when I bring up the VSCode editor, but, even if I see blue initially, it switches back to yellow shortly after. There seem to be various ways to change the settings, but I haven't found one that will stay!

BTW I have specified editor.bracketPairColorization.enabled (and this does work, using the old colours), so this is not the problem...

Help would be appreciated! TIA

PS I don't care whether this is associated with my workbench or all projects, and all languages or each language specifically (I am just doing Go right now), as I would want this for all projects, and all languages...

答案1

得分: 2

为了更好地了解幕后发生的情况,首先安装Scope Inspector插件。你可以在以下链接中找到安装方法:https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide#scope-inspector

然后使用快捷键ctrl+shift+P打开你的settings.json文件,选择"Preferences: Open Settings.json"。

现在打开一个你想要用作测试对象的.go文件,然后启用scope inspector:使用快捷键ctrl+shift+p,选择"Developer: Inspect Editor Tokens & Scopes"。

当你在代码中移动光标时,你会看到不同的scope应用于不同的标记。

在这个例子中,inspector显示有2个scope被应用。

要更改颜色,打开Settings.json文件...

在文件中,除了其他可能添加的内容之外,添加一个"editor.tokenColorCustomizations"对象,其中包含一个子对象"textMateRules",并使用上面提到的Scope Inspector指定你想要定位的scopes:

{
"editor.tokenColorCustomizations":{
"textMateRules": [
{ "scope": "punctuation.definition.bracket.square.go",
"settings": {
"foreground": "#8110239f",
"fontStyle": "bold",
}
},
//.... 可以添加其他规则,针对你在inspector中找到的不同scopes...
]
} //end "editor.tokenColorCustomizations"
}

在这个例子中,结果立即变为深红色。

英文:

To get a better idea of whats going on behind the scenes, first install the Scope Inspector

https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide#scope-inspector

then open your settings.json with ctrl+shift+P -> "Preferences: Open Settings.json".

Now open a .go file that you want to use as a test subject... and then enable the scope inspector:
ctrl+shift+p -> Developer: Inspect Editor Tokens & Scopes

For me I am using a Slice tutorial as example, Light+ on MacOS :我想将VSCode中的黄色括号级别更改为更明显的颜色。

moving around your cursor you will see different scopes are applied to different tokens in your code.

In this example the inspector shows that it has 2 scopes being applied.

To change the color, go to the Settings.json file...

Inside, alongside whatever else you may have added, put in the "editor.tokenColorCustomizations" object with a sub "textMateRules" object, and include the scopes you want to target using the ScopeInspector mentioned above:

{
  "editor.tokenColorCustomizations":{
    // "comments": "#33FFCC",  //will affect all comments in VSCode...
    "textMateRules": [
      { "scope": "punctuation.definition.bracket.square.go",
         "settings": {
            "foreground": "#8110239f",
            "fontStyle": "bold",
         }
      },
     //.... Other rules you may add for different scopes you find with inspector etc... 
    ]
  } //end "editor.tokenColorCustomizations"
}

In this example, The result immediately changes to a dark red:

我想将VSCode中的黄色括号级别更改为更明显的颜色。

答案2

得分: 0

似乎我现在可以根据需要自定义括号的颜色,而无需使用testMateRules,如下所示:

 "editor.bracketPairColorization.enabled": true,
"editor.guides.bracketPairs": "active",
"bracket-pair-colorizer-2.forceUniqueOpeningColor": false,
"bracket-pair-colorizer-2.showVerticalScopeLine": true,
"bracket-pair-colorizer-2.showHorizontalScopeLine": true,
"bracket-pair-colorizer-2.colors": [
  "#3344F0",
  "Orchid",
  "LightSkyBlue",
  "Green"
],

这似乎有效 - 也许有人可以告诉我是否存在问题!谢谢

英文:

It seems that I can now colour the brackets as desired without using testMateRules, as follows:

 "editor.bracketPairColorization.enabled": true,
"editor.guides.bracketPairs": "active",
"bracket-pair-colorizer-2.forceUniqueOpeningColor": false,
"bracket-pair-colorizer-2.showVerticalScopeLine": true,
"bracket-pair-colorizer-2.showHorizontalScopeLine": true,
"bracket-pair-colorizer-2.colors": [
  "#3344F0",
  "Orchid",
  "LightSkyBlue",
  "Green"
],

This seems to work - maybe someone could let me know if there is a problem with this! Thanks

huangapple
  • 本文由 发表于 2022年1月18日 05:07:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/70747523.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定