斜体JavaScript';VS代码中的保留关键字

斜体JavaScript';VS代码中的保留关键字,javascript,visual-studio-code,textmate,vscode-settings,Javascript,Visual Studio Code,Textmate,Vscode Settings,我正在尝试使用via创建自定义语法样式 具体来说,我想将JavaScript的所有保留关键字都斜体化。通过下面的设置,我成功地获得了98%的成功率(剩下的部分包括了评论) 不幸的是,我找不到一些规则: storage包含胖箭头符号,我不想包含它。我试图更具体一些,如下面的设置所示,但无法找到构造函数和常量的更具体的设置。此外,“storage.type.function”是我所能找到的函数的最显式设置(function关键字需要,但它包括胖箭头) 关键字包含逻辑运算符等字符,我不想包含这些字符关

我正在尝试使用via创建自定义语法样式

具体来说,我想将JavaScript的所有保留关键字都斜体化。通过下面的设置,我成功地获得了98%的成功率(剩下的部分包括了评论)

不幸的是,我找不到一些规则:

  • storage
    包含胖箭头符号,我不想包含它。我试图更具体一些,如下面的设置所示,但无法找到
    构造函数
    常量
    的更具体的设置。此外,
    “storage.type.function”
    是我所能找到的函数的最显式设置(function关键字需要,但它包括胖箭头)
  • 关键字
    包含逻辑运算符等字符,我不想包含这些字符
    关键字。运算符
    对于文本运算符是必需的(例如中的,
    实例
    ),但包括字符运算符
  • 我无法找到
    eval
    (严格来说是不允许的)或
    package
    (未使用的未来关键字)的规则
  • 有什么想法吗

    const settings = {
      "editor.tokenColorCustomizations": {
        "textMateRules": [
          {
            "scope": [
              // TODO: missing keywords: package, eval
    
          // all comment types
          "comment",
    
          // true, false, null
          "constant.language",
    
          // import, from, export, default, return, if, for, break, continue, try, catch, finally,
          // throw, default, yield, await
          "keyword.control",
    
          // TODO: remove operator symbols
          // in, void, delete, instanceof
          "keyword.operator",
    
          // debugger
          "keyword.other",
    
          // new
          "keyword.operator.new",
    
          // enum
          "storage.type.enum",
    
          // super, this, arguments
          "variable.language",
    
          // attributes in html, jsx, etc.
          "entity.other.attribute-name",
    
          // TODO: remove storage.type after finding explicit for constructor, const, let, var
          "storage.type",
    
          // static, extends, async, private, public, implements
          "storage.modifier",
    
          // TODO: exclude fat arrow
          // function
          "storage.type.function",
    
          // class
          "storage.type.class",
    
          // interface
          "storage.type.interface",
        ],
        "settings": {
          "fontStyle": "italic"
        }
      },
    ]
      },
    };
    

    事实证明,在VS代码中,您可以轻松找到所需的范围

    使用ctrl/cmd+shift+p打开命令搜索,并搜索
    Developer:Inspect TM scopes
    。然后,您可以单击要查找范围的任何符号/单词的左侧


    回答我自己的问题:

  • 到目前为止,
    const
    let
    var
    function
    关键字本身没有明确的范围(
    storage.type.function
    包括保留字和箭头)。但是,函数arrow有一个明确的作用域:
    storage.type.function.arrow
    。这允许我们包括整个
    存储
    范围,然后明确排除箭头
  • 关键字.operator.expression
    是仅表示为单词的运算符所需的范围
  • eval
    package
    的具体范围尚不可用。您可以将
    support.function
    package
    variable.other.readwrite
    作为
    eval
    的目标,但这些范围很广,将包括许多其他结果

  • 话虽如此,将VS代码中所有JavaScript保留关键字斜体化所需的规则如下所示(还包括注释和jsx/html属性):


    您也可以参考此列表-
    "editor.tokenColorCustomizations": {
    "textMateRules": [
      {
        "scope": [
          // all comment types
          "comment",
    
          // true, false, null
          "constant.language",
    
          // import, from, export, default, return, if, for, break, continue, try, catch, finally,
          // throw, default, yield, await
          "keyword.control",
    
          // in, void, delete, instanceof
          "keyword.operator.expression",
    
          // debugger
          "keyword.other",
    
          // new
          "keyword.operator.new",
    
          // super, this, arguments
          "variable.language",
    
          // attributes in html, jsx, etc.
          "entity.other.attribute-name",
    
          // static, extends, async, private, public, implements
          // constructor, const, let, var, enum, class, function, interface
          // no explicit scopes for constructor, const, let, var
          // also no explicit scope for function without the arrow
          // therefore we enable all storage and explictly exclude the arrow in another scope
          "storage",
    
          // // no explicit scope for the eval keyword yet
          // // can be targeted with the scope below, but scope is too broad
          // "support.function",
    
          // // no explicit scope for the package keyword yet
          // // can be targeted with the scope below, but scope is too broad
          // "variable.other.readwrite",
        ],
        "settings": {
          "fontStyle": "italic"
        }
      },
      {
        "scope": [
          // function keyword does not have an explicit scope without the arrow
          // therefore we explictly exclude the function arrow from being italicized
          "storage.type.function.arrow",
        ],
        "settings": {
          "fontStyle": ""
        }
      }
    ]
      }