语法突出显示类型提示的VSCODE

发布于 2025-01-18 15:10:57 字数 649 浏览 3 评论 0原文

我正在使用Dark ++主题,但个性化了很多颜色。 一切都很好,只有一件小事:只有基本类型才适当突出显示。 例如,这

"editor.tokenColorCustomizations": {
      "comments": "#707070",
      "keywords": "#adc5ee",
      "types": "#bbbbbb",
      "strings": "#bdceb7"
}

给了我以下图片:

我希望函数声明中的类型提示为灰色+斜体,因为它适用于类型的“ str”。我知道这对npt.ndarray并不简单,因为它来自打字模块,但是为什么这甚至对“列表”和“ dict”都不起作用呢? 您知道我可以使用的解决方法吗? 据我所知,这些类型没有特殊的令牌,因此除了自定义一般令牌“类型”之外,无法访问它们。 我尝试使用“突出显示”扩展名的正则表达式,但这并不是最佳的,因为我也想保持功能,如果我将部分评论出现在该文本中,则应将其弄清楚(使用“突出显示” )。

I am using the Dark++ theme but personalising a lot of colours.
Everything works fine but one small thing: only the basic types are properly highlighted.
For example this

"editor.tokenColorCustomizations": {
      "comments": "#707070",
      "keywords": "#adc5ee",
      "types": "#bbbbbb",
      "strings": "#bdceb7"
}

gives me the following picture:
enter image description here

I would like the type hints in the function declaration to be grey+italic, as it happens correctly for the type "str". I understand it is not straightforward for npt.NDArray as that comes from the typing module, but why is this not working even for "list" and "dict"?
And do you know of a workaround I could use?
There are not special tokens for these types as far as I know, so no way to access them other than just customising the general token "types".
I tried using regex expressions with the "Highlight" extension but that is not optimal, because I also want to keep the functionality that if I comment out part of that text, it should be greyed-out (using "Highlight" it doesn't).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

漫漫岁月 2025-01-25 15:10:57

为了结束这个主题并供将来参考,这就是我解决问题的方法:我最终按照 rioV8 的建议使用语义突出显示类型提示。

这是通过将以下内容添加到我的 Vscode 设置 JSON 文件来完成的:

    "editor.semanticTokenColorCustomizations": {
      "rules": {
        "*.typeHint": {
          "foreground": "#bbbbbb",
          "fontStyle": "italic"
        },
        "class.typeHint.builtin": {
          "foreground": "#bbbbbb",
          "fontStyle": "italic"
        }
      }
    }

To close this topic and for future reference, this is how I solved my issue: I ended up using semantic highlighting for type hints as rioV8 suggested.

This is done by adding the following to my Vscode settings JSON file:

    "editor.semanticTokenColorCustomizations": {
      "rules": {
        "*.typeHint": {
          "foreground": "#bbbbbb",
          "fontStyle": "italic"
        },
        "class.typeHint.builtin": {
          "foreground": "#bbbbbb",
          "fontStyle": "italic"
        }
      }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文