vscode-scala-syntax
vscode-scala-syntax copied to clipboard
Add support for meta.function-call
I have noticed that the function/method calls don't get any color when I configure it using the meta.function-call scope:
Settings.json:
{
"scope": "meta.function-call",
"settings": {
"foreground": "#82AAFF"
}
}
I tested this in other languages and it works as expected using that scope. Am I using the wrong scope? Could this be added? Thanks in advance
Could you provide some examples where you would expect this coloring? And some example of the other languages as a guide.
Here you can see a little example on scala:

and the same in python:

and this is how I see the same scala code on IntelliJ:

Notice that If I try to color the source.scala scope it colors all the code.
I think we can implement something that highlights some function calls as meta.function-call, but this would only be an approximation of coloring all function calls. The simplest heuristic we can use is to assign meta.function-call for any identifier followed by ( or {.
There are some cases where we cannot highlight correctly:
- Arity-0 function calls that omit parentheses (e.g.
replyinstead ofreply()) — though this is (mostly) dropped in Scala 3 - Calls to functions whose names starts with an uppercase letter. These are ambiguous with calls to the
applymethod of an object (e.g.MyObject(1, 2, 3)vsMyFunction(1, 2, 3)) — though in this case, I think we can just go with the convention that uppercased identifiers are names of types, and lowercased identifiers are for methods and variables. So function calls starting with an uppercase would not be assignedmeta.function-call.
In general, coloring all function calls correctly would require information from the compiler about which identifiers correspond to function names. In VS Code terminology, we would need to write a semantic highlighter, but this project is a syntax highlighter. So I think some approximation definitely is acceptable for the scope of this project.
Adding a color for the a . following a name and optionally ( or { looks awesome. I don't care to wait for scala 3 to make mandatory the parenthesis or brackets
I do not really see how we could get this information syntactically. This is in the domain of semantic highlighting.
Consider the following cases
val x1 = ???
def x2 = ???
def x3() = ???
val x4: () => () = ???
x1 // not a function call
x2 // function call
x3() // function call
x4() // not a function call
p.x1 // not a function call
p.x2 // function call
p.x3() // function call
p.x4() // not a function call
Semantic highlighting is part of LSP, so we might make it work in Metals. We should already have most information needed in semanticdb and we added the project as part of GSoC, but I am not sure if anyone applied.