9

I am doing my own local tweaks to this color theme for VSCode. The theme will be used to mainly code in Java and C++.

I would like function and method declaration color to be different from function and method invocation calls.

So the word Foo in the following two instances would be a different color...

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

someClass.Foo("blah" , 2);

Currently the block of code that is setting the color for functions in this is as follows

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

I would be ok if function invocation used the default foreground text color.

Scorb
  • 1,654
  • 13
  • 70
  • 144
  • Did you try examining the two scopes with the "Developer: Inspect TM Scopes" command and see it they differ? If they do, you should be able to separately target those scopes. I am not running java or C++ files to check. – Mark Sep 28 '18 at 15:15
  • I don't have such a command available to me in the command palette. – Scorb Sep 28 '18 at 15:18
  • In vscode you don't have that? That is weird. – Mark Sep 28 '18 at 15:31
  • Correct, I do not have it. I am running version 1.27.2 (user setup). – Scorb Sep 28 '18 at 15:33
  • @ScottF Make sure you are focused on a text editor with syntax highlighting when you search the command palette for that command – Matt Bierner Oct 30 '18 at 04:29
  • If they are the same scope, I don't think you can do it with the usual editor.tokenColorCustomizations scoping. Are you open to a regex solution to find and style declarations differently from invocations? – Mark Mar 05 '19 at 05:16

3 Answers3

2

For function call set color for the following scopes add the folowing settings:

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

also, you might be able to set the color for only CPP by setting the scope of

meta.function-call.cpp
Bradia
  • 827
  • 5
  • 8
1

I have got the answer for you for C++!

For function calls:

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

and for declarations:

    {
        "name": "Function declarations",
        "scope": [
            "entity.name.function.definition.cpp",
            
        ],
        "settings": {
            "foreground": "#ffc66d"
        }
    },
    
Kleysley
  • 505
  • 3
  • 12
0

If you don't get a scope-based answer, you can do this with more work via a regex based approach. Using an extension like Highlight which allows you to specify synatx highlighting for strings that can be captured via regular expressions. For example,

 "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
      ]
    }

The first of those captures calls like someClass.Foo("blah" , 2); with Foo in the second capture group.

The second of those captures calls like public void Foo(String s, int d) with Foo in the second capture group.

I have simplified the second regex a bit (I added only void and int, but you could easily add the other alternatives).

java code highlighted

Mark
  • 143,421
  • 24
  • 428
  • 436