【问题标题】:Custom color highlighting for Pylance in VS Code: defined variables in white, undefined variables in redVS Code 中 Pylance 的自定义颜色突出显示:已定义变量为白色,未定义变量为红色
【发布时间】:2022-11-01 13:30:56
【问题描述】:

我在 VS Code(深色主题)中使用 Pylance,编写 Python 3.9。 启用语义突出显示时,定义明确的变量以青色着色,当我使用未定义的变量(并且在运行代码时会产生错误)时,它以白色着色。

我想改变它,使定义明确的变量用白色着色,而未定义的变量用红色着色(错误的颜色)。

我知道我需要编辑settings.json,但我没有在下面的文档中找到我要查找的内容。

参考文献:https://github.com/microsoft/pylance-release#semantic-highlighting

【问题讨论】:

    标签: python visual-studio-code pylance


    【解决方案1】:

    以下配置可能对您有用

    // settings.json file
    {
        "editor.tokenColorCustomizations":{
            // I guess you are using the dark+ theme, 
            // because I use the dark theme and enable semantic highlighting 
            // with both defined and undefined variables in white color.
            "[Default Dark+]": {
                "textMateRules": [
                    {
                        "scope": "meta.function-call.arguments.python",
                        "settings": {
                            "foreground": "#FF0000"
                        }
                    },
                    {
                        "scope": "variable.other.readwrite",
                        "settings": {
                            "foreground": "#ffffff"
                        }
                    },
                    {
                        "scope": "punctuation.separator.arguments.python",
                        "settings": {
                            "foreground": "#D4D4D4"
                        }
                    }
                ]
            }
        },
        "editor.semanticHighlighting.enabled": true,
        "workbench.colorTheme": "Default Dark+",
    }
    

    在我的电脑上看起来像这样

    请注意,上述配置可能会导致其他意外更改。因为更改颜色的范围也可能在其他一些地方起作用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-03
      • 2018-07-20
      • 2021-11-29
      • 2010-12-24
      相关资源
      最近更新 更多