某些VS Code主题为什么没有语义突出显示,如何为它们获取语义突出显示?

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

Why don't certain VS Code themes have semantic highlighting, and how can I get semantic highlighting for them?

问题

在Visual Studio Code中,我想使用Tokyo Night颜色主题。然而,它将变量、模块、类标识符和属性设置为相同的颜色。我觉得这有点混淆,所以我尝试自定义它们为不同的颜色。但是,Tokyo Night颜色扩展替换了语义标记分析器,改为使用基于TextMate的分析器。

请参考下面的图片。比较VS Code的dark+颜色主题用于Python,它将np的语义标记类型识别为模块。而Tokyo Night则不识别这一点。

如何在不改变语义分析器的情况下更改颜色主题?

英文:

In Visual Studio Code, I want to use the Tokyo Night colour theme. However, it sets variables, modules, class identifiers and properties to the same colour. I find this a bit confusing so I try to customise them to different colours. However, the Tokyo Night colour extension replaces the semantic token analyser with a TextMate-based one.

See images below. Compare VS Code's dark+ colour theme for Python, which recognises np's semantic token type as a module. Tokyo Night does not recognise this.

How do I change the colour theme without changing the semantic analyser?

答案1

得分: 1

可能只是东京夜晚主题尚未为自身启用语义高亮。请参阅 https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide#enablement-of-semantic-highlighting。如果您查看VS Code的内置主题JSON文件,您会看到它们具有"semanticHighlighting": true。例如,在Solarized Dark主题中。您可以在此处查看VS Code为其内置主题启用语义高亮的提交:41a4adb

我当前在https://github.com/enkia/tokyo-night-vscode-theme/blob/master/themes/tokyo-night-color-theme.json中没有看到类似的行。实际上,经过进一步的调查(我在这个相关讨论中找到了信息),东京之夜实际上曾经在其过去的某个时刻选择启用了语义高亮。请参阅提交ce2b1f1,但在提交2dbedf6中决定取消选择。

您可以通过将editor.semanticHighlighting.enabled设置为true,或在settings.json中执行以下操作,强制启用该主题的语义高亮:

"editor.semanticTokenColorCustomizations": {
    "[Tokyo Night]": {
        "enabled": true,
    },
    "[Tokyo Night Storm]": {
        "enabled": true,
    },
    "[Tokyo Night Light]": {
        "enabled": true,
    },
},
英文:

It might just be that the tokyo night theme hasn't enabled semantic highlighting for itself. See also https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide#enablement-of-semantic-highlighting. If you look at the builtin theme JSON files of VS Code, you'll see that they have "semanticHighlighting": true. Ex. in the Solarized Dark Theme. You can see the commit where VS Code opted in to semantic highlighting for its builtin themes here: 41a4adb.

I currently don't see a line like that in in https://github.com/enkia/tokyo-night-vscode-theme/blob/master/themes/tokyo-night-color-theme.json. Actually, upon further digging (where I found this related discussion), Tokyo Night actually did at one point in its past opt in to semantic highlighting. See commit ce2b1f1, but decided to opt back out in commit 2dbedf6.

You can force semantic highlighting to be enabled for that theme by setting your editor.semanticHighlighting.enabled setting to true, or doing something like the following in settings.json:

"editor.semanticTokenColorCustomizations": {
    "[Tokyo Night]": {
        "enabled": true,
    },
    "[Tokyo Night Storm]": {
        "enabled": true,
    },
    "[Tokyo Night Light]": {
        "enabled": true,
    },
},

huangapple
  • 本文由 发表于 2023年8月11日 02:08:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76878302.html
匿名

发表评论

匿名网友

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

确定