【问题标题】:VSCode color theme function callsVSCode 颜色主题函数调用
【发布时间】:2018-09-28 14:57:35
【问题描述】:

我正在为 VSCode 对 this color theme 进行自己的本地调整。该主题将主要用于 Java 和 C++ 中的代码。

我希望函数和方法声明颜色不同于函数和方法调用调用。

因此,以下两个实例中的单词 Foo 将是不同的颜色...

public void Foo(String s, int d) {
}

someClass.Foo("blah" , 2);

目前这里设置函数颜色的代码块如下

{
  "name": "Functions",
  "scope": "entity.name.function, meta.require, support.function.any-method",
  "settings": {
    "foreground": "#e26660"
  }
},

如果函数调用使用默认的前景色,我会好的。

【问题讨论】:

  • 您是否尝试使用“Developer: Inspect TM Scopes”命令检查这两个范围并发现它们不同?如果他们这样做,您应该能够单独定位这些范围。我没有运行 java 或 C++ 文件来检查。
  • 我在命令面板中没有这样的命令可用。
  • 在vscode中你没有那个?这很奇怪。
  • 正确,我没有。我正在运行版本 1.27.2(用户设置)。
  • @ScottF 当您在命令面板中搜索该命令时,请确保您专注于具有语法突出显示的文本编辑器

标签: visual-studio-code textmate color-scheme


【解决方案1】:

对于以下范围的函数调用集颜色,请添加以下设置:

{
  "name": "Function call",
  "scope": "meta.function-call.generic, meta.function-call.object, meta.function-call.static",
  "settings": {
    "foreground": "#e26f60"
  }
}, 

另外,您可以通过设置范围来仅为 CPP 设置颜色

meta.function-call.cpp

【讨论】:

    【解决方案2】:

    如果您没有得到基于范围的答案,您可以通过基于正则表达式的方法做更多的工作。使用像 Highlight 这样的扩展,它允许您为可以通过正则表达式捕获的字符串指定 synatx 突出显示。例如,

     "highlight.regexes": {
    
        "(\\b.*\\.)([^(\\s]*)(\\s*\\(.*\\))": {
    
          "regexFlags": "g",
          "filterLanguageRegex": "(java|cpp)",
          \\ "filterFileRegex" : ".*\\.java",
          "decorations" : [
            {},  // first capture group, " do nothing
            {  "color": "red",
             "fontWeight": "bold",
             "padding": "3px",  // only pads top and bottom unfortunately
             "backgroundColor": "darkgreen",
            //  "border": "1px solid white",
            //  "borderRadius": "4px"
            },
            {}  // third capture group, ", do nothing
          ]
        },
    
        "((?:void|int)\\s+)([^(\\s]*)(\\s*\\(.*\\))": {
    
          "regexFlags": "g",
          "filterLanguageRegex": "(java|cpp)",
          \\ "filterFileRegex" : ".*\\.java",
          "decorations" : [
            {},  // first capture group, " do nothing
            {  "color": "red",
             "fontWeight": "bold",
             "padding": "3px",  // only pads top and bottom unfortunately
             "backgroundColor": "darkgreen",
            //  "border": "1px solid white",
            //  "borderRadius": "4px"
            },
            {}  // third capture group, ", do nothing
          ]
        }
    

    其中的第一个在第二个捕获组中捕获像 someClass.Foo("blah" , 2); 这样的调用,Foo

    其中的第二个在第二个捕获组中捕获像 public void Foo(String s, int d)Foo 这样的调用。

    我稍微简化了第二个正则表达式(我只添加了voidint,但您可以轻松添加其他选项)。

    【讨论】:

      【解决方案3】:

      我已经为你找到了 C++ 的答案!

      对于函数调用:

      {
          "name": "Function calls",
          "scope": [
              "entity.name.function.call.cpp",
                  
          ],
          "settings": {
          "foreground": "#9bff6d"
          }
      },
      

      对于声明:

          {
              "name": "Function declarations",
              "scope": [
                  "entity.name.function.definition.cpp",
                  
              ],
              "settings": {
                  "foreground": "#ffc66d"
              }
          },
          
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-08-18
        • 2018-04-17
        • 2018-10-11
        • 1970-01-01
        • 1970-01-01
        • 2019-12-29
        • 1970-01-01
        • 2020-09-06
        相关资源
        最近更新 更多